diff UnitTests/Fluent/AssertExceptionEx.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTests/Fluent/AssertExceptionEx.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,62 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace BLToolkit.Fluent.Test
+{
+    /// <summary>
+    /// Класс для работы с асертами обладающий дополнительными методами
+    /// </summary>
+    public static class AssertExceptionEx
+    {
+        /// <summary>
+        /// Проверка на обязательность исключения
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="action"></param>
+        /// <param name="message"></param>
+        public static void AreException<T>(Action action, string message)
+        {
+            bool isOk = false;
+            try
+            {
+                action();
+            }
+            catch (Exception e)
+            {
+                if (e is T)
+                {
+                    isOk = true;
+                }
+            }
+            if (!isOk)
+            {
+                Assert.Fail(message);
+            }
+        }
+        /// <summary>
+        /// Проверка на обязательность отсутсвия исключения
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="action"></param>
+        /// <param name="message"></param>
+        public static void AreNotException<T>(Action action, string message)
+        {
+            bool isOk = true;
+            try
+            {
+                action();
+            }
+            catch (Exception e)
+            {
+                if (e is T)
+                {
+                    isOk = false;
+                }
+            }
+            if (!isOk)
+            {
+                Assert.Fail(message);
+            }
+        }
+    }
+}
\ No newline at end of file