|
1 |
| -using FluentAssertions.Primitives; |
2 |
| -using FluentAssertions.Execution; |
3 |
| -using System; |
4 |
| -using System.Web.Mvc; |
5 |
| -using System.Diagnostics; |
6 |
| - |
7 |
| -namespace FluentAssertions.Mvc |
8 |
| -{ |
9 |
| - [DebuggerNonUserCode] |
10 |
| - public class ActionResultAssertions : ObjectAssertions |
11 |
| - { |
12 |
| - public struct Constants |
13 |
| - { |
14 |
| - public const string CommonFailMessage = "Expected ActionResult to be {0}{reason}, but found {1}"; |
15 |
| - } |
16 |
| - |
17 |
| - public ActionResultAssertions (ActionResult subject) : base(subject) |
18 |
| - { |
19 |
| - Subject = subject; |
20 |
| - } |
21 |
| - |
22 |
| - public ContentResultAssertions BeContent() |
23 |
| - { |
24 |
| - return BeContent(string.Empty, null); |
25 |
| - } |
26 |
| - |
27 |
| - public ContentResultAssertions BeContent(string reason, params object[] reasonArgs) |
28 |
| - { |
29 |
| - Execute.Verification |
30 |
| - .BecauseOf(reason, reasonArgs) |
31 |
| - .ForCondition(Subject is ContentResult) |
32 |
| - .FailWith(Constants.CommonFailMessage, typeof(ContentResult).Name, Subject.GetType().Name); |
33 |
| - |
34 |
| - return new ContentResultAssertions(Subject as ContentResult); |
35 |
| - } |
36 |
| - |
37 |
| - public EmptyResult BeEmpty() |
38 |
| - { |
39 |
| - return BeEmpty(string.Empty, null); |
40 |
| - } |
41 |
| - |
42 |
| - public EmptyResult BeEmpty(string reason, params object[] reasonArgs) |
43 |
| - { |
44 |
| - Execute.Verification |
45 |
| - .BecauseOf(reason, reasonArgs) |
46 |
| - .ForCondition(Subject is EmptyResult) |
47 |
| - .FailWith(Constants.CommonFailMessage, typeof(EmptyResult).Name, Subject.GetType().Name); |
48 |
| - |
49 |
| - return Subject as EmptyResult; |
50 |
| - } |
51 |
| - |
52 |
| - public RedirectToRouteAssertions BeRedirectToRoute() |
53 |
| - { |
54 |
| - return BeRedirectToRoute(string.Empty, null); |
55 |
| - } |
56 |
| - |
57 |
| - public RedirectToRouteAssertions BeRedirectToRoute(string reason, params object[] reasonArgs) |
58 |
| - { |
59 |
| - Execute.Verification |
60 |
| - .BecauseOf(reason, reasonArgs) |
61 |
| - .ForCondition(Subject is RedirectToRouteResult) |
62 |
| - .FailWith(Constants.CommonFailMessage, typeof(RedirectToRouteResult).Name, Subject.GetType().Name); |
63 |
| - |
64 |
| - return new RedirectToRouteAssertions(Subject as RedirectToRouteResult); |
65 |
| - } |
66 |
| - |
67 |
| - public PartialViewResultAssertions BePartialView() |
68 |
| - { |
69 |
| - return BePartialView(string.Empty, null); |
70 |
| - } |
71 |
| - |
72 |
| - public PartialViewResultAssertions BePartialView(string reason, params object[] reasonArgs) |
73 |
| - { |
74 |
| - Execute.Verification |
75 |
| - .BecauseOf(reason, reasonArgs) |
76 |
| - .ForCondition(Subject is PartialViewResult) |
77 |
| - .FailWith(Constants.CommonFailMessage, typeof(PartialViewResult).Name, Subject.GetType().Name); |
78 |
| - |
79 |
| - return new PartialViewResultAssertions(Subject as PartialViewResult); |
80 |
| - } |
81 |
| - |
82 |
| - public RedirectResultAssertions BeRedirect() |
83 |
| - { |
84 |
| - return BeRedirect(string.Empty, null); |
85 |
| - } |
86 |
| - |
87 |
| - public RedirectResultAssertions BeRedirect(string reason, params object[] reasonArgs) |
88 |
| - { |
89 |
| - Execute.Verification |
90 |
| - .BecauseOf(reason, reasonArgs) |
91 |
| - .ForCondition(Subject is RedirectResult) |
92 |
| - .FailWith(Constants.CommonFailMessage, "RedirectResult", Subject.GetType().Name); |
93 |
| - |
94 |
| - return new RedirectResultAssertions(Subject as RedirectResult); |
95 |
| - } |
96 |
| - |
97 |
| - public ViewResultAssertions BeView() |
98 |
| - { |
99 |
| - return BeView(string.Empty, null); |
100 |
| - } |
101 |
| - |
102 |
| - public ViewResultAssertions BeView(string reason, params object[] reasonArgs) |
103 |
| - { |
104 |
| - Execute.Verification |
105 |
| - .BecauseOf(reason, reasonArgs) |
106 |
| - .ForCondition (Subject is ViewResult) |
107 |
| - .FailWith(Constants.CommonFailMessage, "ViewResult", Subject.GetType().Name); |
108 |
| - |
109 |
| - return new ViewResultAssertions (Subject as ViewResult); |
110 |
| - } |
111 |
| - } |
112 |
| -} |
| 1 | +using FluentAssertions.Primitives; |
| 2 | +using FluentAssertions.Execution; |
| 3 | +using System; |
| 4 | +using System.Web.Mvc; |
| 5 | +using System.Diagnostics; |
| 6 | + |
| 7 | +namespace FluentAssertions.Mvc |
| 8 | +{ |
| 9 | + [DebuggerNonUserCode] |
| 10 | + public class ActionResultAssertions : ObjectAssertions |
| 11 | + { |
| 12 | + public struct Constants |
| 13 | + { |
| 14 | + public const string CommonFailMessage = "Expected ActionResult to be {0}{reason}, but found {1}"; |
| 15 | + } |
| 16 | + |
| 17 | + public ActionResultAssertions (ActionResult subject) : base(subject) |
| 18 | + { |
| 19 | + Subject = subject; |
| 20 | + } |
| 21 | + |
| 22 | + public ContentResultAssertions BeContentResult() |
| 23 | + { |
| 24 | + return BeContentResult(string.Empty, null); |
| 25 | + } |
| 26 | + |
| 27 | + public ContentResultAssertions BeContentResult(string reason, params object[] reasonArgs) |
| 28 | + { |
| 29 | + Execute.Verification |
| 30 | + .BecauseOf(reason, reasonArgs) |
| 31 | + .ForCondition(Subject is ContentResult) |
| 32 | + .FailWith(Constants.CommonFailMessage, typeof(ContentResult).Name, Subject.GetType().Name); |
| 33 | + |
| 34 | + return new ContentResultAssertions(Subject as ContentResult); |
| 35 | + } |
| 36 | + |
| 37 | + public EmptyResult BeEmptyResult() |
| 38 | + { |
| 39 | + return BeEmptyResult(string.Empty, null); |
| 40 | + } |
| 41 | + |
| 42 | + public EmptyResult BeEmptyResult(string reason, params object[] reasonArgs) |
| 43 | + { |
| 44 | + Execute.Verification |
| 45 | + .BecauseOf(reason, reasonArgs) |
| 46 | + .ForCondition(Subject is EmptyResult) |
| 47 | + .FailWith(Constants.CommonFailMessage, typeof(EmptyResult).Name, Subject.GetType().Name); |
| 48 | + |
| 49 | + return Subject as EmptyResult; |
| 50 | + } |
| 51 | + |
| 52 | + public RedirectToRouteAssertions BeRedirectToRouteResult() |
| 53 | + { |
| 54 | + return BeRedirectToRouteResult(string.Empty, null); |
| 55 | + } |
| 56 | + |
| 57 | + public RedirectToRouteAssertions BeRedirectToRouteResult(string reason, params object[] reasonArgs) |
| 58 | + { |
| 59 | + Execute.Verification |
| 60 | + .BecauseOf(reason, reasonArgs) |
| 61 | + .ForCondition(Subject is RedirectToRouteResult) |
| 62 | + .FailWith(Constants.CommonFailMessage, typeof(RedirectToRouteResult).Name, Subject.GetType().Name); |
| 63 | + |
| 64 | + return new RedirectToRouteAssertions(Subject as RedirectToRouteResult); |
| 65 | + } |
| 66 | + |
| 67 | + public PartialViewResultAssertions BePartialViewResult() |
| 68 | + { |
| 69 | + return BePartialViewResult(string.Empty, null); |
| 70 | + } |
| 71 | + |
| 72 | + public PartialViewResultAssertions BePartialViewResult(string reason, params object[] reasonArgs) |
| 73 | + { |
| 74 | + Execute.Verification |
| 75 | + .BecauseOf(reason, reasonArgs) |
| 76 | + .ForCondition(Subject is PartialViewResult) |
| 77 | + .FailWith(Constants.CommonFailMessage, typeof(PartialViewResult).Name, Subject.GetType().Name); |
| 78 | + |
| 79 | + return new PartialViewResultAssertions(Subject as PartialViewResult); |
| 80 | + } |
| 81 | + |
| 82 | + public RedirectResultAssertions BeRedirectResult() |
| 83 | + { |
| 84 | + return BeRedirectResult(string.Empty, null); |
| 85 | + } |
| 86 | + |
| 87 | + public RedirectResultAssertions BeRedirectResult(string reason, params object[] reasonArgs) |
| 88 | + { |
| 89 | + Execute.Verification |
| 90 | + .BecauseOf(reason, reasonArgs) |
| 91 | + .ForCondition(Subject is RedirectResult) |
| 92 | + .FailWith(Constants.CommonFailMessage, "RedirectResult", Subject.GetType().Name); |
| 93 | + |
| 94 | + return new RedirectResultAssertions(Subject as RedirectResult); |
| 95 | + } |
| 96 | + |
| 97 | + public ViewResultAssertions BeViewResult() |
| 98 | + { |
| 99 | + return BeViewResult(string.Empty, null); |
| 100 | + } |
| 101 | + |
| 102 | + public ViewResultAssertions BeViewResult(string reason, params object[] reasonArgs) |
| 103 | + { |
| 104 | + Execute.Verification |
| 105 | + .BecauseOf(reason, reasonArgs) |
| 106 | + .ForCondition (Subject is ViewResult) |
| 107 | + .FailWith(Constants.CommonFailMessage, "ViewResult", Subject.GetType().Name); |
| 108 | + |
| 109 | + return new ViewResultAssertions (Subject as ViewResult); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments