TestBase 4.1.2.4

*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
   - AspNetCore.Mvc, AspNet.Mvc or WebApi Contexts
- HttpClient
- Ado.Net
- Streams & Logging

```
UnitUnderTest.Action()
 .ShouldNotBeNull()
 .ShouldEqualByValueExceptFor(new {Id=1, Descr=expected}, ignoreList )
 .Payload
   .ShouldMatchIgnoringCase("I expected this")
  .Should(someOtherPredicate);
.Items
   .ShouldAll(predicate)
 .ShouldContain(item)
 .ShouldNotContain(predicate)
 .Where(predicate)
 .SingleOrAssertFail()

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

TestBase.HttpClient.Fake

```
new FakeHttpClient()
     .Setup(x=>x.RequestUri.PathAndQuery.StartsWith("/this"))
       .Returns(response)
     .Setup(x=>x.Method==HttpMethod.Put)
       .Returns(new HttpResponseMessage(HttpStatusCode.Accepted));
```

TestBase.FakeDb
------------------
`FakeDbConnection`

```
- db.SetupForQuery(…)
- db.SetupForExecuteNonQuery(…)
- db.ShouldHaveUpdated("tableName", …)
- db.ShouldHaveSelected("tableName", …)
- db.ShouldHaveDeleted("tableName", …)
- db.Verify( x=>x.CommandText.Matches("Insert [case] .*")
            && x.Parameters["id"].Value==1 )
- db
   .ShouldHaveInvoked(cmd => predicate(cmd))
   .ShouldHaveParameter("name", value)
```

TestBase.Mvc.AspNetCore & TestBase.Mvc for Mvc 4 & Mvc 5
--------------------------------------------------------

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

ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc.
```


- Test AspNetCore controllers with zero setup using
 `controllerUnderTest.WithControllerContext(actionUnderTest)`
- Test more complex AspNetCore controller/application dependencies using
 `HostedMvcTestFixtureBase` and specify your MVCApplications `Startup` class.

```
[TestCase("/dummy")]
public async Task Put_Should_ReturnA(string url)
{
   var httpClient=GivenClientForRunningServer<Startup>();
   GivenRequestHeaders(httpClient, "CustomHeader", "HeaderValue1");

   var result = await httpClient.PutAsync(url, json);

   result.ShouldBe_202Accepted();
}
```

Foor Mvc4 and Mvc 5, fake your http request &amp; context, and use the `RegisterRoutes` method
of your actual application to set up `Controller.Url`

```
ControllerUnderTest
 .WithHttpContextAndRoutes(
   RouteConfig.RegisterRoutes,
   "/incomingurl"
 );

ApiControllerUnderTest.WithWebApiHttpContext<T>(
   httpMethod,
   requestUri,
   routeTemplate)
```

Testable Logging

```
// Extensions.Logging.ListOfString
var log = new List<String>();
ILogger       mslogger= new LoggerFactory().AddStringListLogger(log).CreateLogger("Test2");

// Serilog.Sinks.ListOfString
Serilog.Logger slogger= new LoggerConfiguration().WriteTo.StringList(log).CreateLogger();
```

There is a newer version of this package available.
See the version list below for details.
Install-Package TestBase -Version 4.1.2.4
dotnet add package TestBase --version 4.1.2.4
<PackageReference Include="TestBase" Version="4.1.2.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TestBase --version 4.1.2.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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
    • AspNetCore.Mvc, AspNet.Mvc or WebApi Contexts
    • HttpClient
    • Ado.Net
    • Streams & Logging
UnitUnderTest.Action()
  .ShouldNotBeNull()
  .ShouldEqualByValueExceptFor(new {Id=1, Descr=expected}, ignoreList )
  .Payload
    .ShouldMatchIgnoringCase("I expected this")
  	.Should(someOtherPredicate);
	.Items
    .ShouldAll(predicate)
	  .ShouldContain(item)
	  .ShouldNotContain(predicate)
	  .Where(predicate)
	  .SingleOrAssertFail()

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

TestBase.HttpClient.Fake

new FakeHttpClient()
      .Setup(x=>x.RequestUri.PathAndQuery.StartsWith("/this"))
        .Returns(response)
      .Setup(x=>x.Method==HttpMethod.Put)
        .Returns(new HttpResponseMessage(HttpStatusCode.Accepted));

TestBase.FakeDb

FakeDbConnection

- db.SetupForQuery(…)
- db.SetupForExecuteNonQuery(…)
- db.ShouldHaveUpdated("tableName", …)
- db.ShouldHaveSelected("tableName", …)
- db.ShouldHaveDeleted("tableName", …)
- db.Verify( x=>x.CommandText.Matches("Insert [case] .*") 
             && x.Parameters["id"].Value==1 )
- db
    .ShouldHaveInvoked(cmd => predicate(cmd))
    .ShouldHaveParameter("name", value)

TestBase.Mvc.AspNetCore & TestBase.Mvc for Mvc 4 & Mvc 5

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

ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc.
  • Test AspNetCore controllers with zero setup using
    controllerUnderTest.WithControllerContext(actionUnderTest)
  • Test more complex AspNetCore controller/application dependencies using
    HostedMvcTestFixtureBase and specify your MVCApplications Startup class.
[TestCase("/dummy")]
public async Task Put_Should_ReturnA(string url)
{
    var httpClient=GivenClientForRunningServer<Startup>();
    GivenRequestHeaders(httpClient, "CustomHeader", "HeaderValue1");

    var result = await httpClient.PutAsync(url, json);

    result.ShouldBe_202Accepted();
}

Foor Mvc4 and Mvc 5, fake your http request &amp; context, and use the RegisterRoutes method
of your actual application to set up Controller.Url

ControllerUnderTest
  .WithHttpContextAndRoutes(
    RouteConfig.RegisterRoutes, 
    "/incomingurl"
  );

ApiControllerUnderTest.WithWebApiHttpContext<T>(
    httpMethod, 
    requestUri,
    routeTemplate)

Testable Logging

// Extensions.Logging.ListOfString
var log = new List<String>();
ILogger       mslogger= new LoggerFactory().AddStringListLogger(log).CreateLogger("Test2");

// Serilog.Sinks.ListOfString
Serilog.Logger slogger= new LoggerConfiguration().WriteTo.StringList(log).CreateLogger();

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
    • AspNetCore.Mvc, AspNet.Mvc or WebApi Contexts
    • HttpClient
    • Ado.Net
    • Streams & Logging
UnitUnderTest.Action()
  .ShouldNotBeNull()
  .ShouldEqualByValueExceptFor(new {Id=1, Descr=expected}, ignoreList )
  .Payload
    .ShouldMatchIgnoringCase("I expected this")
  	.Should(someOtherPredicate);
	.Items
    .ShouldAll(predicate)
	  .ShouldContain(item)
	  .ShouldNotContain(predicate)
	  .Where(predicate)
	  .SingleOrAssertFail()

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

TestBase.HttpClient.Fake

new FakeHttpClient()
      .Setup(x=>x.RequestUri.PathAndQuery.StartsWith("/this"))
        .Returns(response)
      .Setup(x=>x.Method==HttpMethod.Put)
        .Returns(new HttpResponseMessage(HttpStatusCode.Accepted));

TestBase.FakeDb

FakeDbConnection

- db.SetupForQuery(…)
- db.SetupForExecuteNonQuery(…)
- db.ShouldHaveUpdated("tableName", …)
- db.ShouldHaveSelected("tableName", …)
- db.ShouldHaveDeleted("tableName", …)
- db.Verify( x=>x.CommandText.Matches("Insert [case] .*") 
             && x.Parameters["id"].Value==1 )
- db
    .ShouldHaveInvoked(cmd => predicate(cmd))
    .ShouldHaveParameter("name", value)

TestBase.Mvc.AspNetCore & TestBase.Mvc for Mvc 4 & Mvc 5

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

ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc.
  • Test AspNetCore controllers with zero setup using
    controllerUnderTest.WithControllerContext(actionUnderTest)
  • Test more complex AspNetCore controller/application dependencies using
    HostedMvcTestFixtureBase and specify your MVCApplications Startup class.
[TestCase("/dummy")]
public async Task Put_Should_ReturnA(string url)
{
    var httpClient=GivenClientForRunningServer<Startup>();
    GivenRequestHeaders(httpClient, "CustomHeader", "HeaderValue1");

    var result = await httpClient.PutAsync(url, json);

    result.ShouldBe_202Accepted();
}

Foor Mvc4 and Mvc 5, fake your http request &amp; context, and use the RegisterRoutes method
of your actual application to set up Controller.Url

ControllerUnderTest
  .WithHttpContextAndRoutes(
    RouteConfig.RegisterRoutes, 
    "/incomingurl"
  );

ApiControllerUnderTest.WithWebApiHttpContext<T>(
    httpMethod, 
    requestUri,
    routeTemplate)

Testable Logging

// Extensions.Logging.ListOfString
var log = new List<String>();
ILogger       mslogger= new LoggerFactory().AddStringListLogger(log).CreateLogger("Test2");

// Serilog.Sinks.ListOfString
Serilog.Logger slogger= new LoggerConfiguration().WriteTo.StringList(log).CreateLogger();

Release Notes

ChangeLog
---------
4.1.2.4 TestBase.AdoNet providers VerifyFirst(), VerifyLast(), VerifySingle(). Added ToCodeString() overload
4.1.2.1 Added TestBase.Pdf.DocumentWithLineOfText
4.1.2.0 TestBase.Mvc.AspNetCore provides WithControllerContext()
4.1.1.0 Should(assertion) and ShouldHave(assertion) as well as Should(predicate)
4.1.0.0 [ExpressionToCodeLib](https://www.nuget.org/packages/ExpressionToCodeLib/) and [FastExpressionCompiler](https://www.nuget.org/packages/FastExpressionCompiler/) ftw. Awesomer, and faster, assertions.
4.0.9.2  ShouldNotMatch(pattern)
4.0.9.1  ShouldNotContain( item or predicate)
4.0.9.0  Removed dependency on net4 version of Mono.Linq.Expressions
4.0.8.0  Separated Serilog.Sinks.ListOfString and Extensions.Logging.StringListLogger
4.0.7.0  Added TestBase.FakeHttpClient. Added Should(predicate,...) as synonym of ShouldHave(predicate,...)
4.0.6.2  TestBase.Mvc can run controller actions on aspnetcore using controller.WithControllerContext()
4.0.5.2  TestBase.Mvc partially ported to netstandard20 / AspNetCore
4.0.4.1  StreamShoulds
4.0.3.0  StringListLogger as MS Logger and as Serilogger
4.0.1.0  Port to NetCore
3.0.3.0  Improves FakeDb setup
3.0.x.0  adds and/or corrects missing Shoulds()
2.0.5.0  adds some intellisense and FakeDbConnection.Verify(..., message,args) overload

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
4.1.4.3 1,580 11/20/2018
4.1.4.1 865 11/16/2018
4.1.3.2 860 10/28/2018
4.1.3.1 831 10/26/2018
4.1.2.7 868 10/24/2018
4.1.2.4 843 10/16/2018
4.1.2.3 1,269 5/22/2018
4.1.2.2 909 5/22/2018
4.1.2.1 923 5/22/2018
4.1.2 945 5/19/2018
4.1.1 966 4/8/2018
4.1.0 922 4/3/2018
4.0.9.2 1,091 3/31/2018
4.0.9.1 976 3/28/2018
4.0.9 1,091 3/23/2018
4.0.8 1,060 3/23/2018
4.0.7 909 3/22/2018
4.0.6.2 936 3/9/2018
4.0.6.1 914 3/7/2018
4.0.5.2 946 3/2/2018
4.0.5 923 3/1/2018
4.0.4.2 957 3/1/2018
4.0.4 923 2/25/2018
4.0.3 946 2/25/2018
4.0.2 901 2/24/2018
4.0.1 967 2/24/2018
3.1.0 1,261 7/24/2016
3.0.8.5 1,011 7/23/2016
3.0.8.3 1,052 4/14/2016
3.0.8.2 996 3/31/2016
3.0.8.1 988 3/30/2016
3.0.8 1,030 3/29/2016
3.0.7.6 1,025 3/14/2016
3.0.7.5 999 3/10/2016
3.0.7.4 1,033 2/11/2016
3.0.7.3 1,023 1/29/2016
3.0.6.2 1,041 1/27/2016
3.0.6.1 1,028 1/26/2016
3.0.5 1,044 1/15/2016
3.0.4 1,032 1/13/2016
3.0.3 1,021 12/28/2015
3.0.2 2,708 12/27/2013
3.0.1.1 1,058 12/23/2013
3.0.1 1,126 11/28/2013
2.0.5 1,090 11/28/2013
2.0.4.1 1,081 11/12/2013
2.0.4 1,101 11/12/2013
2.0.3.1 1,061 11/8/2013
2.0.3 1,113 11/7/2013
2.0.2 1,093 11/7/2013
2.0.1 1,101 11/1/2013
1.0.4 1,092 10/31/2013
1.0.3 1,116 10/23/2013
Show less