Skip to content

Convert all FluentAssertions code to Shouldly#85

Merged
tknightnd merged 2 commits intomainfrom
copilot/fix-84
Jun 26, 2025
Merged

Convert all FluentAssertions code to Shouldly#85
tknightnd merged 2 commits intomainfrom
copilot/fix-84

Conversation

Copy link
Contributor

Copilot AI commented Jun 26, 2025

This PR converts all FluentAssertions usage to Shouldly across both test projects as requested in issue #84.

Changes Made

Package References

  • Replaced FluentAssertions 7.1.0 with Shouldly 4.2.1 in both test projects:
    • BenchmarkDotNetAnalyser.Tests.Unit
    • BenchmarkDotNetAnalyser.Tests.Integration

Code Conversions

Updated 29 test files across both projects with the following assertion pattern conversions:

FluentAssertions Shouldly
.Should().Be(x) .ShouldBe(x)
.Should().BeTrue() .ShouldBeTrue()
.Should().BeFalse() .ShouldBeFalse()
.Should().BeNull() .ShouldBeNull()
.Should().NotBeNull() .ShouldNotBeNull()
.Should().BeEmpty() .ShouldBeEmpty()
.Should().BeGreaterThan(x) .ShouldBeGreaterThan(x)
.Should().NotBeNullOrWhiteSpace() .ShouldNotBeNullOrWhiteSpace()
.Should().Throw<T>() .ShouldThrow<T>()

Special Handling

  • Exception Testing: Converted Func<T> delegates to Action delegates for exception assertions since Shouldly requires Action for .ShouldThrow<T>()
  • Chained Assertions: Broke down FluentAssertions .And chains into separate Shouldly assertions
  • Nullable Comparisons: Added .Value property access for nullable type comparisons where needed
  • Collection Ordering: Replaced .Should().BeInAscendingOrder(x => x.Name) with custom comparison logic using .OrderBy()

Verification

✅ All 301 tests pass (258 unit + 43 integration)
✅ Solution builds without errors
✅ No FluentAssertions references remain in test code

Example conversion:

// Before (FluentAssertions)
result.Should().NotBeNull();
result.Count.Should().BeGreaterThan(0);
f.Should().Throw<ArgumentNullException>();

// After (Shouldly)  
result.ShouldNotBeNull();
result.Count.ShouldBeGreaterThan(0);
f.ShouldThrow<ArgumentNullException>();

Fixes #84.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: tknightnd <45595149+tknightnd@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert all FluentAssertions code to Shouldly Convert all FluentAssertions code to Shouldly Jun 26, 2025
Copilot AI requested a review from tknightnd June 26, 2025 09:24
@github-actions github-actions bot added the tests label Jun 26, 2025
@tknightnd tknightnd marked this pull request as ready for review June 26, 2025 09:30
@tknightnd tknightnd requested a review from alefranz as a code owner June 26, 2025 09:30
@tknightnd tknightnd merged commit 4b18f88 into main Jun 26, 2025
9 checks passed
@tknightnd tknightnd deleted the copilot/fix-84 branch June 26, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert all FluentAssertions code to Shouldly

2 participants