5
5
using Blog . Controllers . Models ;
6
6
using Blog . Data . Models ;
7
7
using Data ;
8
+ using FluentAssertions ;
8
9
using MyTested . AspNetCore . Mvc ;
9
10
using Services ;
10
11
using Services . Models ;
11
- using Shouldly ;
12
12
using System . Linq ;
13
13
using Xunit ;
14
14
@@ -28,9 +28,9 @@ public void AllShouldReturnDefaultViewWithCorrectModel(int total, int page, int
28
28
. WithModelOfType < ArticleListingViewModel > ( )
29
29
. Passing ( articleListing =>
30
30
{
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 ) ;
34
34
} ) ) ;
35
35
36
36
[ Fact ]
@@ -44,17 +44,17 @@ public void DetailsShouldReturnNotFoundWhenInvalidArticleId()
44
44
[ Fact ]
45
45
public void DetailsShouldReturnNotFoundWhenNonPublicArticleAndAnonymousUser ( )
46
46
=> MyController < ArticlesController >
47
- . Instance ( )
48
- . WithData ( ArticleTestData . GetArticles ( 1 , isPublic : false ) )
47
+ . Instance ( instance => instance
48
+ . WithData ( ArticleTestData . GetArticles ( 1 , isPublic : false ) ) )
49
49
. Calling ( c => c . Details ( 1 ) )
50
50
. ShouldReturn ( )
51
51
. NotFound ( ) ;
52
52
53
53
[ Fact ]
54
54
public void DetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndAnonymousUser ( )
55
55
=> MyController < ArticlesController >
56
- . Instance ( )
57
- . WithData ( ArticleTestData . GetArticles ( 1 ) )
56
+ . Instance ( instance => instance
57
+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
58
58
. Calling ( c => c . Details ( 1 ) )
59
59
. ShouldReturn ( )
60
60
. View ( view => view
@@ -64,19 +64,19 @@ public void DetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndAnonymous
64
64
[ Fact ]
65
65
public void DetailsShouldReturnNotFoundWhenNonPublicArticleAndNonAdministratorNonAuthorUser ( )
66
66
=> 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 ) ) )
70
70
. Calling ( c => c . Details ( 1 ) )
71
71
. ShouldReturn ( )
72
72
. NotFound ( ) ;
73
73
74
74
[ Fact ]
75
75
public void DetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndNonAdministratorNonAuthorUser ( )
76
76
=> MyController < ArticlesController >
77
- . Instance ( )
78
- . WithUser ( "NonAuthor" )
79
- . WithData ( ArticleTestData . GetArticles ( 1 ) )
77
+ . Instance ( instance => instance
78
+ . WithUser ( "NonAuthor" )
79
+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
80
80
. Calling ( c => c . Details ( 1 ) )
81
81
. ShouldReturn ( )
82
82
. View ( view => view
@@ -93,9 +93,9 @@ public void DetailsShouldReturnViewWithCorrectModelWhenCorrectUser(
93
93
string username ,
94
94
string role )
95
95
=> 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 ) ) )
99
99
. Calling ( c => c . Details ( 1 ) )
100
100
. ShouldReturn ( )
101
101
. View ( view => view
@@ -138,7 +138,7 @@ public void CreatePostShouldReturnViewWithSameModelWhenInvalidModelState()
138
138
139
139
[ Theory ]
140
140
[ InlineData ( "Article Title" , "Article Content" ) ]
141
- public void CreatePostShouldSaveArticleSetModelStateMessageAndRedirectWhenValidModelState ( string title , string content )
141
+ public void CreatePostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel ( string title , string content )
142
142
=> MyController < ArticlesController >
143
143
. Instance ( )
144
144
. Calling ( c => c . Create ( new ArticleFormModel
@@ -151,11 +151,15 @@ public void CreatePostShouldSaveArticleSetModelStateMessageAndRedirectWhenValidM
151
151
. AndAlso ( )
152
152
. ShouldHave ( )
153
153
. 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
+ ) )
159
163
. AndAlso ( )
160
164
. ShouldHave ( )
161
165
. TempData ( tempData => tempData
@@ -186,9 +190,9 @@ public void EditGetShouldReturnNotFoundWhenInvalidId()
186
190
[ Fact ]
187
191
public void EditGetShouldReturnNotFoundWhenNonAuthorUser ( )
188
192
=> MyController < ArticlesController >
189
- . Instance ( )
190
- . WithUser ( "NonAuthor" )
191
- . WithData ( ArticleTestData . GetArticles ( 1 ) )
193
+ . Instance ( instance => instance
194
+ . WithUser ( "NonAuthor" )
195
+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
192
196
. Calling ( c => c . Edit ( 1 ) )
193
197
. ShouldReturn ( )
194
198
. NotFound ( ) ;
@@ -198,9 +202,9 @@ public void EditGetShouldReturnNotFoundWhenNonAuthorUser()
198
202
[ InlineData ( 1 , "Administrator" , ControllerConstants . AdministratorRole ) ]
199
203
public void EditGetShouldReturnViewWithCorrectModelWhenCorrectUser ( int articleId , string username , string role )
200
204
=> 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 ) ) )
204
208
. Calling ( c => c . Edit ( articleId ) )
205
209
. ShouldReturn ( )
206
210
. View ( view => view
@@ -232,19 +236,19 @@ public void EditPostShouldReturnNotFoundWhenInvalidId()
232
236
[ Fact ]
233
237
public void EditPostShouldReturnNotFoundWhenNonAuthorUser ( )
234
238
=> 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 ) ) )
238
242
. Calling ( c => c . Edit ( 1 , With . Empty < ArticleFormModel > ( ) ) )
239
243
. ShouldReturn ( )
240
244
. NotFound ( ) ;
241
245
242
246
[ Fact ]
243
247
public void EditPostShouldReturnViewWithSameModelWhenInvalidModelState ( )
244
248
=> MyController < ArticlesController >
245
- . Instance ( )
246
- . WithUser ( )
247
- . WithData ( ArticleTestData . GetArticles ( 1 ) )
249
+ . Instance ( instance => instance
250
+ . WithUser ( )
251
+ . WithData ( ArticleTestData . GetArticles ( 1 ) ) )
248
252
. Calling ( c => c . Edit ( 1 , With . Default < ArticleFormModel > ( ) ) )
249
253
. ShouldHave ( )
250
254
. InvalidModelState ( )
@@ -262,9 +266,9 @@ public void EditPostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel
262
266
string username ,
263
267
string role )
264
268
=> 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 ) ) )
268
272
. Calling ( c => c . Edit ( articleId , new ArticleFormModel
269
273
{
270
274
Title = $ "Edit { title } ",
@@ -277,13 +281,13 @@ public void EditPostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel
277
281
. Data ( data => data
278
282
. WithSet < Article > ( set =>
279
283
{
280
- set . ShouldNotBeEmpty ( ) ;
284
+ set . Should ( ) . NotBeEmpty ( ) ;
281
285
282
286
var article = set . SingleOrDefault ( a => a . Id == articleId ) ;
283
287
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 } ") ;
287
291
} ) )
288
292
. AndAlso ( )
289
293
. ShouldHave ( )
@@ -314,9 +318,9 @@ public void DeleteShouldReturnNotFoundWhenInvalidId()
314
318
[ Fact ]
315
319
public void DeleteShouldReturnNotFoundWhenNonAuthorUser ( )
316
320
=> 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 ) ) )
320
324
. Calling ( c => c . Delete ( 1 ) )
321
325
. ShouldReturn ( )
322
326
. NotFound ( ) ;
@@ -326,9 +330,9 @@ public void DeleteShouldReturnNotFoundWhenNonAuthorUser()
326
330
[ InlineData ( 1 , "Administrator" , ControllerConstants . AdministratorRole ) ]
327
331
public void DeleteShouldReturnViewWithCorrectModelWhenCorrectUser ( int articleId , string username , string role )
328
332
=> 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 ) ) )
332
336
. Calling ( c => c . Delete ( articleId ) )
333
337
. ShouldReturn ( )
334
338
. View ( articleId ) ;
@@ -353,9 +357,9 @@ public void ConfirmDeleteShouldReturnNotFoundWhenInvalidId()
353
357
[ Fact ]
354
358
public void ConfirmDeleteShouldReturnNotFoundWhenNonAuthorUser ( )
355
359
=> 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 ) ) )
359
363
. Calling ( c => c . ConfirmDelete ( 1 ) )
360
364
. ShouldReturn ( )
361
365
. NotFound ( ) ;
@@ -368,13 +372,13 @@ public void ConfirmDeleteShouldDeleteArticleSetTempDataMessageAndRedirectWhenVal
368
372
string username ,
369
373
string role )
370
374
=> 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 ) ) )
374
378
. Calling ( c => c . ConfirmDelete ( articleId ) )
375
379
. ShouldHave ( )
376
380
. Data ( data => data
377
- . WithSet < Article > ( set => set . ShouldBeEmpty ( ) ) )
381
+ . WithSet < Article > ( set => set . Should ( ) . NotBeNull ( ) ) )
378
382
. AndAlso ( )
379
383
. ShouldHave ( )
380
384
. TempData ( tempData => tempData
@@ -396,17 +400,20 @@ public void MineShouldHaveRestrictionsForAuthorizedUsers()
396
400
[ Fact ]
397
401
public void MineShouldReturnViewWithCorrectModel ( )
398
402
=> 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 ) ) )
402
406
. Calling ( c => c . Mine ( ) )
403
407
. ShouldReturn ( )
404
408
. View ( view => view
405
409
. 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 ( ) ) ) ;
411
418
}
412
419
}
0 commit comments