@@ -80,6 +80,33 @@ public void ShouldHaveInvalidModelStateShouldBeValidWithInvalidRequestModel()
8080 . InvalidModelState ( ) ;
8181 }
8282
83+ [ Test ]
84+ public void ShouldHaveInvalidModelStateShouldBeValidWithInvalidRequestModelAndCorrectNumberOfErrors ( )
85+ {
86+ var requestModelWithErrors = TestObjectFactory . GetRequestModelWithErrors ( ) ;
87+
88+ MyWebApi
89+ . Controller < WebApiController > ( )
90+ . Calling ( c => c . ModelStateCheck ( requestModelWithErrors ) )
91+ . ShouldHave ( )
92+ . InvalidModelState ( 2 ) ;
93+ }
94+
95+ [ Test ]
96+ [ ExpectedException (
97+ typeof ( ModelErrorAssertionException ) ,
98+ ExpectedMessage = "When calling ModelStateCheck action in WebApiController expected to have invalid model state with 5 errors, but contained 2." ) ]
99+ public void ShouldHaveInvalidModelStateShouldBeInvalidWithInvalidRequestModelAndIncorrectNumberOfErrors ( )
100+ {
101+ var requestModelWithErrors = TestObjectFactory . GetRequestModelWithErrors ( ) ;
102+
103+ MyWebApi
104+ . Controller < WebApiController > ( )
105+ . Calling ( c => c . ModelStateCheck ( requestModelWithErrors ) )
106+ . ShouldHave ( )
107+ . InvalidModelState ( 5 ) ;
108+ }
109+
83110 [ Test ]
84111 [ ExpectedException (
85112 typeof ( ModelErrorAssertionException ) ,
@@ -95,6 +122,21 @@ public void ShouldHaveInvalidModelStateShouldThrowExceptionWithValidRequestModel
95122 . InvalidModelState ( ) ;
96123 }
97124
125+ [ Test ]
126+ [ ExpectedException (
127+ typeof ( ModelErrorAssertionException ) ,
128+ ExpectedMessage = "When calling ModelStateCheck action in WebApiController expected to have invalid model state with 5 errors, but contained 0." ) ]
129+ public void ShouldHaveInvalidModelStateShouldThrowExceptionWithValidRequestModelAndProvidedNumberOfErrors ( )
130+ {
131+ var requestModel = TestObjectFactory . GetValidRequestModel ( ) ;
132+
133+ MyWebApi
134+ . Controller < WebApiController > ( )
135+ . Calling ( c => c . ModelStateCheck ( requestModel ) )
136+ . ShouldHave ( )
137+ . InvalidModelState ( 5 ) ;
138+ }
139+
98140 [ Test ]
99141 public void AndShouldWorkCorrectlyWithValidModelState ( )
100142 {
0 commit comments