Skip to content

Commit 4f66312

Browse files
si618claude
andauthored
Replace FluentAssertions with Shouldly for test assertions (#147)
* Replace FluentAssertions with Shouldly for test assertions - Remove FluentAssertions 7.2.0 and add Shouldly 4.2.1 package - Update GlobalUsings.cs to import Shouldly instead of FluentAssertions - Migrate 50+ C# problem files with 140+ assertion patterns: - .Should().Be() → .ShouldBe() - .Should().BeTrue() → .ShouldBeTrue() - .Should().BeFalse() → .ShouldBeFalse() - .Should().BeEquivalentTo() → .ShouldBeEquivalentTo() - .Should().Throw<T>() → .ShouldThrow<T>() - Remove AssertionScope usage patterns - Fix complex object comparisons for ListNode and TreeNode types - Update CLAUDE.md documentation to reflect Shouldly usage - All 74 C# + 6 F# tests pass with new assertion library Benefits: More natural syntax, better error messages, lighter weight * Fix dotnet format imports ordering in GlobalUsings.cs * Fix .gitignore alphabetical ordering * Move global usings from GlobalUsings.cs files to .csproj files - Convert GlobalUsings.cs files to <Using> ItemGroup in project files - Remove GlobalUsings.cs files from both LeetCode.CSharp and LeetCode projects - Maintain same global imports functionality using MSBuild <Using> elements - Build, tests, and formatting all pass successfully 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e6b9f21 commit 4f66312

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+185
-190
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.vs
1+
.plan
2+
.vs
3+
*.DotSettings.user
24
bin
35
obj
4-
*.DotSettings.user
56
BenchmarkDotNet.Artifacts
67
/.idea/.idea.LeetCode/.idea/material_theme_project_new.xml

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ This is a LeetCode problem solutions repository with benchmarking capabilities,
6161

6262
**Console Application**: Built with Spectre.Console, provides an interactive menu system and CLI commands (app, benchmark, info, list, workflow) for running benchmarks and viewing problem information.
6363

64-
**Testing**: Uses xUnit with FluentAssertions for test assertions. Tests are co-located with problem implementations for easy access.
64+
**Testing**: Uses xUnit with Shouldly for test assertions. Tests are co-located with problem implementations for easy access.
6565

6666
**Package Management**: Uses Directory.Packages.props for centralized NuGet package version management across all projects.

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<PrivateAssets>all</PrivateAssets>
99
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1010
</PackageVersion>
11-
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
1211
<PackageVersion Include="FsUnit.xUnit" Version="6.0.1" />
1312
<PackageVersion Include="FSharp.Core" Version="8.0.400" />
1413
<PackageVersion Include="lolcat" Version="1.1.120" />
@@ -17,6 +16,7 @@
1716
<PrivateAssets>all</PrivateAssets>
1817
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1918
</PackageVersion>
19+
<PackageVersion Include="Shouldly" Version="4.2.1" />
2020
<PackageVersion Include="Spectre.Console" Version="0.50.0" />
2121
<PackageVersion Include="Spectre.Console.Analyzer" Version="1.0.0">
2222
<PrivateAssets>all</PrivateAssets>

LeetCode.CSharp/GlobalUsings.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

LeetCode.CSharp/LeetCode.CSharp.csproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@
55
<RootNamespace>LeetCode.CSharp</RootNamespace>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<Using Include="BenchmarkDotNet.Attributes" />
10+
<Using Include="BenchmarkDotNet.Columns" />
11+
<Using Include="BenchmarkDotNet.Configs" />
12+
<Using Include="BenchmarkDotNet.Diagnosers" />
13+
<Using Include="LeetCode.CSharp.Problems" />
14+
<Using Include="Shouldly" />
15+
<Using Include="System.Diagnostics.CodeAnalysis" />
16+
<Using Include="System.Text" />
17+
<Using Include="Xunit" />
18+
</ItemGroup>
19+
820
<ItemGroup>
921
<PackageReference Include="BenchmarkDotNet" />
10-
<PackageReference Include="FluentAssertions" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1222
<PackageReference Include="coverlet.collector" />
23+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
24+
<PackageReference Include="Shouldly" />
1325
<PackageReference Include="xunit" />
1426
<PackageReference Include="xunit.runner.visualstudio" />
1527
</ItemGroup>

LeetCode.CSharp/Problems/AddTwoNumbers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void AddTwoNumbersTest(int[] list1, int[] list2, int[] expectedList)
5959
var listNode2 = new ListNode(list2);
6060
var expectedNode = new ListNode(expectedList);
6161
var result = AddTwoNumbers(listNode1, listNode2);
62-
result.Should().NotBeNull();
62+
result.ShouldNotBeNull();
6363
AssertEqual(result, expectedNode);
6464

6565
return;
@@ -77,7 +77,7 @@ static void AssertEqual(ListNode? l1, ListNode? l2)
7777
Assert.Fail("Either both nodes or neither node should be null");
7878
return;
7979
}
80-
l1.val.Should().Be(l2.val);
80+
l1.val.ShouldBe(l2.val);
8181
l1 = l1.next;
8282
l2 = l2.next;
8383
}

LeetCode.CSharp/Problems/BinarySearch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ public static int BinarySearch(int[] nums, int target)
4040
[InlineData(new[] { -1, 0, 3, 5, 9, 12 }, 2, -1)]
4141
[InlineData(new int[] { }, 0, -1)]
4242
public void BinarySearchTest(int[] nums, int target, int expected) =>
43-
BinarySearch(nums, target).Should().Be(expected);
43+
BinarySearch(nums, target).ShouldBe(expected);
4444
}

LeetCode.CSharp/Problems/CanAttendMeetings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void CanAttendMeetingsTest()
4040
new(9, 15)
4141
};
4242

43-
CanAttendMeetings(ex1).Should().BeFalse();
44-
CanAttendMeetings(ex2).Should().BeTrue();
43+
CanAttendMeetings(ex1).ShouldBeFalse();
44+
CanAttendMeetings(ex2).ShouldBeTrue();
4545
}
4646
}

LeetCode.CSharp/Problems/ClimbStairs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ public static int ClimbStairs(int n)
2727
[Theory]
2828
[InlineData(2, 2)]
2929
[InlineData(3, 3)]
30-
public void ClimbStairsTest(int n, int expected) => ClimbStairs(n).Should().Be(expected);
30+
public void ClimbStairsTest(int n, int expected) => ClimbStairs(n).ShouldBe(expected);
3131
}

LeetCode.CSharp/Problems/ContainsDuplicate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public static bool ContainsDuplicate(int[] nums)
1919
[InlineData(new[] { 1, 2, 3, 4 }, false)]
2020
[InlineData(new[] { 1, 1, 1, 3, 3, 4, 3, 2, 4, 2 }, true)]
2121
public void ContainsDuplicateTest(int[] nums, bool expected) =>
22-
ContainsDuplicate(nums).Should().Be(expected);
22+
ContainsDuplicate(nums).ShouldBe(expected);
2323
}

0 commit comments

Comments
 (0)