Skip to main content

A library that provides FluentAssertions-style syntax while using Shouldly under the hood, perfect for projects migrating from FluentAssertions to Shouldly.

Total Downloads
625
625
Published
Feb 27, 2025
1y ago

Get Started

dotnet add package FluentAssertions2Shouldly --version 1.0.0-beta.4
ProductVersions
.NET
net6.0

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:

  1. Replace FluentAssertions package with FluentAssertions2Shouldly
  2. Tests continue to work with the same syntax
  3. 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.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.