SparkyTestHelpers.AspNetMvc
1.0.1
See the version list below for details.
dotnet add package SparkyTestHelpers.AspNetMvc --version 1.0.1
NuGet\Install-Package SparkyTestHelpers.AspNetMvc -Version 1.0.1
<PackageReference Include="SparkyTestHelpers.AspNetMvc" Version="1.0.1" />
paket add SparkyTestHelpers.AspNetMvc --version 1.0.1
#r "nuget: SparkyTestHelpers.AspNetMvc, 1.0.1"
// Install SparkyTestHelpers.AspNetMvc as a Cake Addin #addin nuget:?package=SparkyTestHelpers.AspNetMvc&version=1.0.1 // Install SparkyTestHelpers.AspNetMvc as a Cake Tool #tool nuget:?package=SparkyTestHelpers.AspNetMvc&version=1.0.1
see also:
- SparkyTestHelpers.AspNetMvc.Core - the .NET Core version of this package
- the rest of the "Sparky suite" of .NET utilities and test helpers
ControllerTester<TController>
Instantiation:
using SparkyTestHelpers.AspNetMvc
var homeController = new HomeController(/* with test dependencies */);
var controllerTester = new ControllerTester<HomeController>(homeController);
It doesn't do anything on its own - just provides an Action(actionDefinitionExpression) method that's used to create a...
ControllerActionTester
var controllerActionTester =
new ControllerTester<HomeController>(homeController).Action(x => x.Index);
ControllerActionTester has several .Test... methods used to assert that the controller action returns the expected ActionResult implementation. There are methods for all of the standard result types, plus the generic TestResult<TActionResultType> method:
- .TestContent(Action<ContentResult> validate)
- .TestEmpty(Action<EmptyResult> validate)
- .TestFile(Action<FileResult> validate)
- .TestJson(Action<JsonResult> validate)
- .TestPartialView(Action<PartialViewResult> validate)
- .TestRedirect(string expectedUrl, Action<RedirectResult> validate)
- .TestRedirectToAction(string expecteActionName, Action<RedirectToRouteResult> validate)
- .TestRedirectToRoute(string expectedRoute, Action<RedirectToRouteResult> validate)
- .TestView(Action<ViewResult> validate)
- .TestResult<TActionResultType>(Action<TActionResultType> validate)
Additional methods:
- .ExpectingViewName(string expectedViewName) - used with .TestView and .TestPartialView
- .ExpectingModel<TModelType>(Action<TModelType> validate) - using with .TestView and .TestJson
- WhenModelStateIsValidEquals(bool isValid) - used to test conditional logic based on ModelState.IsValid
All validate "callback" actions shown above are optional.
Examples
var homeController = new HomeController(/* with test dependencies */);
var controllerTester = new ControllerTester<HomeController>(homeController);
controllerTester.Action(x => x.Index).TestView();
controllerTester
.Action(x => () => x.Details(3))
.ExpectingViewName("Details")
.ExpectingModel<Foo>(foo => Assert.IsTrue(foo.IsValid))
.TestView();
controllerTester
.Action(x => () => x.Edit(updateModel))
.WhenModelStateIsValidEquals(false)
.TestRedirectToAction("Errors");
controllerTester
.Action(x => () => x.Edit(updateModel))
.WhenModelStateIsValidEquals(true)
.ExpectingViewName("UpdateSuccessful")
.TestRedirectToRoute("Home/UpdateSuccessful");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- Microsoft.AspNet.Mvc (>= 5.2.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.6.8 | 1,832 | 3/5/2021 |
1.6.7 | 392 | 3/5/2021 |
1.6.6 | 395 | 2/28/2021 |
1.6.4 | 418 | 2/24/2021 |
1.6.3 | 365 | 2/23/2021 |
1.6.2 | 439 | 2/23/2021 |
1.6.1 | 357 | 2/22/2021 |
1.6.0 | 357 | 2/22/2021 |
1.5.0 | 359 | 2/20/2021 |
1.4.0 | 419 | 1/7/2021 |
1.3.1 | 1,360 | 5/18/2019 |
1.3.0 | 1,099 | 3/31/2018 |
1.2.0 | 952 | 3/28/2018 |
1.1.0 | 858 | 3/26/2018 |
1.0.1 | 980 | 3/22/2018 |
1.0.0 | 1,012 | 3/22/2018 |
v1.0.2: simplified dependencies