Skip to content

Commit 23aacbe

Browse files
Remove FluentAssertions; add internal xUnit assertion shims
Replaced FluentAssertions with custom extension methods in AssertionExtensions.cs that provide a similar API using xUnit's Assert. Removed the FluentAssertions package and related global using. This reduces dependencies and keeps assertion syntax familiar.
1 parent c4a4206 commit 23aacbe

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

Tests/AssertionExtensions.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Open.Text.Tests;
2+
3+
/// <summary>
4+
/// Lightweight shim providing FluentAssertions-like API using xUnit assertions.
5+
/// </summary>
6+
public static class AssertionExtensions
7+
{
8+
public static AssertionResult<T> Should<T>(this T actual) => new(actual);
9+
10+
public readonly struct AssertionResult<T>
11+
{
12+
private readonly T _actual;
13+
14+
public AssertionResult(T actual) => _actual = actual;
15+
16+
public void Be(T expected) => Assert.Equal(expected, _actual);
17+
18+
public void BeEquivalentTo(T expected) => Assert.Equal(expected, _actual);
19+
}
20+
21+
public static BoolAssertionResult Should(this bool actual) => new(actual);
22+
23+
public readonly struct BoolAssertionResult
24+
{
25+
private readonly bool _actual;
26+
27+
public BoolAssertionResult(bool actual) => _actual = actual;
28+
29+
public void Be(bool expected) => Assert.Equal(expected, _actual);
30+
31+
public void BeTrue() => Assert.True(_actual);
32+
33+
public void BeFalse() => Assert.False(_actual);
34+
}
35+
36+
public static StringAssertionResult Should(this string? actual) => new(actual);
37+
38+
public readonly struct StringAssertionResult
39+
{
40+
private readonly string? _actual;
41+
42+
public StringAssertionResult(string? actual) => _actual = actual;
43+
44+
public void Be(string? expected) => Assert.Equal(expected, _actual);
45+
46+
public void BeEquivalentTo(string? expected) => Assert.Equal(expected, _actual);
47+
}
48+
}

Tests/Open.Text.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
<PrivateAssets>all</PrivateAssets>
2222
</PackageReference>
23-
<PackageReference Include="FluentAssertions" Version="6.12.2" />
2423
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
2524
<PackageReference Include="xunit" Version="2.9.3" />
2625
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">

Tests/_Global.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
global using FluentAssertions;
2-
global using System.Diagnostics.CodeAnalysis;
1+
global using System.Diagnostics.CodeAnalysis;
32
global using Xunit;

0 commit comments

Comments
 (0)