A library that provides FluentAssertions-style syntax while using Shouldly under the hood, perfect for projects migrating from FluentAssertions to Shouldly.
Get Started
| Product | Versions |
|---|---|
| .NET |
README
FluentAssertions2Shouldly
This library was developed using Cursor, an AI-powered code editor.
All code, all tests and all documentation was written by the AI, no code was written by me.
The AI is not perfect, it is like a very newbie developer. It needed a lot of coaching, and it didn't remember what it was told. On the bright side, it never complained, but just tried to do what it was told, and I could do other stuff while it was wading through its own errors, trying to fix them.
A library that provides a FluentAssertions-style syntax while using Shouldly under the hood. This is perfect for:
- Projects migrating from FluentAssertions to Shouldly
- Teams who prefer FluentAssertions' syntax but want to use Shouldly's features
- Maintaining consistent test style across mixed codebases
Requirements
- .NET 6 or higher (required for global using statements and file-scoped namespaces)
Installation
dotnet add package FluentAssertions2Shouldly
Usage
The library provides a familiar FluentAssertions-style syntax:
// String assertions
string text = "Hello";
text.Should().Be("Hello");
text.Should().StartWith("He");
text.Should().Contain("ell");
// Numeric assertions
int number = 42;
number.Should().Be(42);
number.Should().BeGreaterThan(40);
number.Should().BeInRange(40, 45);
// Collection assertions
var list = new[] { 1, 2, 3 };
list.Should().HaveCount(3);
list.Should().Contain(2);
list.Should().BeInAscendingOrder();
// Exception assertions
Action action = () => throw new Exception();
action.Should().Throw<Exception>();
While using Shouldly under the hood:
// What you write
text.Should().Be("Hello");
// What actually runs
text.ShouldBe("Hello");
Features
Core Assertions
- String assertions
- Numeric assertions
- Boolean assertions
- Collection assertions
- Exception assertions
- DateTime assertions
- Dictionary assertions
Specialized Assertions
- File assertions
- Async/Task assertions
- Approximate equality assertions
- Enum assertions
- Property change assertions
- Custom assertions
Documentation
Migration
The library makes it easy to migrate from FluentAssertions to Shouldly gradually:
- Replace FluentAssertions package with FluentAssertions2Shouldly
- Tests continue to work with the same syntax
- Optionally migrate to native Shouldly syntax over time
Example:
// Original FluentAssertions code
using FluentAssertions;
value.Should().Be(expected);
// Step 1: Switch to FluentAssertions2Shouldly
using FluentAssertions2Shouldly;
value.Should().Be(expected);
// Step 2 (Optional): Native Shouldly
using Shouldly;
value.ShouldBe(expected);
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Downloads by Version
Similar & Alternative Packages
Hand-picked matching NuGet libraries based on tags & ecosystem
Depended On By
Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.