Skip to content

Commit 39f59c6

Browse files
committed
All tests now use the generic version of ShouldPassForThe (#181)
1 parent 6a5e11b commit 39f59c6

File tree

28 files changed

+141
-298
lines changed

28 files changed

+141
-298
lines changed

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/BadRequestTests/BadRequestTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
530530
.Calling(c => c.FullHttpBadRequestAction())
531531
.ShouldReturn()
532532
.BadRequest()
533-
.ShouldPassFor()
534-
.TheActionResult(actionResult =>
533+
.ShouldPassForThe<IActionResult>(actionResult =>
535534
{
536535
Assert.NotNull(actionResult);
537536
Assert.IsAssignableFrom<BadRequestObjectResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/CreatedTests/CreatedTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
962962
.Calling(c => c.CreatedAction())
963963
.ShouldReturn()
964964
.Created()
965-
.ShouldPassFor()
966-
.TheActionResult(actionResult =>
965+
.ShouldPassForThe<IActionResult>(actionResult =>
967966
{
968967
Assert.NotNull(actionResult);
969968
Assert.IsAssignableFrom<CreatedResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/FileTests/FileTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
211211
.Calling(c => c.FileWithContents())
212212
.ShouldReturn()
213213
.File()
214-
.ShouldPassFor()
215-
.TheActionResult(actionResult =>
214+
.ShouldPassForThe<IActionResult>(actionResult =>
216215
{
217216
Assert.NotNull(actionResult);
218217
Assert.IsAssignableFrom<FileResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/HttpNotFoundTests/HttpNotFoundTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
453453
.Calling(c => c.FullHttpNotFoundAction())
454454
.ShouldReturn()
455455
.NotFound()
456-
.ShouldPassFor()
457-
.TheActionResult(actionResult =>
456+
.ShouldPassForThe<IActionResult>(actionResult =>
458457
{
459458
Assert.NotNull(actionResult);
460459
Assert.IsAssignableFrom<NotFoundObjectResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/ObjectTests/ObjectTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
438438
.Calling(c => c.FullObjectResultAction())
439439
.ShouldReturn()
440440
.Object()
441-
.ShouldPassFor()
442-
.TheActionResult(actionResult =>
441+
.ShouldPassForThe<IActionResult>(actionResult =>
443442
{
444443
Assert.NotNull(actionResult);
445444
Assert.IsAssignableFrom<ObjectResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/OkTests/OkTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
465465
.Calling(c => c.FullOkAction())
466466
.ShouldReturn()
467467
.Ok()
468-
.ShouldPassFor()
469-
.TheActionResult(actionResult =>
468+
.ShouldPassForThe<IActionResult>(actionResult =>
470469
{
471470
Assert.NotNull(actionResult);
472471
Assert.IsAssignableFrom<OkObjectResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/RedirectTests/RedirectTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
592592
.Calling(c => c.RedirectToActionResult())
593593
.ShouldReturn()
594594
.Redirect()
595-
.ShouldPassFor()
596-
.TheActionResult(actionResult =>
595+
.ShouldPassForThe<IActionResult>(actionResult =>
597596
{
598597
Assert.NotNull(actionResult);
599598
Assert.IsAssignableFrom<RedirectToActionResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ActionResultsTests/StatusCodeTests/StatusCodeTestBuilderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,7 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
426426
.Calling(c => c.FullObjectResultAction())
427427
.ShouldReturn()
428428
.StatusCode()
429-
.ShouldPassFor()
430-
.TheActionResult(actionResult =>
429+
.ShouldPassForThe<IActionResult>(actionResult =>
431430
{
432431
Assert.NotNull(actionResult);
433432
Assert.IsAssignableFrom<ObjectResult>(actionResult);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/AndTests/AndProvideTestBuilderTests.cs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public void AndProvideShouldReturnProperController()
1818
.ShouldReturn()
1919
.BadRequest()
2020
.WithErrorMessage()
21-
.ShouldPassFor()
22-
.TheController(controller =>
21+
.ShouldPassForThe<MvcController>(controller =>
2322
{
2423
Assert.NotNull(controller);
2524
Assert.IsAssignableFrom<MvcController>(controller);
@@ -33,29 +32,12 @@ public void AndProvideTheControllerAttributesShouldReturnProperAttributes()
3332
.Instance()
3433
.ShouldHave()
3534
.Attributes()
36-
.ShouldPassFor()
37-
.TheControllerAttributes(attributes =>
35+
.ShouldPassForThe<ControllerAttributes>(attributes =>
3836
{
3937
Assert.Equal(2, attributes.Count());
4038
});
4139
}
42-
43-
[Fact]
44-
public void AndProvideShouldReturnProperActionName()
45-
{
46-
MyController<MvcController>
47-
.Instance()
48-
.Calling(c => c.BadRequestWithErrorAction())
49-
.ShouldReturn()
50-
.BadRequest()
51-
.WithErrorMessage()
52-
.ShouldPassFor()
53-
.TheAction(actionName =>
54-
{
55-
Assert.Equal("BadRequestWithErrorAction", actionName);
56-
});
57-
}
58-
40+
5941
[Fact]
6042
public void AndProvideShouldReturnProperActionAttributes()
6143
{
@@ -64,8 +46,7 @@ public void AndProvideShouldReturnProperActionAttributes()
6446
.Calling(c => c.VariousAttributesAction())
6547
.ShouldHave()
6648
.ActionAttributes()
67-
.ShouldPassFor()
68-
.TheActionAttributes(attributes =>
49+
.ShouldPassForThe<ActionAttributes>(attributes =>
6950
{
7051
Assert.Equal(6, attributes.Count());
7152
});
@@ -79,8 +60,7 @@ public void AndProvideShouldReturnProperActionResult()
7960
.Calling(c => c.LocalRedirect("URL"))
8061
.ShouldReturn()
8162
.LocalRedirect()
82-
.ShouldPassFor()
83-
.TheActionResult(actionResult =>
63+
.ShouldPassForThe<IActionResult>(actionResult =>
8464
{
8565
Assert.NotNull(actionResult);
8666
Assert.IsAssignableFrom<LocalRedirectResult>(actionResult);
@@ -95,8 +75,7 @@ public void AndProvideShouldReturnProperCaughtException()
9575
.Calling(c => c.ActionWithException())
9676
.ShouldThrow()
9777
.Exception()
98-
.ShouldPassFor()
99-
.TheCaughtException(caughtException =>
78+
.ShouldPassForThe<Exception>(caughtException =>
10079
{
10180
Assert.NotNull(caughtException);
10281
Assert.IsAssignableFrom<NullReferenceException>(caughtException);

test/MyTested.AspNetCore.Mvc.Controllers.Test/BuildersTests/ControllersTests/ControllerBuilderTests.cs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Extensions.DependencyInjection;
1919
using Microsoft.AspNetCore.Http;
2020
using Microsoft.AspNetCore.Mvc.Controllers;
21+
using Builders.Base;
2122

2223
public class ControllerBuilderTests
2324
{
@@ -60,7 +61,7 @@ public void CallingShouldPopulateCorrectActionNameWithTaskActionCall()
6061

6162
this.CheckActionName(voidActionResultTestBuilder, "EmptyActionAsync");
6263
}
63-
64+
6465
[Fact]
6566
public void CallingShouldHaveValidModelStateWhenThereAreNoModelErrors()
6667
{
@@ -71,10 +72,9 @@ public void CallingShouldHaveValidModelStateWhenThereAreNoModelErrors()
7172
.Calling(c => c.OkResultActionWithRequestBody(1, requestModel))
7273
.ShouldReturn()
7374
.Ok()
74-
.ShouldPassFor()
75-
.TheController(controller =>
75+
.ShouldPassForThe<MvcController>(controller =>
7676
{
77-
var modelState = (controller as Controller).ModelState;
77+
var modelState = controller.ModelState;
7878

7979
Assert.True(modelState.IsValid);
8080
Assert.Equal(0, modelState.Values.Count());
@@ -90,8 +90,7 @@ public void WithAuthenticatedNotCalledShouldNotHaveAuthorizedUser()
9090
.Calling(c => c.AuthorizedAction())
9191
.ShouldReturn()
9292
.NotFound()
93-
.ShouldPassFor()
94-
.TheController(controller =>
93+
.ShouldPassForThe<MvcController>(controller =>
9594
{
9695
var controllerUser = (controller as Controller).User;
9796

@@ -101,7 +100,7 @@ public void WithAuthenticatedNotCalledShouldNotHaveAuthorizedUser()
101100
Assert.Equal(false, controllerUser.Identity.IsAuthenticated);
102101
});
103102
}
104-
103+
105104
[Fact]
106105
public void PrepareControllerShouldSetCorrectPropertiesWithCustomSetup()
107106
{
@@ -111,8 +110,7 @@ public void PrepareControllerShouldSetCorrectPropertiesWithCustomSetup()
111110
{
112111
c.ControllerContext = new ControllerContext();
113112
})
114-
.ShouldPassFor()
115-
.TheController(controller =>
113+
.ShouldPassForThe<MvcController>(controller =>
116114
{
117115
Assert.NotNull(controller);
118116
Assert.NotNull(controller.ControllerContext);
@@ -126,16 +124,15 @@ public void CallingShouldPopulateCorrectActionDescriptor()
126124
MyController<MvcController>
127125
.Instance()
128126
.Calling(c => c.OkResultAction())
129-
.ShouldPassFor()
130-
.TheController(controller =>
127+
.ShouldPassForThe<MvcController>(controller =>
131128
{
132129
Assert.NotNull(controller);
133130
Assert.NotNull((controller as Controller).ControllerContext);
134131
Assert.NotNull((controller as Controller).ControllerContext.ActionDescriptor);
135132
Assert.Equal("OkResultAction", (controller as Controller).ControllerContext.ActionDescriptor.ActionName);
136133
});
137134
}
138-
135+
139136
[Fact]
140137
public void UsingTryUpdateModelAsyncShouldWorkCorrectly()
141138
{
@@ -145,7 +142,7 @@ public void UsingTryUpdateModelAsyncShouldWorkCorrectly()
145142
.ShouldReturn()
146143
.Ok();
147144
}
148-
145+
149146
[Fact]
150147
public void UnresolvedRouteValuesShouldHaveFriendlyException()
151148
{
@@ -190,8 +187,7 @@ public void WithControllerContextShouldSetControllerContext()
190187
MyController<MvcController>
191188
.Instance()
192189
.WithControllerContext(controllerContext)
193-
.ShouldPassFor()
194-
.TheController(controller =>
190+
.ShouldPassForThe<MvcController>(controller =>
195191
{
196192
Assert.NotNull(controller);
197193
Assert.NotNull(controller.ControllerContext);
@@ -208,8 +204,7 @@ public void WithControllerContextSetupShouldSetCorrectControllerContext()
208204
{
209205
controllerContext.RouteData.Values.Add("testkey", "testvalue");
210206
})
211-
.ShouldPassFor()
212-
.TheController(controller =>
207+
.ShouldPassForThe<MvcController>(controller =>
213208
{
214209
Assert.NotNull(controller);
215210
Assert.NotNull(controller.ControllerContext);
@@ -246,14 +241,13 @@ public void InvalidControllerTypeShouldThrowException()
246241
},
247242
"RequestModel is not a valid controller type.");
248243
}
249-
244+
250245
[Fact]
251246
public void PrepareControllerShouldSetCorrectPropertiesWithDefaultServices()
252247
{
253248
MyController<MvcController>
254249
.Instance()
255-
.ShouldPassFor()
256-
.TheController(controller =>
250+
.ShouldPassForThe<MvcController>(controller =>
257251
{
258252
Assert.NotNull(controller);
259253
Assert.NotNull(controller.HttpContext);
@@ -272,16 +266,15 @@ public void PrepareControllerShouldSetCorrectPropertiesWithDefaultServices()
272266
Assert.Null(controller.ControllerContext.ActionDescriptor);
273267
});
274268
}
275-
269+
276270
private void CheckActionResultTestBuilder<TActionResult>(
277271
IActionResultTestBuilder<TActionResult> actionResultTestBuilder,
278272
string expectedActionName)
279273
{
280274
this.CheckActionName(actionResultTestBuilder, expectedActionName);
281275

282276
actionResultTestBuilder
283-
.ShouldPassFor()
284-
.TheActionResult(actionResult =>
277+
.ShouldPassForThe<MvcController>(actionResult =>
285278
{
286279
Assert.NotNull(actionResult);
287280
Assert.IsAssignableFrom<OkResult>(actionResult);
@@ -290,14 +283,11 @@ private void CheckActionResultTestBuilder<TActionResult>(
290283

291284
private void CheckActionName(IBaseTestBuilderWithInvokedAction testBuilder, string expectedActionName)
292285
{
293-
testBuilder
294-
.ShouldPassFor()
295-
.TheAction(actionName =>
296-
{
297-
Assert.NotNull(actionName);
298-
Assert.NotEmpty(actionName);
299-
Assert.Equal(expectedActionName, actionName);
300-
});
286+
var actionName = (testBuilder as BaseTestBuilderWithInvokedAction)?.ActionName;
287+
288+
Assert.NotNull(actionName);
289+
Assert.NotEmpty(actionName);
290+
Assert.Equal(expectedActionName, actionName);
301291
}
302292
}
303293
}

0 commit comments

Comments
 (0)