CustomAssertions 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CustomAssertions --version 1.0.0
                    
NuGet\Install-Package CustomAssertions -Version 1.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="CustomAssertions" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CustomAssertions" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CustomAssertions" />
                    
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 CustomAssertions --version 1.0.0
                    
#r "nuget: CustomAssertions, 1.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.
#:package CustomAssertions@1.0.0
                    
#: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=CustomAssertions&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CustomAssertions&version=1.0.0
                    
Install as a Cake Tool

CustomAssertions

License: MIT .NET NuGet

A modern, fluent assertion library for .NET that provides type-safe, chainable assertions with comprehensive validation capabilities. Designed to work seamlessly with xUnit, NUnit, and MSTest.

โœจ Features

  • ๐Ÿ”— Fluent API: Chain multiple assertions together for readable, expressive tests
  • ๐ŸŽฏ Type-Safe: Strong typing with compile-time validation
  • ๐Ÿ“ฆ Comprehensive: Assertions for strings, integers, collections, dates, records, structs, tuples, and more
  • ๐Ÿงช Test Framework Agnostic: Works with xUnit, NUnit, MSTest
  • ๐Ÿš€ Modern C#: Leverages latest C# features (records, pattern matching, nullable types)
  • ๐Ÿ“ Well-Documented: Full XML documentation for IntelliSense support
  • โšก Performant: Minimal overhead with efficient implementation
  • ๐Ÿ” Detailed Error Messages: Clear, descriptive failure messages

๐Ÿ“ฆ Installation

Via NuGet Package Manager

Install-Package CustomAssertions

Via .NET CLI

dotnet add package CustomAssertions

Via PackageReference

<PackageReference Include="CustomAssertions" Version="1.0.0" />

๐Ÿš€ Quick Start

using CustomAssertions.ConcreteModels;
using Xunit;

public class ExampleTests
{
    [Fact]
    public void StringAssertion_Example()
    {
        var result = new StringAssertions("Hello, World!")
            .NotNullOrEmpty()
            .HasMinimumLength(5)
            .Contains("World")
            .MatchesRegex(@"^Hello.*!")
            .Validate();

        Assert.True(result);
    }

    [Fact]
    public void IntAssertion_Example()
    {
        var result = new IntAssertions(42)
            .IsPositive()
            .IsGreaterThan(10)
            .IsLessThan(100)
            .IsInRange(1, 50)
            .Validate();

        Assert.True(result);
    }
}

๐Ÿ“š Available Assertions

  • StringAssertions: null/empty checks, length validations, regex matching, contains/not contains
  • IntAssertions: positive/negative/zero, comparisons, range validation
  • CollectionAssertions: empty/not empty, contains item
  • DateTimeAssertions: before/after, date range, weekend checks
  • DictionaryAssertions: key/value existence
  • RecordAssertions: value equality for records
  • NullableAssertions: has value, conditional validation
  • StructAssertions: default value, equality checks
  • TupleAssertions: length, item validation
  • FloatingPointAssertions: approximate equality, range, special values (NaN, Infinity)
  • CharAssertions: letter, digit, case, punctuation checks
  • ByteAssertions: byte-specific comparisons and range validation
  • GenericAssertions: type checks, custom predicates

๐Ÿ—๏ธ Architecture

The library follows these design principles:

  • SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
  • Fluent Interface Pattern: Enables method chaining for readable code
  • Template Method Pattern: Base classes define structure, concrete classes implement specifics
  • Curiously Recurring Template Pattern (CRTP): Type-safe fluent chaining

๐Ÿ”ง Requirements

  • .NET 6.0 or higher (.NET 6, .NET 7, .NET 8, .NET 9 supported)
  • C# 10 or higher (for modern language features)

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE.txt file for details.


Made with โค๏ธ by Darel Johnson

Copyright ยฉ 2024 Darel Johnson. All rights reserved.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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.4.0 537 12/1/2025
1.3.0 527 12/1/2025
1.2.1 435 12/1/2025
1.2.0 457 11/30/2025
1.1.0 380 11/30/2025
1.0.0 386 11/30/2025

Initial release of CustomAssertions library with comprehensive fluent assertion support for .NET 6+.