12
12
public class ResponseModelDetailsTestBuilderTests
13
13
{
14
14
[ Fact ]
15
- public void WithResponseModelShouldNotThrowExceptionWithCorrectAssertions ( )
15
+ public void WithResponseModelShouldNotThrowExceptionPassingCorrectAssertions ( )
16
16
{
17
17
MyController < MvcController >
18
18
. Instance ( )
@@ -28,7 +28,22 @@ public void WithResponseModelShouldNotThrowExceptionWithCorrectAssertions()
28
28
}
29
29
30
30
[ Fact ]
31
- public void WithResponseModelShouldThrowExceptionWithIncorrectAssertions ( )
31
+ public void WithResponseModelShouldNotThrowExceptionWithActionWithCorrectAssertions ( )
32
+ {
33
+ MyController < MvcController >
34
+ . Instance ( )
35
+ . Calling ( c => c . OkResultWithResponse ( ) )
36
+ . ShouldReturn ( )
37
+ . Ok ( ok => ok
38
+ . WithModelOfType < ICollection < ResponseModel > > ( m =>
39
+ {
40
+ Assert . Equal ( 2 , m . Count ) ;
41
+ Assert . Equal ( 1 , m . First ( ) . IntegerValue ) ;
42
+ } ) ) ;
43
+ }
44
+
45
+ [ Fact ]
46
+ public void WithResponseModelShouldThrowExceptionPassingIncorrectAssertions ( )
32
47
{
33
48
Assert . Throws < EqualException > (
34
49
( ) =>
@@ -48,7 +63,26 @@ public void WithResponseModelShouldThrowExceptionWithIncorrectAssertions()
48
63
}
49
64
50
65
[ Fact ]
51
- public void WithResponseModelShouldNotThrowExceptionWithCorrectPredicate ( )
66
+ public void WithResponseModelShouldThrowExceptionWithActionWithIncorrectAssertions ( )
67
+ {
68
+ Assert . Throws < EqualException > (
69
+ ( ) =>
70
+ {
71
+ MyController < MvcController >
72
+ . Instance ( )
73
+ . Calling ( c => c . OkResultWithResponse ( ) )
74
+ . ShouldReturn ( )
75
+ . Ok ( ok => ok
76
+ . WithModelOfType < ICollection < ResponseModel > > ( m =>
77
+ {
78
+ Assert . Equal ( 1 , m . First ( ) . IntegerValue ) ;
79
+ Assert . Equal ( 3 , m . Count ) ;
80
+ } ) ) ;
81
+ } ) ;
82
+ }
83
+
84
+ [ Fact ]
85
+ public void WithResponseModelShouldNotThrowExceptionPassingCorrectPredicate ( )
52
86
{
53
87
MyController < MvcController >
54
88
. Instance ( )
@@ -60,7 +94,18 @@ public void WithResponseModelShouldNotThrowExceptionWithCorrectPredicate()
60
94
}
61
95
62
96
[ Fact ]
63
- public void WithResponseModelShouldThrowExceptionWithWrongPredicate ( )
97
+ public void WithResponseModelShouldNotThrowExceptionWithCorrectPredicate ( )
98
+ {
99
+ MyController < MvcController >
100
+ . Instance ( )
101
+ . Calling ( c => c . OkResultWithResponse ( ) )
102
+ . ShouldReturn ( )
103
+ . Ok ( ok => ok
104
+ . WithModelOfType < ICollection < ResponseModel > > ( m => m . First ( ) . IntegerValue == 1 ) ) ;
105
+ }
106
+
107
+ [ Fact ]
108
+ public void WithResponseModelShouldThrowExceptionPassingWrongPredicate ( )
64
109
{
65
110
Test . AssertException < ResponseModelAssertionException > (
66
111
( ) =>
@@ -75,5 +120,21 @@ public void WithResponseModelShouldThrowExceptionWithWrongPredicate()
75
120
} ,
76
121
"When calling OkResultWithResponse action in MvcController expected response model IList<ResponseModel> to pass the given predicate, but it failed." ) ;
77
122
}
123
+
124
+ [ Fact ]
125
+ public void WithResponseModelShouldThrowExceptionWithWrongPredicate ( )
126
+ {
127
+ Test . AssertException < ResponseModelAssertionException > (
128
+ ( ) =>
129
+ {
130
+ MyController < MvcController >
131
+ . Instance ( )
132
+ . Calling ( c => c . OkResultWithResponse ( ) )
133
+ . ShouldReturn ( )
134
+ . Ok ( ok => ok
135
+ . WithModelOfType < IList < ResponseModel > > ( m => m . First ( ) . IntegerValue == 2 ) ) ;
136
+ } ,
137
+ "When calling OkResultWithResponse action in MvcController expected response model IList<ResponseModel> to pass the given predicate, but it failed." ) ;
138
+ }
78
139
}
79
140
}
0 commit comments