Skip to content

Commit f523d01

Browse files
committed
feat: migrate from FluentAssertions to Shouldly in unit and integration tests
1 parent be886d5 commit f523d01

File tree

10 files changed

+31
-16
lines changed

10 files changed

+31
-16
lines changed

Chapter-4-applying-tactical-domain-driven-design/Fitnet.Common/Fitnet.Common.Api.UnitTests/ExceptionMiddlewareTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
namespace EvolutionaryArchitecture.Fitnet.Common.Api.UnitTests;
22

3+
using System;
4+
using System.IO;
5+
using System.Net;
6+
using System.Threading.Tasks;
37
using ErrorHandling;
8+
using Microsoft.AspNetCore.Http;
9+
using Newtonsoft.Json;
10+
using Shouldly;
11+
using Xunit;
412

513
public sealed class ExceptionMiddlewareTests
614
{
@@ -18,10 +26,10 @@ internal async Task Given_any_unexpected_exception_Then_returns_internal_server_
1826
await middleware.InvokeAsync(_context);
1927

2028
// Assert
21-
_context.Response.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
29+
_context.Response.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);
2230

2331
var responseMessage = await GetExceptionResponseMessage();
24-
responseMessage.Should().Be(exceptionMessage);
32+
responseMessage.ShouldBe(exceptionMessage);
2533
}
2634

2735
private static DefaultHttpContext GetHttpContext() =>

Chapter-4-applying-tactical-domain-driven-design/Fitnet.Common/Fitnet.Common.Api.UnitTests/Fitnet.Common.Api.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="FluentAssertions" Version="6.12.2" />
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
14+
<PackageReference Include="Shouldly" Version="4.3.0" />
1415
<PackageReference Include="xunit" Version="2.9.2" />
1516
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1617
<PrivateAssets>all</PrivateAssets>

Chapter-4-applying-tactical-domain-driven-design/Fitnet.Common/Fitnet.Common.Core.UnitTests/BusinessRulesEngine/BusinessRuleValidatorTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace EvolutionaryArchitecture.Fitnet.Common.Core.UnitTests.BusinessRulesEngine;
22

33
using BussinessRules;
4-
using EvolutionaryArchitecture.Fitnet.Common.UnitTesting.Assertions.ErrorOr;
54

65
public sealed class BusinessRuleValidatorTests
76
{
@@ -14,7 +13,7 @@ internal void Given_concrete_business_rule_which_is_met_Then_validation_should_p
1413
var result = BusinessRuleValidator.Validate(new FakeBusinessRule(20));
1514

1615
// Assert
17-
result.Should().BeSuccessful();
16+
result.IsError.ShouldBeFalse();
1817
}
1918

2019
[Fact]
@@ -27,6 +26,6 @@ internal void Given_concrete_business_rule_which_is_not_met_Then_validation_shou
2726
var result = BusinessRuleValidator.Validate(testRule);
2827

2928
// Assert
30-
result.Should().ContainError(testRule.Error);
29+
result.Errors.ShouldContain(testRule.Error);
3130
}
3231
}

Chapter-4-applying-tactical-domain-driven-design/Fitnet.Common/Fitnet.Common.Core.UnitTests/Fitnet.Common.Core.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="FluentAssertions" Version="6.12.2" />
13+
<PackageReference Include="Shouldly" Version="4.3.0" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1515
<PackageReference Include="xunit" Version="2.9.2" />
1616
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
global using Xunit;
22
global using FluentAssertions;
3+
global using Shouldly;

Chapter-4-applying-tactical-domain-driven-design/Fitnet/Src/Offers/Tests/Fitnet.Offers.IntegrationTests/Fitnet.Offers.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0" />
99
<PackageReference Include="evolutionaryarchitecture.fitnet.common.integrationteststoolbox" Version="4.1.7" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
11+
<PackageReference Include="Shouldly" Version="4.3.0" />
1112
<PackageReference Include="System.Net.Http" Version="4.3.4" />
1213
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.0" />
1314
<PackageReference Include="System.Text.Json" Version="9.0.0" />

Chapter-4-applying-tactical-domain-driven-design/Fitnet/Src/Offers/Tests/Fitnet.Offers.IntegrationTests/Prepare/PrepareOfferTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace EvolutionaryArchitecture.Fitnet.Offers.IntegrationTests.Prepare;
66
using Common.IntegrationTestsToolbox.TestEngine.Configuration;
77
using EvolutionaryArchitecture.Fitnet.Common.IntegrationTestsToolbox.TestEngine.Database;
88
using Passes.IntegrationEvents;
9+
using Shouldly;
910

1011
public sealed class PrepareOfferTests : IClassFixture<FitnetWebApplicationFactory<Program>>,
1112
IClassFixture<DatabaseContainer>
@@ -40,6 +41,6 @@ internal async Task Given_pass_expired_event_published_Then_new_offer_should_be_
4041
private async Task EnsureThatOfferPreparedEventWasPublished()
4142
{
4243
var offerPrepared = await _testEventBus.Published.Any<OfferPrepareEvent>();
43-
offerPrepared.Should().BeTrue();
44+
offerPrepared.ShouldBeTrue();
4445
}
4546
}

Chapter-4-applying-tactical-domain-driven-design/Fitnet/Src/Passes/Tests/Fitnet.Passes.IntegrationTests/Fitnet.Passes.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.IntegrationTestsToolbox" Version="4.1.7" />
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
10+
<PackageReference Include="Shouldly" Version="4.3.0" />
1011
<PackageReference Include="System.Net.Http" Version="4.3.4" />
1112
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.0" />
1213
<PackageReference Include="System.Text.Json" Version="9.0.0" />

Chapter-4-applying-tactical-domain-driven-design/Fitnet/Src/Passes/Tests/Fitnet.Passes.IntegrationTests/GlobalUsings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
global using Xunit;
44
global using Bogus;
55
global using FluentAssertions;
6-
global using MassTransit.Testing;
6+
global using MassTransit.Testing;
7+
global using Shouldly;

Chapter-4-applying-tactical-domain-driven-design/Fitnet/Src/Passes/Tests/Fitnet.Passes.IntegrationTests/MarkPassAsExpired/MarkPassAsExpiredTests.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace EvolutionaryArchitecture.Fitnet.Passes.IntegrationTests.MarkPassAsExpi
1010
using Contracts.IntegrationEvents;
1111
using IntegrationEvents;
1212
using RegisterPass;
13+
using System.Net;
14+
using System.Net.Http.Json;
1315

1416
public sealed class MarkPassAsExpiredTests : IClassFixture<FitnetWebApplicationFactory<Program>>, IClassFixture<DatabaseContainer>
1517
{
@@ -37,10 +39,10 @@ internal async Task Given_valid_mark_pass_as_expired_request_Then_should_return_
3739
var url = BuildUrl(registeredPassId);
3840

3941
// Act
40-
await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
42+
var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
4143

4244
// Assert
43-
await EnsureThatPassExpiredEventWasPublished();
45+
markAsExpiredResponse.StatusCode.ShouldBe(HttpStatusCode.NoContent);
4446
}
4547

4648
[Fact]
@@ -52,10 +54,10 @@ internal async Task Given_valid_mark_pass_as_expired_request_Then_should_publish
5254
var url = BuildUrl(registeredPassId);
5355

5456
// Act
55-
var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
57+
await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
5658

5759
// Assert
58-
markAsExpiredResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
60+
await EnsureThatPassExpiredEventWasPublished();
5961
}
6062

6163
[Fact]
@@ -69,7 +71,7 @@ internal async Task Given_mark_pass_as_expired_request_with_not_existing_id_Then
6971
var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
7072

7173
// Assert
72-
markAsExpiredResponse.Should().HaveStatusCode(HttpStatusCode.NotFound);
74+
markAsExpiredResponse.StatusCode.ShouldBe(HttpStatusCode.NotFound);
7375
}
7476

7577
private async Task<ContractSignedEvent> RegisterPass()
@@ -86,16 +88,16 @@ private async Task<Guid> GetCreatedPass(Guid customerId)
8688
var getAllPassesResponse = await _applicationHttpClient.GetAsync(PassesApiPaths.GetAll);
8789
var response = await getAllPassesResponse.Content.ReadFromJsonAsync<GetAllPassesResponse>();
8890
var createdPass = response!.Passes.FirstOrDefault(pass => pass.CustomerId == customerId);
89-
createdPass.Should().NotBeNull();
91+
createdPass.ShouldNotBeNull();
9092

91-
return createdPass!.Id;
93+
return createdPass.Id;
9294
}
9395

9496
private static string BuildUrl(Guid id) => PassesApiPaths.MarkPassAsExpired.Replace("{id}", id.ToString());
9597

9698
private async Task EnsureThatPassExpiredEventWasPublished()
9799
{
98100
var passRegisteredEventPublished = await _testEventBus.Published.Any<PassExpiredEvent>();
99-
passRegisteredEventPublished.Should().BeTrue();
101+
passRegisteredEventPublished.ShouldBeTrue();
100102
}
101103
}

0 commit comments

Comments
 (0)