0
|
1 using System;
|
|
2 using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
3
|
|
4 namespace BLToolkit.Fluent.Test
|
|
5 {
|
|
6 /// <summary>
|
|
7 /// Класс для работы с асертами обладающий дополнительными методами
|
|
8 /// </summary>
|
|
9 public static class AssertExceptionEx
|
|
10 {
|
|
11 /// <summary>
|
|
12 /// Проверка на обязательность исключения
|
|
13 /// </summary>
|
|
14 /// <typeparam name="T"></typeparam>
|
|
15 /// <param name="action"></param>
|
|
16 /// <param name="message"></param>
|
|
17 public static void AreException<T>(Action action, string message)
|
|
18 {
|
|
19 bool isOk = false;
|
|
20 try
|
|
21 {
|
|
22 action();
|
|
23 }
|
|
24 catch (Exception e)
|
|
25 {
|
|
26 if (e is T)
|
|
27 {
|
|
28 isOk = true;
|
|
29 }
|
|
30 }
|
|
31 if (!isOk)
|
|
32 {
|
|
33 Assert.Fail(message);
|
|
34 }
|
|
35 }
|
|
36 /// <summary>
|
|
37 /// Проверка на обязательность отсутсвия исключения
|
|
38 /// </summary>
|
|
39 /// <typeparam name="T"></typeparam>
|
|
40 /// <param name="action"></param>
|
|
41 /// <param name="message"></param>
|
|
42 public static void AreNotException<T>(Action action, string message)
|
|
43 {
|
|
44 bool isOk = true;
|
|
45 try
|
|
46 {
|
|
47 action();
|
|
48 }
|
|
49 catch (Exception e)
|
|
50 {
|
|
51 if (e is T)
|
|
52 {
|
|
53 isOk = false;
|
|
54 }
|
|
55 }
|
|
56 if (!isOk)
|
|
57 {
|
|
58 Assert.Fail(message);
|
|
59 }
|
|
60 }
|
|
61 }
|
|
62 } |