1212 public class ResponseModelDetailsTestBuilderTests
1313 {
1414 [ Fact ]
15- public void WithResponseModelShouldNotThrowExceptionWithCorrectAssertions ( )
15+ public void WithResponseModelShouldNotThrowExceptionPassingCorrectAssertions ( )
1616 {
1717 MyController < MvcController >
1818 . Instance ( )
@@ -28,7 +28,22 @@ public void WithResponseModelShouldNotThrowExceptionWithCorrectAssertions()
2828 }
2929
3030 [ 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 ( )
3247 {
3348 Assert . Throws < EqualException > (
3449 ( ) =>
@@ -48,7 +63,26 @@ public void WithResponseModelShouldThrowExceptionWithIncorrectAssertions()
4863 }
4964
5065 [ 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 ( )
5286 {
5387 MyController < MvcController >
5488 . Instance ( )
@@ -60,7 +94,18 @@ public void WithResponseModelShouldNotThrowExceptionWithCorrectPredicate()
6094 }
6195
6296 [ 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 ( )
64109 {
65110 Test . AssertException < ResponseModelAssertionException > (
66111 ( ) =>
@@ -75,5 +120,21 @@ public void WithResponseModelShouldThrowExceptionWithWrongPredicate()
75120 } ,
76121 "When calling OkResultWithResponse action in MvcController expected response model IList<ResponseModel> to pass the given predicate, but it failed." ) ;
77122 }
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+ }
78139 }
79140}
0 commit comments