CustomAssertions 1.1.0
See the version list below for details.
dotnet add package CustomAssertions --version 1.1.0
NuGet\Install-Package CustomAssertions -Version 1.1.0
<PackageReference Include="CustomAssertions" Version="1.1.0" />
<PackageVersion Include="CustomAssertions" Version="1.1.0" />
<PackageReference Include="CustomAssertions" />
paket add CustomAssertions --version 1.1.0
#r "nuget: CustomAssertions, 1.1.0"
#:package CustomAssertions@1.1.0
#addin nuget:?package=CustomAssertions&version=1.1.0
#tool nuget:?package=CustomAssertions&version=1.1.0
CustomAssertions
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
Type-Specific Assertions
- StringAssertions: null/empty checks, length validations, regex matching, contains/not contains
- IntAssertions: positive/negative/zero, comparisons, range validation
- LongAssertions: 64-bit integer validation, even/odd checks, range operations
- ByteAssertions: byte-specific comparisons and range validation
- DecimalAssertions: high-precision decimal validation, scale checks, financial operations
- FloatingPointAssertions: approximate equality, range, special values (NaN, Infinity)
- BoolAssertions: true/false validation, equality checks
- CharAssertions: letter, digit, case, punctuation, whitespace checks
- GuidAssertions: empty/not empty, version validation, format matching
- EnumAssertions: defined values, flag operations, name validation
- DateTimeAssertions: before/after, date range, weekend checks, component validation
- DateTimeOffsetAssertions: timezone-aware date/time validation, offset checks
- TimeSpanAssertions: duration validation, component checks, approximation
Collection & Complex Type Assertions
- CollectionAssertions: empty/not empty, contains item
- DictionaryAssertions: key/value existence, containment checks
- TupleAssertions: length, item validation, reference equality
- NullableAssertions: has value, conditional validation, value equality
- RecordAssertions: value equality for records, reference checks
- StructAssertions: default value, equality checks
- GenericAssertions: type checks, custom predicates, equality operations
- ExceptionAssertions: exception message, type, inner exception, stack trace validation
๐๏ธ 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 | 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
- 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.
v1.1.0: Added 8 new assertion types (BoolAssertions, DecimalAssertions, LongAssertions, GuidAssertions, TimeSpanAssertions, DateTimeOffsetAssertions, EnumAssertions, ExceptionAssertions). Standardized validation pattern - all assertions now throw exceptions immediately. Added GlobalUsings.cs for modern C# support. See CHANGELOG.md for full details.