Noundry.Assertive
1.0.1
dotnet add package Noundry.Assertive --version 1.0.1
NuGet\Install-Package Noundry.Assertive -Version 1.0.1
<PackageReference Include="Noundry.Assertive" Version="1.0.1" />
<PackageVersion Include="Noundry.Assertive" Version="1.0.1" />
<PackageReference Include="Noundry.Assertive" />
paket add Noundry.Assertive --version 1.0.1
#r "nuget: Noundry.Assertive, 1.0.1"
#:package Noundry.Assertive@1.0.1
#addin nuget:?package=Noundry.Assertive&version=1.0.1
#tool nuget:?package=Noundry.Assertive&version=1.0.1
Noundry.Assertive: Fluent Assertions Made Easy
Noundry.Assertive is a simple yet powerful fluent assertion library for .NET, making your tests readable, intuitive, and expressive with zero runtime dependencies.
Why Choose Noundry.Assertive?
- Fluent and readable assertions that make your tests self-documenting
- Zero runtime dependencies for clean, lightweight integration
- Easy integration into your existing projects
- Intuitive API for clear, expressive tests
- Clean error messages for quicker debugging
- Comprehensive assertions for common scenarios
- Extensible design for custom validation logic
- High performance with compiled binary distribution
Quick Installation
Install directly from NuGet:
dotnet add package Noundry.Assertive
Or add to your .csproj:
<PackageReference Include="Noundry.Assertive" Version="1.0.0" />
Usage Examples
Basic Assertions
using Noundry.Assertive;
"Hello, World!"
.Assert()
.IsNotNull()
.IsEqualTo("Hello, World!")
.IsOfType<string>()
.Satisfies(s => s.Length > 5, "String length should exceed 5 characters");
Numeric Assertions
using Noundry.Assertive;
42.Assert()
.IsNotNull()
.IsEqualTo(42)
.IsOfType<int>()
.IsInRange(1, 100)
.Satisfies(x => x > 0, "Number should be positive")
.Fails(x => x < 0, "Number should not be negative");
Collection Assertions
using Noundry.Assertive;
var numbers = new List<int> { 1, 2, 3, 4, 5 };
numbers.Assert()
.IsNotEmpty<int>()
.HasCount<int>(5)
.Contains(3)
.DoesNotContain(10);
Null Handling
using Noundry.Assertive;
string nullValue = null;
nullValue.Assert().IsNull();
string notNull = "value";
notNull.Assert().IsNotNull();
Custom Objects with Context
using Noundry.Assertive;
var person = new Person { Name = "John", Age = 30 };
person.Assert()
.WithContext("Person validation")
.IsNotNull()
.Satisfies(p => p.Age >= 18, "Person should be an adult")
.Satisfies(p => !string.IsNullOrEmpty(p.Name), "Person should have a name");
Complete API Reference
Core Assertions
| Method | Description |
|---|---|
IsNotNull() |
Ensures the object isn't null |
IsNull() |
Ensures the object is null |
IsEqualTo(value) |
Checks equality with expected value |
IsNotEqualTo(value) |
Checks inequality with specified value |
Type Assertions
| Method | Description |
|---|---|
IsOfType<T>() |
Checks object's exact type |
IsNotOfType<T>() |
Ensures object isn't the specified type |
Predicate Assertions
| Method | Description |
|---|---|
Satisfies(predicate, message) |
Validates custom conditions |
Fails(predicate, message) |
Ensures object doesn't match a condition |
Range Assertions
| Method | Description |
|---|---|
IsInRange(min, max) |
Checks if value is within range (inclusive) |
Collection Assertions
| Method | Description |
|---|---|
Contains(item) |
Ensures collection contains the item |
DoesNotContain(item) |
Ensures collection doesn't contain the item |
IsEmpty<T>() |
Ensures collection is empty |
IsNotEmpty<T>() |
Ensures collection is not empty |
HasCount<T>(count) |
Ensures collection has specific count |
Context & Chaining
| Method | Description |
|---|---|
WithContext(context) |
Adds context to error messages |
Value |
Property to access the underlying value |
Error Handling
Assertive throws AssertionException when assertions fail, providing:
- Clear error messages
- Expected vs. actual values
- Optional context information
using Noundry.Assertive;
try
{
42.Assert()
.WithContext("Age validation")
.IsEqualTo(18);
}
catch (AssertionException ex)
{
Console.WriteLine($"Message: {ex.Message}");
Console.WriteLine($"Expected: {ex.Expected}");
Console.WriteLine($"Actual: {ex.Actual}");
}
Advanced Features
Method Chaining
All assertion methods return the Assertive<T> instance, enabling fluent chaining:
using Noundry.Assertive;
myObject
.Assert()
.IsNotNull()
.IsOfType<MyClass>()
.Satisfies(obj => obj.IsValid)
.Satisfies(obj => obj.Count > 0);
Custom Predicates
Use Satisfies and Fails for custom validation logic:
using Noundry.Assertive;
email.Assert()
.Satisfies(e => e.Contains("@"), "Email should contain @")
.Satisfies(e => e.EndsWith(".com"), "Email should end with .com");
Contextual Assertions
Add context to make error messages more descriptive:
using Noundry.Assertive;
user.Assert()
.WithContext("User registration validation")
.Satisfies(u => u.Age >= 13, "User must be at least 13 years old");
Best Practices
- Use descriptive messages in
SatisfiesandFailsmethods - Add context for complex validations using
WithContext - Chain assertions logically for better readability
- Catch AssertionException to handle validation failures gracefully
- Combine with test frameworks like xUnit, NUnit, or MSTest
Integration with Test Frameworks
xUnit
using Noundry.Assertive;
using Xunit;
[Fact]
public void TestMethod()
{
var result = Calculate();
result.Assert()
.IsNotNull()
.IsEqualTo(42);
}
NUnit
using Noundry.Assertive;
using NUnit.Framework;
[Test]
public void TestMethod()
{
var result = Calculate();
result.Assert()
.IsNotNull()
.IsEqualTo(42);
}
MSTest
using Noundry.Assertive;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestMethod]
public void TestMethod()
{
var result = Calculate();
result.Assert()
.IsNotNull()
.IsEqualTo(42);
}
Contributing
We welcome contributions! To contribute:
- Fork this repository
- Create your feature branch:
git checkout -b feature/YourFeature - Commit your changes:
git commit -m 'Add YourFeature' - Push to the branch:
git push origin feature/YourFeature - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/noundry/Noundry.Assertive.git
cd Noundry.Assertive
# Restore dependencies
dotnet restore
# Build the solution
dotnet build
# Run tests
dotnet test
# Run examples
dotnet run --project examples/Noundry.Assertive.Examples
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- NuGet: Noundry.Assertive
Roadmap
- Add async assertion support
- Add more collection assertions
- Add string-specific assertions
- Add date/time specific assertions
- Performance optimizations
- Additional documentation and examples
Made with ❤️ by the Noundry.Assertive community
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.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.0.1 | 124 | 3/4/2026 |