TestBase 4.0.5

Package Description

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

TestBase gets you off to a flying start when unit testing projects with dependencies.
It has rich, but easily extensible, fluent assertions, including EqualsByValue, Regex, Stream Comparision, and Ado.Net assertions.

TestBase.Shoulds

Chainable fluent assertions get you to the point concisely

UnitUnderTest.Action()
    .ShouldNotBeNull()
    .ShouldContain(expected);
UnitUnderTest.OtherAction()
    .ShouldEqualByValue(new {Id=1, Payload=expected, Additional=new[]{ expected1, expected2 }} )
    .Payload
        .ShouldMatchIgnoringCase(""I expected this"");
* ShouldBe(), ShouldMatch(), ShouldNotBe(), ShouldContain(), ShouldNotContain(), ShouldBeEmpty(), ShouldNotBeEmpty(), ShouldAll() and many more
* ShouldEqualByValue(), ShouldEqualByValueExceptForValues() works with all kinds of object and collections
* Stream.ShouldHaveSameStreamContentAs()` and `Stream.ShouldContain()

Testable Logging with StringListLogger:

MS Logging: ILoggerFactory factory=new LoggerFactory.AddProvider(new StringListLoggerProvider())
Serilogging: new LoggerConfiguration().WriteTo.StringList(stringList).CreateLogger()
//
var logger=new StringListLogger(); ... ; logger.LoggedLines.ShouldContain(x=>x.Matches("kilroy was here")

TestBase.FakeDb

Works with Ado.Net and technologies on top of it, including Dapper.

* fakeDbConnection.SetupForQuery(IEnumerable<TFakeData>; )
* fakeDbConnection.SetupForQuery(IEnumerable<Tuple<TFakeDataForTable1,TFakeDataForTable2>> )
* fakeDbConnection.SetupForQuery(fakeData, new[] {""FieldName1"", FieldName2""})
* fakeDbConnection.SetupForExecuteNonQuery(rowsAffected)
* fakeDbConnection.ShouldHaveUpdated(""tableName"", [Optional] fieldList, whereClauseField)
* fakeDbConnection.ShouldHaveSelected(""tableName"", [Optional] fieldList, whereClauseField)
* fakeDbConnection.ShouldHaveUpdated(""tableName"", [Optional] fieldList, whereClauseField)
* fakeDbConnection.ShouldHaveDeleted(""tableName"", whereClauseField)
* fakeDbConnection.ShouldHaveInvoked(cmd => predicate(cmd))
* fakeDbConnection.ShouldHaveXXX().ShouldHaveParameter(""name"", value)
* fakeDbConnection.Verify(x=>x.CommandText.Matches(""Insert [case] .*"") && x.Parameters[""id""].Value==1)

TestBase.Mvc

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

ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc.

Version 3 on Net4 only

TestBase-Mvc for MVC 4 & 5

  • Includes mocking of HttpConttextBase and parsing of RouteConfig so that Controllers have a working Controller.Url when under test:
uut = new MyController().WithHttpContextAndRoutes(RouteConfig.RegisterRoutes);
uut.Url.Action("MyAction", "MyOtherController").ShouldEqual("/MyOtherController/MyAction");

Can be used in both NUnit & MS UnitTestFramework test projects.

  • Building on Mono : define compile symbol NoMSTest to remove dependency on Microsoft.VisualStudio.QualityTools.UnitTestFramework

ChangeLog

4.0.5.0 TestBase.Mvc partially ported to AspNetcore
4.0.4.0 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

TestBase gets you off to a flying start when unit testing projects with dependencies.
It has rich, but easily extensible, fluent assertions, including EqualsByValue, Regex, Stream Comparision, and Ado.Net assertions.

TestBase.Shoulds

Chainable fluent assertions get you to the point concisely

UnitUnderTest.Action()
    .ShouldNotBeNull()
    .ShouldContain(expected);
UnitUnderTest.OtherAction()
    .ShouldEqualByValue(new {Id=1, Payload=expected, Additional=new[]{ expected1, expected2 }} )
    .Payload
        .ShouldMatchIgnoringCase(""I expected this"");
* ShouldBe(), ShouldMatch(), ShouldNotBe(), ShouldContain(), ShouldNotContain(), ShouldBeEmpty(), ShouldNotBeEmpty(), ShouldAll() and many more
* ShouldEqualByValue(), ShouldEqualByValueExceptForValues() works with all kinds of object and collections
* Stream.ShouldHaveSameStreamContentAs()` and `Stream.ShouldContain()

Testable Logging with StringListLogger:

MS Logging: ILoggerFactory factory=new LoggerFactory.AddProvider(new StringListLoggerProvider())
Serilogging: new LoggerConfiguration().WriteTo.StringList(stringList).CreateLogger()
//
var logger=new StringListLogger(); ... ; logger.LoggedLines.ShouldContain(x=>x.Matches("kilroy was here")

TestBase.FakeDb

Works with Ado.Net and technologies on top of it, including Dapper.

* fakeDbConnection.SetupForQuery(IEnumerable<TFakeData>; )
* fakeDbConnection.SetupForQuery(IEnumerable<Tuple<TFakeDataForTable1,TFakeDataForTable2>> )
* fakeDbConnection.SetupForQuery(fakeData, new[] {""FieldName1"", FieldName2""})
* fakeDbConnection.SetupForExecuteNonQuery(rowsAffected)
* fakeDbConnection.ShouldHaveUpdated(""tableName"", [Optional] fieldList, whereClauseField)
* fakeDbConnection.ShouldHaveSelected(""tableName"", [Optional] fieldList, whereClauseField)
* fakeDbConnection.ShouldHaveUpdated(""tableName"", [Optional] fieldList, whereClauseField)
* fakeDbConnection.ShouldHaveDeleted(""tableName"", whereClauseField)
* fakeDbConnection.ShouldHaveInvoked(cmd => predicate(cmd))
* fakeDbConnection.ShouldHaveXXX().ShouldHaveParameter(""name"", value)
* fakeDbConnection.Verify(x=>x.CommandText.Matches(""Insert [case] .*"") && x.Parameters[""id""].Value==1)

TestBase.Mvc

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

ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc.

Version 3 on Net4 only

TestBase-Mvc for MVC 4 & 5

  • Includes mocking of HttpConttextBase and parsing of RouteConfig so that Controllers have a working Controller.Url when under test:
uut = new MyController().WithHttpContextAndRoutes(RouteConfig.RegisterRoutes);
uut.Url.Action("MyAction", "MyOtherController").ShouldEqual("/MyOtherController/MyAction");

Can be used in both NUnit & MS UnitTestFramework test projects.

  • Building on Mono : define compile symbol NoMSTest to remove dependency on Microsoft.VisualStudio.QualityTools.UnitTestFramework

ChangeLog

4.0.5.0 TestBase.Mvc partially ported to AspNetcore
4.0.4.0 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,080 11/12/2013
2.0.4 1,100 11/12/2013
2.0.3.1 1,060 11/8/2013
2.0.3 1,112 11/7/2013
2.0.2 1,092 11/7/2013
2.0.1 1,100 11/1/2013
1.0.4 1,091 10/31/2013
1.0.3 1,115 10/23/2013
Show less