TestBase-Mvc 4.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TestBase-Mvc --version 4.0.0
NuGet\Install-Package TestBase-Mvc -Version 4.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TestBase-Mvc" Version="4.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TestBase-Mvc --version 4.0.0
#r "nuget: TestBase-Mvc, 4.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TestBase-Mvc as a Cake Addin
#addin nuget:?package=TestBase-Mvc&version=4.0.0

// Install TestBase-Mvc as a Cake Tool
#tool nuget:?package=TestBase-Mvc&version=4.0.0

TestBase gives you a flying start with

  • fluent assertions that are easy to extend
  • sharp error messages
  • tools to help you test with "heavyweight" dependencies on
    • AspNet.Mvc or AspNetCore Contexts
    • HttpClient
    • Ado.Net
    • Streams & Logging
  • Mix & match with your favourite test runners and assertions.

TestBase.Mvc for Mvc4 and Mvc5

Use the Controller.WithHttpContextAndRoutes() extension methods to fake the http request & context, enabling you to unit test with dependecies on Controller.Url(), Request.Cookies, Response.Cookies Request.QueryString and more. By passing in your own MvcApplication's actual RegisterRoutes() method , you can verify Controller.Url with your application's actual routes.

var controllerUnderTest = new AController().WithHttpContextAndRoutes();

controllerUnderTest
    .Action("SomeController","SomeAction",other:1)
    .ShouldBeViewWithModel<AClass>("ViewName");
        .FooterLink
        .ShouldBe("/Controller/Action?other=1");

ControllerUnderTest
  .WithHttpContextAndRoutes(
    [Optional] Action<RouteCollection> mvcApplicationRoutesRegistration, 
    [optional] string requestUrl,
    [Optional] string query = "",
    [Optional] string appVirtualPath = "/",
    [Optional] HttpApplication applicationInstance)

ApiControllerUnderTest.WithWebApiHttpContext&lt;T&gt;(
    HttpMethod httpMethod, 
    [Optional] string requestUri,
    [Optional] string routeTemplate)

Chainable fluent assertions get you to the point concisely:

ControllerUnderTest.Action()
  .ShouldbeViewResult()
  .ShouldHaveModel<TModel>()
  .ShouldEqualByValue(expected)
ControllerUnderTest.Action()
  .ShouldBeRedirectToRouteResult()
  .ShouldHaveRouteValue("expectedKey", [Optional] "expectedValue");

ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc.

.ShouldEqualByValue().ShouldEqualByValueExceptFor(...).ShouldEqualByValueOnMembers()
  work with all kinds of object and collections, and report what differed.
string.ShouldMatch(pattern).ShouldNotMatch().ShouldBeEmpty().ShouldNotBeEmpty()
.ShouldNotBeNullOrEmptyOrWhiteSpace().ShouldEqualIgnoringCase()
.ShouldContain().ShouldStartWith().ShouldEndWith().ShouldBeContainedIn().ShouldBeOneOf().ShouldNotBeOneOf()
numeric.ShouldBeBetween().ShouldEqualWithTolerance()....GreaterThan....LessThan...GreaterOrEqualTo ...
ienumerable.ShouldAll().ShouldContain().ShouldNotContain().ShouldBeEmpty().ShouldNotBeEmpty() ...
stream.ShouldHaveSameStreamContentAs().ShouldContain()
value.ShouldBe().ShouldNotBe().ShouldBeOfType().ShouldBeAssignableTo()...

See Also

TestBase.HttpClient.Fake TestBase.AdoNet TestBase.AspNetCore.Mvc TestBase-Mvc for Mvc 3-5 Extensions.Logging.ListOfString Serilog.Sinks.ListOfString

Product Compatible and additional computed target framework versions.
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
4.1.4.3 3,813 11/20/2018
4.0.0 1,509 11/16/2018
3.1.0 1,997 7/24/2016
3.0.8.5 1,753 7/23/2016
3.0.8.3 1,765 4/14/2016
3.0.8.2 1,760 3/31/2016
3.0.8.1 1,731 3/30/2016
3.0.8 1,763 3/29/2016
3.0.7.6 1,712 3/14/2016
3.0.7.5 1,737 3/10/2016
3.0.7.4 1,844 2/11/2016
3.0.7.3 1,720 1/29/2016
3.0.7.2 1,738 1/28/2016
3.0.7.1 1,742 1/27/2016
3.0.7 1,760 1/27/2016
3.0.6.2 1,693 1/27/2016
3.0.6.1 1,749 1/26/2016
3.0.5 2,066 1/15/2016
3.0.4 1,864 1/13/2016
3.0.3 1,784 12/28/2015
3.0.2 3,876 12/27/2013
3.0.1.1 1,833 12/23/2013
3.0.1 1,986 11/28/2013
2.0.5 1,970 11/28/2013
2.0.4.1 1,851 11/12/2013
2.0.4 1,893 11/12/2013
2.0.3.1 1,868 11/8/2013
2.0.3 1,965 11/7/2013
2.0.2 1,941 11/7/2013
2.0.1 1,891 11/1/2013
1.0.4 1,879 10/31/2013
1.0.3 1,883 10/23/2013

v4. Removed dependency on NUnit.