Skip to content

Commit

Permalink
Remove FluentAssertions (#2459)
Browse files Browse the repository at this point in the history
Complete migration from FluentAssertions to Shouldly.

Resolves #2450.
  • Loading branch information
martincostello authored Jan 19, 2025
1 parent 3b8ba0e commit e3f1a3a
Show file tree
Hide file tree
Showing 98 changed files with 7,679 additions and 8,867 deletions.
2 changes: 2 additions & 0 deletions eng/Test.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<Using Include="Shouldly" />
<Using Include="Xunit" />
</ItemGroup>

Expand All @@ -15,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="ReportGenerator" PrivateAssets="all" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions test/Polly.Core.Tests/Polly.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="Microsoft.Bcl.TimeProvider" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" />
<PackageReference Include="Shouldly" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net9.0'))">
Expand All @@ -31,6 +30,5 @@
<ItemGroup>
<Using Include="Polly.Core.Tests.Helpers" />
<Using Include="Polly.TestUtils" />
<Using Include="Shouldly" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

<ItemGroup>
<Using Include="Polly.TestUtils" />
<Using Include="Shouldly" />
<ProjectReference Include="..\..\src\Polly.Extensions\Polly.Extensions.csproj" />
<ProjectReference Include="..\..\src\Polly.RateLimiting\Polly.RateLimiting.csproj" />
<ProjectReference Include="..\Polly.TestUtils\Polly.TestUtils.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Shouldly" />
<Reference Include="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
</ItemGroup>
</Project>
4 changes: 0 additions & 4 deletions test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@
<ProjectReference Include="..\..\src\Polly.RateLimiting\Polly.RateLimiting.csproj" />
<ProjectReference Include="..\..\src\Polly.Testing\Polly.Testing.csproj" />
<ProjectReference Include="..\Polly.TestUtils\Polly.TestUtils.csproj" />
<PackageReference Include="Shouldly" />
</ItemGroup>
<ItemGroup>
<Using Include="Shouldly" />
</ItemGroup>
</Project>
33 changes: 17 additions & 16 deletions test/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public void Should_throw_when_action_is_null()

var func = () => generic.Invoke(instance, [action, new Context(), CancellationToken, false]);

var exceptionAssertions = func.Should().Throw<TargetInvocationException>();
exceptionAssertions.And.Message.Should().Be("Exception has been thrown by the target of an invocation.");
exceptionAssertions.And.InnerException.Should().BeOfType<ArgumentNullException>()
.Which.ParamName.Should().Be("action");
var exceptionAssertions = Should.Throw<TargetInvocationException>(func);
exceptionAssertions.Message.ShouldBe("Exception has been thrown by the target of an invocation.");
exceptionAssertions.InnerException.ShouldBeOfType<ArgumentNullException>()
.ParamName.ShouldBe("action");
}

[Fact]
Expand All @@ -39,8 +39,8 @@ public void Should_throw_when_maxParallelization_less_or_equal_to_zero_and_no_ma
Action policy = () => Policy
.BulkheadAsync(0);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxParallelization");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxParallelization");
}

[Fact]
Expand All @@ -49,8 +49,8 @@ public void Should_throw_when_maxParallelization_less_or_equal_to_zero()
Action policy = () => Policy
.BulkheadAsync(0, 1);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxParallelization");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxParallelization");
}

[Fact]
Expand All @@ -59,8 +59,8 @@ public void Should_throw_when_maxQueuingActions_less_than_zero()
Action policy = () => Policy
.BulkheadAsync(1, -1);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxQueuingActions");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxQueuingActions");
}

[Fact]
Expand All @@ -69,8 +69,8 @@ public void Should_throw_when_onBulkheadRejected_is_null()
Action policy = () => Policy
.BulkheadAsync(1, 0, null!);

policy.Should().Throw<ArgumentNullException>().And
.ParamName.Should().Be("onBulkheadRejectedAsync");
Should.Throw<ArgumentNullException>(policy)
.ParamName.ShouldBe("onBulkheadRejectedAsync");
}

#endregion
Expand All @@ -94,7 +94,8 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()

Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

await bulkhead.Awaiting(b => b.ExecuteAsync(_ => TaskHelper.EmptyTask, contextPassedToExecute)).Should().ThrowAsync<BulkheadRejectedException>();
await Should.ThrowAsync<BulkheadRejectedException>(
() => bulkhead.ExecuteAsync(_ => TaskHelper.EmptyTask, contextPassedToExecute));

cancellationSource.Cancel();

Expand All @@ -105,9 +106,9 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
#endif
}

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
contextPassedToOnRejected!.ShouldNotBeNull();
contextPassedToOnRejected!.OperationKey.ShouldBe(operationKey);
contextPassedToOnRejected!.ShouldBeSameAs(contextPassedToExecute);
}

#endregion
Expand Down
33 changes: 16 additions & 17 deletions test/Polly.Specs/Bulkhead/BulkheadSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public void Should_throw_when_action_is_null()

var func = () => generic.Invoke(instance, [action, new Context(), CancellationToken]);

var exceptionAssertions = func.Should().Throw<TargetInvocationException>();
exceptionAssertions.And.Message.Should().Be("Exception has been thrown by the target of an invocation.");
exceptionAssertions.And.InnerException.Should().BeOfType<ArgumentNullException>()
.Which.ParamName.Should().Be("action");
var exceptionAssertions = Should.Throw<TargetInvocationException>(func);
exceptionAssertions.Message.ShouldBe("Exception has been thrown by the target of an invocation.");
exceptionAssertions.InnerException.ShouldBeOfType<ArgumentNullException>()
.ParamName.ShouldBe("action");
}

[Fact]
Expand All @@ -44,8 +44,8 @@ public void Should_throw_when_maxParallelization_less_or_equal_to_zero_and_no_ma
Action policy = () => Policy
.Bulkhead(0);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxParallelization");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxParallelization");
}

[Fact]
Expand All @@ -54,8 +54,8 @@ public void Should_throw_when_maxParallelization_less_or_equal_to_zero()
Action policy = () => Policy
.Bulkhead(0, 1);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxParallelization");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxParallelization");
}

[Fact]
Expand All @@ -64,8 +64,8 @@ public void Should_throw_when_maxQueuedActions_less_than_zero()
Action policy = () => Policy
.Bulkhead(1, -1);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxQueuingActions");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxQueuingActions");
}

[Fact]
Expand All @@ -74,8 +74,8 @@ public void Should_throw_when_onBulkheadRejected_is_null()
Action policy = () => Policy
.Bulkhead(1, 0, null!);

policy.Should().Throw<ArgumentNullException>().And
.ParamName.Should().Be("onBulkheadRejected");
Should.Throw<ArgumentNullException>(policy)
.ParamName.ShouldBe("onBulkheadRejected");
}

#endregion
Expand All @@ -99,18 +99,17 @@ public void Should_call_onBulkheadRejected_with_passed_context()
// Time for the other thread to kick up and take the bulkhead.
Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

bulkhead.Invoking(b => b.Execute(_ => { }, contextPassedToExecute)).Should()
.Throw<BulkheadRejectedException>();
Should.Throw<BulkheadRejectedException>(() => bulkhead.Execute(_ => { }, contextPassedToExecute));

#if NET
tcs.SetCanceled(CancellationToken);
#else
tcs.SetCanceled();
#endif

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
contextPassedToOnRejected!.ShouldNotBeNull();
contextPassedToOnRejected!.OperationKey.ShouldBe(operationKey);
contextPassedToOnRejected!.ShouldBeSameAs(contextPassedToExecute);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ protected void Within(TimeSpan timeSpan, Func<AssertionFailure?> actionContainin
if (watch.Elapsed > permitted)
{
TestOutputHelper.WriteLine("Failing assertion on: {0}", potentialFailure.Measure);
potentialFailure.Actual.Should().Be(potentialFailure.Expected, $"for '{potentialFailure.Measure}', in scenario: {Scenario}");
potentialFailure.Actual.ShouldBe(potentialFailure.Expected, $"for '{potentialFailure.Measure}', in scenario: {Scenario}");
throw new InvalidOperationException("Code should never reach here. Preceding assertion should fail.");
}

Expand Down
39 changes: 17 additions & 22 deletions test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
namespace Polly.Specs.Bulkhead;

[Collection(Constants.ParallelThreadDependentTestCollection)]
public class BulkheadTResultAsyncSpecs : BulkheadSpecsBase
public class BulkheadTResultAsyncSpecs(ITestOutputHelper testOutputHelper) : BulkheadSpecsBase(testOutputHelper)
{
public BulkheadTResultAsyncSpecs(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}

#region Configuration

[Fact]
Expand All @@ -31,10 +26,10 @@ public void Should_throw_when_action_is_null()

var func = () => methodInfo.Invoke(instance, [action, new Context(), CancellationToken, false]);

var exceptionAssertions = func.Should().Throw<TargetInvocationException>();
exceptionAssertions.And.Message.Should().Be("Exception has been thrown by the target of an invocation.");
exceptionAssertions.And.InnerException.Should().BeOfType<ArgumentNullException>()
.Which.ParamName.Should().Be("action");
var exceptionAssertions = Should.Throw<TargetInvocationException>(func);
exceptionAssertions.Message.ShouldBe("Exception has been thrown by the target of an invocation.");
exceptionAssertions.InnerException.ShouldBeOfType<ArgumentNullException>()
.ParamName.ShouldBe("action");
}

[Fact]
Expand All @@ -43,8 +38,8 @@ public void Should_throw_when_maxParallelization_less_or_equal_to_zero_and_no_ma
Action policy = () => Policy
.BulkheadAsync(0);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxParallelization");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxParallelization");
}

[Fact]
Expand All @@ -53,8 +48,8 @@ public void Should_throw_when_maxParallelization_less_or_equal_to_zero()
Action policy = () => Policy
.BulkheadAsync<int>(0, 1);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxParallelization");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxParallelization");
}

[Fact]
Expand All @@ -63,8 +58,8 @@ public void Should_throw_when_maxQueuingActions_less_than_zero()
Action policy = () => Policy
.BulkheadAsync<int>(1, -1);

policy.Should().Throw<ArgumentOutOfRangeException>().And
.ParamName.Should().Be("maxQueuingActions");
Should.Throw<ArgumentOutOfRangeException>(policy)
.ParamName.ShouldBe("maxQueuingActions");
}

[Fact]
Expand All @@ -73,8 +68,8 @@ public void Should_throw_when_onBulkheadRejected_is_null()
Action policy = () => Policy
.BulkheadAsync<int>(1, 0, null!);

policy.Should().Throw<ArgumentNullException>().And
.ParamName.Should().Be("onBulkheadRejectedAsync");
Should.Throw<ArgumentNullException>(policy)
.ParamName.ShouldBe("onBulkheadRejectedAsync");
}

#endregion
Expand Down Expand Up @@ -105,7 +100,7 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()

Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

await bulkhead.Awaiting(b => b.ExecuteAsync(_ => Task.FromResult(1), contextPassedToExecute)).Should().ThrowAsync<BulkheadRejectedException>();
await Should.ThrowAsync<BulkheadRejectedException>(() => bulkhead.ExecuteAsync(_ => Task.FromResult(1), contextPassedToExecute));

cancellationSource.Cancel();

Expand All @@ -116,9 +111,9 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
#endif
}

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
contextPassedToOnRejected.ShouldNotBeNull();
contextPassedToOnRejected.OperationKey.ShouldBe(operationKey);
contextPassedToOnRejected.ShouldBeSameAs(contextPassedToExecute);
}

#endregion
Expand Down
Loading

0 comments on commit e3f1a3a

Please sign in to comment.