OutWit.Common.NUnit
1.0.0
See the version list below for details.
dotnet add package OutWit.Common.NUnit --version 1.0.0
NuGet\Install-Package OutWit.Common.NUnit -Version 1.0.0
<PackageReference Include="OutWit.Common.NUnit" Version="1.0.0" />
<PackageVersion Include="OutWit.Common.NUnit" Version="1.0.0" />
<PackageReference Include="OutWit.Common.NUnit" />
paket add OutWit.Common.NUnit --version 1.0.0
#r "nuget: OutWit.Common.NUnit, 1.0.0"
#:package OutWit.Common.NUnit@1.0.0
#addin nuget:?package=OutWit.Common.NUnit&version=1.0.0
#tool nuget:?package=OutWit.Common.NUnit&version=1.0.0
OutWit.Common.NUnit
OutWit.Common.NUnit is a companion library to OutWit.Common that enhances the NUnit testing experience. It introduces a fluent, expressive assertion syntax for verifying the semantic equality of objects inheriting from ModelBase.
💡 The Problem
When using the OutWit.Common library, your data models often inherit from ModelBase, which provides a powerful .Is() method for deep, property-by-property equality checks.
A standard NUnit test to verify this might look like this:
// Standard NUnit assertion
Assert.That(actualModel.Is(expectedModel), Is.True);
While this works, it's not as readable and doesn't fully leverage NUnit's constraint-based model.
✨ The Solution
This library introduces the
Was class, a static helper that provides custom constraints for a more natural, fluent assertion syntax.
With OutWit.Common.NUnit, the same test becomes:
C#
// Fluent assertion with OutWit.Common.NUnit
Assert.That(actualModel, Was.EqualTo(expectedModel));
This approach is more idiomatic to NUnit and clearly expresses the intent of the test.
Features
Fluent Assertions: Provides a static
Wasclass for expressive and readable tests.Deep Equality Testing: The
Was.EqualTo()constraint is specifically designed to use the.Is()method fromModelBasefor semantic object comparison.Negation Support: Easily assert inequality with
Was.Not.EqualTo().Seamless NUnit Integration: Plugs directly into NUnit's
Assert.That()syntax as a custom constraint.
Getting Started
1. Installation
Install the package from NuGet into your test project.
Bash
dotnet add package OutWit.Common.NUnit
Your test project must also have references to
NUnit and OutWit.Common.
2. Usage
Simply import the namespace and use the Was class in your NUnit Assert.That calls.
Example
Assume you have a model inheriting from ModelBase:
C#
// Your model in the main project
public class MyModel : ModelBase
{
public int Id { get; set; }
public string Name { get; set; }
public override bool Is(ModelBase modelBase, double tolerance = 1E-07)
{
if (modelBase is not MyModel other)
return false;
return this.Id == other.Id && this.Name == other.Name;
}
// Other methods (Clone, etc.)
}
Your NUnit tests can now use Was for cleaner assertions:
C#
using NUnit.Framework;
using OutWit.Common.NUnit; // Import the library
[TestFixture]
public class MyModelTests
{
[Test]
public void TwoModelsWithSameValues_ShouldBeEqual()
{
// Arrange
var model1 = new MyModel { Id = 1, Name = "Test" };
var model2 = new MyModel { Id = 1, Name = "Test" };
// Act & Assert
Assert.That(model1, Was.EqualTo(model2));
}
[Test]
public void TwoModelsWithDifferentValues_ShouldNotBeEqual()
{
// Arrange
var model1 = new MyModel { Id = 1, Name = "Test" };
var model2 = new MyModel { Id = 2, Name = "Test" };
// Act & Assert
Assert.That(model1, Was.Not.EqualTo(model2));
}
}
The Was class also provides convenient shortcuts to standard NUnit constraints like Null, True, False, and Empty.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- NUnit (>= 4.3.2)
- OutWit.Common (>= 1.2.3)
-
net7.0
- NUnit (>= 4.3.2)
- OutWit.Common (>= 1.2.3)
-
net8.0
- NUnit (>= 4.3.2)
- OutWit.Common (>= 1.2.3)
-
net9.0
- NUnit (>= 4.3.2)
- OutWit.Common (>= 1.2.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.