OutWit.Common.NUnit 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package OutWit.Common.NUnit --version 1.1.1
                    
NuGet\Install-Package OutWit.Common.NUnit -Version 1.1.1
                    
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="OutWit.Common.NUnit" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OutWit.Common.NUnit" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="OutWit.Common.NUnit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OutWit.Common.NUnit --version 1.1.1
                    
#r "nuget: OutWit.Common.NUnit, 1.1.1"
                    
#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.
#:package OutWit.Common.NUnit@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OutWit.Common.NUnit&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=OutWit.Common.NUnit&version=1.1.1
                    
Install as a Cake Tool

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 Was class for expressive and readable tests.

  • Deep Equality Testing: The Was.EqualTo() constraint is specifically designed to use the .Is() method from ModelBase for 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 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 is compatible.  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. 
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
1.1.2 208 1/25/2026
1.1.1 245 11/23/2025
1.1.0 316 11/12/2025
1.0.1 127 8/1/2025
1.0.0 123 8/1/2025