55 using Blog . Controllers . Models ;
66 using Blog . Data . Models ;
77 using Data ;
8+ using FluentAssertions ;
89 using MyTested . AspNetCore . Mvc ;
910 using Services ;
1011 using Services . Models ;
11- using Shouldly ;
1212 using System . Linq ;
1313 using Xunit ;
1414
@@ -28,9 +28,9 @@ public void AllShouldReturnDefaultViewWithCorrectModel(int total, int page, int
2828 . WithModelOfType < ArticleListingViewModel > ( )
2929 . Passing ( articleListing =>
3030 {
31- articleListing . Articles . Count ( ) . ShouldBe ( expectedCount ) ;
32- articleListing . Total . ShouldBe ( total ) ;
33- articleListing . Page . ShouldBe ( page ) ;
31+ articleListing . Articles . Should ( ) . HaveCount ( expectedCount ) ;
32+ articleListing . Total . Should ( ) . Be ( total ) ;
33+ articleListing . Page . Should ( ) . Be ( page ) ;
3434 } ) ) ;
3535
3636 [ Fact ]
@@ -44,17 +44,17 @@ public void DetailsShouldReturnNotFoundWhenInvalidArticleId()
4444 [ Fact ]
4545 public void DetailsShouldReturnNotFoundWhenNonPublicArticleAndAnonymousUser ( )
4646 => MyController < ArticlesController >
47- . Instance ( )
48- . WithData ( ArticleTestData . GetArticles ( 1 , isPublic : false ) )
47+ . Instance ( instance => instance
48+ . WithData ( ArticleTestData . GetArticles ( 1 , isPublic : false ) ) )
4949 . Calling ( c => c . Details ( 1 ) )
5050 . ShouldReturn ( )
5151 . NotFound ( ) ;
5252
5353 [ Fact ]
5454 public void DetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndAnonymousUser ( )
5555 => MyController < ArticlesController >
56- . Instance ( )
57- . WithData ( ArticleTestData . GetArticles ( 1 ) )
56+ . Instance ( instance => instance
57+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
5858 . Calling ( c => c . Details ( 1 ) )
5959 . ShouldReturn ( )
6060 . View ( view => view
@@ -64,19 +64,19 @@ public void DetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndAnonymous
6464 [ Fact ]
6565 public void DetailsShouldReturnNotFoundWhenNonPublicArticleAndNonAdministratorNonAuthorUser ( )
6666 => MyController < ArticlesController >
67- . Instance ( )
68- . WithUser ( "NonAuthor" )
69- . WithData ( ArticleTestData . GetArticles ( 1 , isPublic : false ) )
67+ . Instance ( instance => instance
68+ . WithUser ( "NonAuthor" )
69+ . WithData ( ArticleTestData . GetArticles ( 1 , isPublic : false ) ) )
7070 . Calling ( c => c . Details ( 1 ) )
7171 . ShouldReturn ( )
7272 . NotFound ( ) ;
7373
7474 [ Fact ]
7575 public void DetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndNonAdministratorNonAuthorUser ( )
7676 => MyController < ArticlesController >
77- . Instance ( )
78- . WithUser ( "NonAuthor" )
79- . WithData ( ArticleTestData . GetArticles ( 1 ) )
77+ . Instance ( instance => instance
78+ . WithUser ( "NonAuthor" )
79+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
8080 . Calling ( c => c . Details ( 1 ) )
8181 . ShouldReturn ( )
8282 . View ( view => view
@@ -93,9 +93,9 @@ public void DetailsShouldReturnViewWithCorrectModelWhenCorrectUser(
9393 string username ,
9494 string role )
9595 => MyController < ArticlesController >
96- . Instance ( )
97- . WithUser ( username , new [ ] { role } )
98- . WithData ( ArticleTestData . GetArticles ( 1 , isPublic ) )
96+ . Instance ( instance => instance
97+ . WithUser ( username , new [ ] { role } )
98+ . WithData ( ArticleTestData . GetArticles ( 1 , isPublic ) ) )
9999 . Calling ( c => c . Details ( 1 ) )
100100 . ShouldReturn ( )
101101 . View ( view => view
@@ -138,7 +138,7 @@ public void CreatePostShouldReturnViewWithSameModelWhenInvalidModelState()
138138
139139 [ Theory ]
140140 [ InlineData ( "Article Title" , "Article Content" ) ]
141- public void CreatePostShouldSaveArticleSetModelStateMessageAndRedirectWhenValidModelState ( string title , string content )
141+ public void CreatePostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel ( string title , string content )
142142 => MyController < ArticlesController >
143143 . Instance ( )
144144 . Calling ( c => c . Create ( new ArticleFormModel
@@ -151,11 +151,15 @@ public void CreatePostShouldSaveArticleSetModelStateMessageAndRedirectWhenValidM
151151 . AndAlso ( )
152152 . ShouldHave ( )
153153 . Data ( data => data
154- . WithSet < Article > ( set =>
155- {
156- set . ShouldNotBeEmpty ( ) ;
157- set . SingleOrDefault ( a => a . Title == title ) . ShouldNotBeNull ( ) ;
158- } ) )
154+ . WithSet < Article > ( set => set
155+ . Should ( )
156+ . NotBeEmpty ( )
157+ . And
158+ . Subject
159+ . SingleOrDefault ( a => a . Title == title )
160+ . Should ( )
161+ . NotBeNull ( )
162+ ) )
159163 . AndAlso ( )
160164 . ShouldHave ( )
161165 . TempData ( tempData => tempData
@@ -186,9 +190,9 @@ public void EditGetShouldReturnNotFoundWhenInvalidId()
186190 [ Fact ]
187191 public void EditGetShouldReturnNotFoundWhenNonAuthorUser ( )
188192 => MyController < ArticlesController >
189- . Instance ( )
190- . WithUser ( "NonAuthor" )
191- . WithData ( ArticleTestData . GetArticles ( 1 ) )
193+ . Instance ( instance => instance
194+ . WithUser ( "NonAuthor" )
195+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
192196 . Calling ( c => c . Edit ( 1 ) )
193197 . ShouldReturn ( )
194198 . NotFound ( ) ;
@@ -198,9 +202,9 @@ public void EditGetShouldReturnNotFoundWhenNonAuthorUser()
198202 [ InlineData ( 1 , "Administrator" , ControllerConstants . AdministratorRole ) ]
199203 public void EditGetShouldReturnViewWithCorrectModelWhenCorrectUser ( int articleId , string username , string role )
200204 => MyController < ArticlesController >
201- . Instance ( )
202- . WithUser ( username , new [ ] { role } )
203- . WithData ( ArticleTestData . GetArticles ( articleId ) )
205+ . Instance ( instance => instance
206+ . WithUser ( username , new [ ] { role } )
207+ . WithData ( ArticleTestData . GetArticles ( articleId ) ) )
204208 . Calling ( c => c . Edit ( articleId ) )
205209 . ShouldReturn ( )
206210 . View ( view => view
@@ -232,19 +236,19 @@ public void EditPostShouldReturnNotFoundWhenInvalidId()
232236 [ Fact ]
233237 public void EditPostShouldReturnNotFoundWhenNonAuthorUser ( )
234238 => MyController < ArticlesController >
235- . Instance ( )
236- . WithUser ( user => user . WithIdentifier ( "NonAuthor" ) )
237- . WithData ( ArticleTestData . GetArticles ( 1 ) )
239+ . Instance ( instance => instance
240+ . WithUser ( user => user . WithIdentifier ( "NonAuthor" ) )
241+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
238242 . Calling ( c => c . Edit ( 1 , With . Empty < ArticleFormModel > ( ) ) )
239243 . ShouldReturn ( )
240244 . NotFound ( ) ;
241245
242246 [ Fact ]
243247 public void EditPostShouldReturnViewWithSameModelWhenInvalidModelState ( )
244248 => MyController < ArticlesController >
245- . Instance ( )
246- . WithUser ( )
247- . WithData ( ArticleTestData . GetArticles ( 1 ) )
249+ . Instance ( instance => instance
250+ . WithUser ( )
251+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
248252 . Calling ( c => c . Edit ( 1 , With . Default < ArticleFormModel > ( ) ) )
249253 . ShouldHave ( )
250254 . InvalidModelState ( )
@@ -262,9 +266,9 @@ public void EditPostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel
262266 string username ,
263267 string role )
264268 => MyController < ArticlesController >
265- . Instance ( )
266- . WithUser ( username , new [ ] { role } )
267- . WithData ( ArticleTestData . GetArticles ( 1 ) )
269+ . Instance ( instance => instance
270+ . WithUser ( username , new [ ] { role } )
271+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
268272 . Calling ( c => c . Edit ( articleId , new ArticleFormModel
269273 {
270274 Title = $ "Edit { title } ",
@@ -277,13 +281,13 @@ public void EditPostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel
277281 . Data ( data => data
278282 . WithSet < Article > ( set =>
279283 {
280- set . ShouldNotBeEmpty ( ) ;
284+ set . Should ( ) . NotBeEmpty ( ) ;
281285
282286 var article = set . SingleOrDefault ( a => a . Id == articleId ) ;
283287
284- article . ShouldNotBeNull ( ) ;
285- article . Title . ShouldBe ( $ "Edit { title } ") ;
286- article . Content . ShouldBe ( $ "Edit { content } ") ;
288+ article . Should ( ) . NotBeNull ( ) ;
289+ article . Title . Should ( ) . Be ( $ "Edit { title } ") ;
290+ article . Content . Should ( ) . Be ( $ "Edit { content } ") ;
287291 } ) )
288292 . AndAlso ( )
289293 . ShouldHave ( )
@@ -314,9 +318,9 @@ public void DeleteShouldReturnNotFoundWhenInvalidId()
314318 [ Fact ]
315319 public void DeleteShouldReturnNotFoundWhenNonAuthorUser ( )
316320 => MyController < ArticlesController >
317- . Instance ( )
318- . WithUser ( user => user . WithIdentifier ( "NonAuthor" ) )
319- . WithData ( ArticleTestData . GetArticles ( 1 ) )
321+ . Instance ( instance => instance
322+ . WithUser ( user => user . WithIdentifier ( "NonAuthor" ) )
323+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
320324 . Calling ( c => c . Delete ( 1 ) )
321325 . ShouldReturn ( )
322326 . NotFound ( ) ;
@@ -326,9 +330,9 @@ public void DeleteShouldReturnNotFoundWhenNonAuthorUser()
326330 [ InlineData ( 1 , "Administrator" , ControllerConstants . AdministratorRole ) ]
327331 public void DeleteShouldReturnViewWithCorrectModelWhenCorrectUser ( int articleId , string username , string role )
328332 => MyController < ArticlesController >
329- . Instance ( )
330- . WithUser ( username , new [ ] { role } )
331- . WithData ( ArticleTestData . GetArticles ( articleId ) )
333+ . Instance ( instance => instance
334+ . WithUser ( username , new [ ] { role } )
335+ . WithData ( ArticleTestData . GetArticles ( articleId ) ) )
332336 . Calling ( c => c . Delete ( articleId ) )
333337 . ShouldReturn ( )
334338 . View ( articleId ) ;
@@ -353,9 +357,9 @@ public void ConfirmDeleteShouldReturnNotFoundWhenInvalidId()
353357 [ Fact ]
354358 public void ConfirmDeleteShouldReturnNotFoundWhenNonAuthorUser ( )
355359 => MyController < ArticlesController >
356- . Instance ( )
357- . WithUser ( user => user . WithIdentifier ( "NonAuthor" ) )
358- . WithData ( ArticleTestData . GetArticles ( 1 ) )
360+ . Instance ( instance => instance
361+ . WithUser ( user => user . WithIdentifier ( "NonAuthor" ) )
362+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
359363 . Calling ( c => c . ConfirmDelete ( 1 ) )
360364 . ShouldReturn ( )
361365 . NotFound ( ) ;
@@ -368,13 +372,13 @@ public void ConfirmDeleteShouldDeleteArticleSetTempDataMessageAndRedirectWhenVal
368372 string username ,
369373 string role )
370374 => MyController < ArticlesController >
371- . Instance ( )
372- . WithUser ( username , new [ ] { role } )
373- . WithData ( ArticleTestData . GetArticles ( articleId ) )
375+ . Instance ( instance => instance
376+ . WithUser ( username , new [ ] { role } )
377+ . WithData ( ArticleTestData . GetArticles ( articleId ) ) )
374378 . Calling ( c => c . ConfirmDelete ( articleId ) )
375379 . ShouldHave ( )
376380 . Data ( data => data
377- . WithSet < Article > ( set => set . ShouldBeEmpty ( ) ) )
381+ . WithSet < Article > ( set => set . Should ( ) . NotBeNull ( ) ) )
378382 . AndAlso ( )
379383 . ShouldHave ( )
380384 . TempData ( tempData => tempData
@@ -396,17 +400,20 @@ public void MineShouldHaveRestrictionsForAuthorizedUsers()
396400 [ Fact ]
397401 public void MineShouldReturnViewWithCorrectModel ( )
398402 => MyController < ArticlesController >
399- . Instance ( )
400- . WithUser ( "Author Id 1" , "Author 1" )
401- . WithData ( ArticleTestData . GetArticles ( 2 , sameUser : false ) )
403+ . Instance ( instance => instance
404+ . WithUser ( "Author Id 1" , "Author 1" )
405+ . WithData ( ArticleTestData . GetArticles ( 2 , sameUser : false ) ) )
402406 . Calling ( c => c . Mine ( ) )
403407 . ShouldReturn ( )
404408 . View ( view => view
405409 . WithModelOfType < List < ArticleForUserListingServiceModel > > ( )
406- . Passing ( articles =>
407- {
408- articles . ShouldNotBeEmpty ( ) ;
409- articles . SingleOrDefault ( a => a . Author == "Author 1" ) . ShouldNotBeNull ( ) ;
410- } ) ) ;
410+ . Passing ( articles => articles
411+ . Should ( )
412+ . NotBeEmpty ( )
413+ . And
414+ . Subject
415+ . SingleOrDefault ( a => a . Author == "Author 1" )
416+ . Should ( )
417+ . NotBeNull ( ) ) ) ;
411418 }
412419}
0 commit comments