MvcIntegrationTestFramework 1.0.8
dotnet add package MvcIntegrationTestFramework --version 1.0.8
NuGet\Install-Package MvcIntegrationTestFramework -Version 1.0.8
<PackageReference Include="MvcIntegrationTestFramework" Version="1.0.8" />
paket add MvcIntegrationTestFramework --version 1.0.8
#r "nuget: MvcIntegrationTestFramework, 1.0.8"
// Install MvcIntegrationTestFramework as a Cake Addin #addin nuget:?package=MvcIntegrationTestFramework&version=1.0.8 // Install MvcIntegrationTestFramework as a Cake Tool #tool nuget:?package=MvcIntegrationTestFramework&version=1.0.8
MvcIntegrationTestFramework
Integration test harness for ASP.Net MVC 5. Allows you to fully integration test an MVC web project without needing to host under IIS or similar. Allows access to both server state and client responses in a single assertion.
https://www.nuget.org/packages/MvcIntegrationTestFramework
This fork targets MVC 5, VS2015.
Everything should just work out of the box, no need for post build steps.
Usage
In your test set-up start a new AppHost targeting the folder containing your MVC application:
this.appHost = AppHost.Simulate("MyMvcApplication");
Then for each test flow, start a browsing session, make your calls and assert against the results:
this.appHost.Start(browsingSession =>
{
// Request the root URL
RequestResult result = browsingSession.Get("/welcome");
// Check the result status
Assert.That(result.IsSuccess);
// Make assertions about the ActionResult
var viewResult = (ViewResult)result.ActionExecutedContext.Result;
Assert.AreEqual("Index", viewResult.ViewName);
Assert.AreEqual("Welcome to ASP.NET MVC!", viewResult.ViewData["Message"]);
// Or make assertions about the rendered HTML
Assert.IsTrue(result.ResponseText.Contains("<!DOCTYPE html"));
});
See the MyMvcApplication.Tests
project and the HomeControllerTests.cs
file for more examples.
The framework injects it's own System.Web.Optimization bundle provider, which supplies blank CSS and Javascript files.
Known issues
Simple Injector
Simple Injector's [assembly: WebActivator.PostApplicationStartMethod(...)]
injection can cause problems with the ASP.Net hosting enviroment.
You can remove the assembly level injector and call your setup from Global.aspx
to solve this.
TFS Builds
TFS Build servers can restructure your project, causing the test framework to not find the MVC project directory.
To work around this, you can pass multiple potential locations for your project to the Simulate
function, and the first one to be found will be used.
For example,
appHost = AppHost.Simulate(
"Source\\Web\\MyMvcApplication", // Local solution location
"a\\_PublishedWebsites\\MyMvcApplication"); // TFS build system, under ...\Agent\_work\1\a\_PublishedWebsites ...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. 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.3)
- Microsoft.AspNet.Razor (>= 3.2.3)
- Microsoft.AspNet.Web.Optimization (>= 1.1.3)
- Microsoft.AspNet.WebPages (>= 3.2.3)
- Microsoft.Web.Infrastructure (>= 1.0.0)
- WebGrease (>= 1.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Adding dll resolve-by-name flag to AppHost