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.
Is it complete? Probably not, but it is a good starting point.
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
- .NET 6 or higher (required for global using statements and file-scoped namespaces)
dotnet add package FluentAssertions2Shouldly
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");
- String assertions
- Numeric assertions
- Boolean assertions
- Collection assertions
- Exception assertions
- DateTime assertions
- Dictionary assertions
- File assertions
- Async/Task assertions
- Approximate equality assertions
- Enum assertions
- Property change assertions
- Custom assertions
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);
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.
This project is licensed under the MIT License - see the LICENSE file for details.