Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions Chapter-1-initial-architecture/Src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<Project>

<PropertyGroup>
<AssemblyName>EvolutionaryArchitecture.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFramework>net9.0</TargetFramework>
<AnalysisLevel>latest</AnalysisLevel>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
<PropertyGroup>
<AssemblyName>EvolutionaryArchitecture.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFramework>net9.0</TargetFramework>
<AnalysisLevel>latest</AnalysisLevel>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
</ItemGroup>

<ItemGroup>
<PackageReference
Include="SonarAnalyzer.CSharp"
Version="9.7.0.75501"
PrivateAssets="all"
Condition="$(MSBuildProjectExtension) == '.csproj'"
/>
</ItemGroup>

<ItemGroup>
<PackageReference
Include="SonarAnalyzer.CSharp"
Version="9.7.0.75501"
PrivateAssets="all"
Condition="$(MSBuildProjectExtension) == '.csproj'"
/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
<ItemGroup>
<PackageReference Include="NetArchTest.Rules" Version="1.3.2" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.analyzers" Version="1.17.0">
<PackageReference Include="xunit.v3" Version="3.2.0" />
<PackageReference Include="xunit.analyzers" Version="1.26.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.categories" Version="2.0.8" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class DatabaseContainer : IAsyncLifetime
private PostgreSqlContainer? _container;
internal string? ConnectionString;

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
_container = new PostgreSqlBuilder()
.WithDatabase(Database)
Expand All @@ -24,5 +24,5 @@ public async Task InitializeAsync()
ConnectionString = _container.GetConnectionString();
}

public async Task DisposeAsync() => await _container!.StopAsync();
public async ValueTask DisposeAsync() => await _container!.StopAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ internal async Task Given_valid_contract_preparation_request_When_preparing_new_
var customerId = Guid.NewGuid();
var requestParameters = PrepareContractRequestParameters.GetValid();
var prepareContractResponse = await PrepareCorrectContract(requestParameters, customerId);
var preparedContractId = await prepareContractResponse.Content.ReadFromJsonAsync<Guid>();
var preparedContractId = await prepareContractResponse.Content.ReadFromJsonAsync<Guid>(TestContext.Current.CancellationToken);
var signContractRequestParameters = SignContractRequestParameters.GetValid(preparedContractId);
var signContractRequest = new SignContractRequest(signContractRequestParameters.SignedAt);
var signContractResponse =
await _applicationHttpClient.PatchAsJsonAsync(signContractRequestParameters.Url, signContractRequest);
await _applicationHttpClient.PatchAsJsonAsync(signContractRequestParameters.Url, signContractRequest, TestContext.Current.CancellationToken);
signContractResponse.StatusCode.ShouldBe(HttpStatusCode.NoContent);

// Act
Expand All @@ -62,12 +62,12 @@ internal async Task Given_contract_preparation_request_with_invalid_age_Then_sho

// Act
using var prepareContractResponse =
await _applicationHttpClient.PostAsJsonAsync(ContractsApiPaths.Prepare, prepareContractRequest);
await _applicationHttpClient.PostAsJsonAsync(ContractsApiPaths.Prepare, prepareContractRequest, TestContext.Current.CancellationToken);

// Assert
prepareContractResponse.StatusCode.ShouldBe(HttpStatusCode.Conflict);

var responseMessage = await prepareContractResponse.Content.ReadFromJsonAsync<ProblemDetails>();
var responseMessage = await prepareContractResponse.Content.ReadFromJsonAsync<ProblemDetails>(TestContext.Current.CancellationToken);
responseMessage?.Status.ShouldBe((int)HttpStatusCode.Conflict);
responseMessage?.Title.ShouldBe("Contract can not be prepared for a person who is not adult");
}
Expand All @@ -83,12 +83,12 @@ internal async Task Given_contract_preparation_request_with_invalid_height_Then_

// Act
using var prepareContractResponse =
await _applicationHttpClient.PostAsJsonAsync(ContractsApiPaths.Prepare, prepareContractRequest);
await _applicationHttpClient.PostAsJsonAsync(ContractsApiPaths.Prepare, prepareContractRequest, TestContext.Current.CancellationToken);

// Assert
prepareContractResponse.StatusCode.ShouldBe(HttpStatusCode.Conflict);

var responseMessage = await prepareContractResponse.Content.ReadFromJsonAsync<ProblemDetails>();
var responseMessage = await prepareContractResponse.Content.ReadFromJsonAsync<ProblemDetails>(TestContext.Current.CancellationToken);
responseMessage?.Status.ShouldBe((int)HttpStatusCode.Conflict);
responseMessage?.Title.ShouldBe("Customer height must fit maximum limit for gym instruments");
}
Expand All @@ -107,7 +107,7 @@ internal async Task

// Assert
prepareContractResponse.StatusCode.ShouldBe(HttpStatusCode.Conflict);
var responseMessage = await prepareContractResponse.Content.ReadFromJsonAsync<ProblemDetails>();
var responseMessage = await prepareContractResponse.Content.ReadFromJsonAsync<ProblemDetails>(TestContext.Current.CancellationToken);
responseMessage?.Status.ShouldBe((int)HttpStatusCode.Conflict);
responseMessage?.Title.ShouldBe("Previous contract must be signed by the customer");
}
Expand All @@ -123,9 +123,9 @@ private async Task<HttpResponseMessage> PrepareCorrectContract(PrepareContractRe
return prepareContractResponse;
}

public Task InitializeAsync() => Task.CompletedTask;
public ValueTask InitializeAsync() => ValueTask.CompletedTask;

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
_applicationHttpClient.Dispose();
await applicationInMemoryFactory.DisposeAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public SignContractTests(WebApplicationFactory<Program> applicationInMemoryFacto
.CreateClient();
}

public Task InitializeAsync() => Task.CompletedTask;
public ValueTask InitializeAsync() => ValueTask.CompletedTask;

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
_applicationHttpClient.Dispose();
await _applicationInMemoryFactory.DisposeAsync();
Expand All @@ -43,7 +43,7 @@ internal async Task Given_valid_contract_signature_request_Then_should_return_no

// Act
using var signContractResponse =
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest);
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest, TestContext.Current.CancellationToken);

// Assert
signContractResponse.StatusCode.ShouldBe(HttpStatusCode.NoContent);
Expand All @@ -58,7 +58,7 @@ internal async Task Given_valid_contract_signature_request_Then_contract_signed_
var signContractRequest = new SignContractRequest(requestParameters.SignedAt);

// Act
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest);
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest, TestContext.Current.CancellationToken);

// Assert
EnsureThatContractSignedEventWasPublished();
Expand All @@ -76,7 +76,7 @@ internal async Task Given_contract_signature_request_with_not_existing_id_Then_s

// Act
using var signContractResponse =
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest);
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest, TestContext.Current.CancellationToken);

// Assert
signContractResponse.StatusCode.ShouldBe(HttpStatusCode.NotFound);
Expand All @@ -94,12 +94,12 @@ internal async Task

// Act
using var signContractResponse =
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest);
await _applicationHttpClient.PatchAsJsonAsync(requestParameters.Url, signContractRequest, TestContext.Current.CancellationToken);

// Assert
signContractResponse.StatusCode.ShouldBe(HttpStatusCode.Conflict);

var responseMessage = await signContractResponse.Content.ReadFromJsonAsync<ProblemDetails>();
var responseMessage = await signContractResponse.Content.ReadFromJsonAsync<ProblemDetails>(TestContext.Current.CancellationToken);
responseMessage?.Status.ShouldBe((int)HttpStatusCode.Conflict);
responseMessage?.Title.ShouldBe("Contract can not be signed because more than 30 days have passed from the contract preparation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);S3604</NoWarn>
<NoWarn>$(NoWarn);S3604;xUnit1050</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.0.0" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="Verify.Xunit" Version="28.2.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="Verify.XunitV3" Version="31.7.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Testcontainers" Version="4.0.0" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.analyzers" Version="1.17.0">
<PackageReference Include="xunit.v3" Version="3.2.0" />
<PackageReference Include="xunit.analyzers" Version="1.26.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.categories" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal async Task Given_valid_mark_pass_as_expired_request_Then_should_return_
var url = BuildUrl(registeredPassId);

// Act
await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent, TestContext.Current.CancellationToken);

// Assert
EnsureThatPassExpiredEventWasPublished();
Expand All @@ -51,7 +51,7 @@ internal async Task Given_valid_mark_pass_as_expired_request_Then_should_publish
var url = BuildUrl(registeredPassId);

// Act
using var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
using var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent, TestContext.Current.CancellationToken);

// Assert
markAsExpiredResponse.StatusCode.ShouldBe(HttpStatusCode.NoContent);
Expand All @@ -65,7 +65,7 @@ internal async Task Given_mark_pass_as_expired_request_with_not_existing_id_Then
var url = BuildUrl(notExistingId);

// Act
using var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent);
using var markAsExpiredResponse = await _applicationHttpClient.PatchAsJsonAsync(url, EmptyContent, TestContext.Current.CancellationToken);

// Assert
markAsExpiredResponse.StatusCode.ShouldBe(HttpStatusCode.NotFound);
Expand Down Expand Up @@ -103,9 +103,9 @@ private async Task<Guid> GetCreatedPass(Guid customerId)
private void EnsureThatPassExpiredEventWasPublished() => _fakeEventBus.Received(1)
.PublishAsync(Arg.Any<PassExpiredEvent>(), Arg.Any<CancellationToken>());

public Task InitializeAsync() => Task.CompletedTask;
public ValueTask InitializeAsync() => ValueTask.CompletedTask;

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
_applicationHttpClient.Dispose();
await _applicationInMemoryFactory.DisposeAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public RegisterPassTests(WebApplicationFactory<Program> applicationInMemoryFacto
_applicationHttpClient = _applicationInMemory.CreateClient();
}

public Task InitializeAsync() => Task.CompletedTask;
public ValueTask InitializeAsync() => ValueTask.CompletedTask;

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
_applicationHttpClient.Dispose();
await _applicationInMemory.DisposeAsync();
Expand All @@ -38,7 +38,7 @@ internal async Task Given_contract_signed_event_Then_should_register_pass()
var @event = ContractSignedEventFaker.Create();

// Act
await integrationEventHandlerScope.Consume(@event);
await integrationEventHandlerScope.Consume(@event, TestContext.Current.CancellationToken);

// Assert
EnsureThatPassRegisteredEventWasPublished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ internal async Task Given_valid_generate_new_report_request_Then_should_return_c
await RegisterPasses(passRegistrationDateRanges);

// Act
using var getReportResult = await _applicationHttpClient.GetAsync(ReportsApiPaths.GenerateNewReport);
using var getReportResult = await _applicationHttpClient.GetAsync(ReportsApiPaths.GenerateNewReport, TestContext.Current.CancellationToken);

// Assert
getReportResult.StatusCode.ShouldBe(HttpStatusCode.OK);
var reportData = await getReportResult.Content.ReadFromJsonAsync<NewPassesRegistrationsPerMonthResponse>();
var reportData = await getReportResult.Content.ReadFromJsonAsync<NewPassesRegistrationsPerMonthResponse>(TestContext.Current.CancellationToken);
await Verify(reportData);
}

Expand All @@ -59,9 +59,9 @@ private async Task RegisterPass(DateTimeOffset from, DateTimeOffset to)
await integrationEventHandler.Handle(@event, CancellationToken.None);
}

public Task InitializeAsync() => Task.CompletedTask;
public ValueTask InitializeAsync() => ValueTask.CompletedTask;

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
_applicationHttpClient.Dispose();
await _applicationInMemoryFactory.DisposeAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ internal sealed class SignContractTestData : TheoryData<DateTimeOffset, DateTime
{
public SignContractTestData()
{
AddRow(new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero),
Add(new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero),
new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero),
new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero),
new DateTimeOffset(2022, 1, 1, 1, 1, 1, TimeSpan.Zero));

AddRow(new DateTimeOffset(2022, 6, 1, 12, 0, 0, TimeSpan.Zero),
Add(new DateTimeOffset(2022, 6, 1, 12, 0, 0, TimeSpan.Zero),
new DateTimeOffset(2022, 6, 1, 12, 0, 0, TimeSpan.Zero),
new DateTimeOffset(2022, 6, 1, 12, 0, 0, TimeSpan.Zero),
new DateTimeOffset(2023, 6, 1, 12, 0, 0, TimeSpan.Zero));

AddRow(new DateTimeOffset(2023, 2, 15, 8, 30, 0, TimeSpan.Zero),
Add(new DateTimeOffset(2023, 2, 15, 8, 30, 0, TimeSpan.Zero),
new DateTimeOffset(2023, 2, 15, 8, 30, 0, TimeSpan.Zero),
new DateTimeOffset(2023, 2, 15, 8, 30, 0, TimeSpan.Zero),
new DateTimeOffset(2024, 2, 15, 8, 30, 0, TimeSpan.Zero));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);xUnit1050</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.analyzers" Version="1.17.0">
<PackageReference Include="xunit.v3" Version="3.2.0" />
<PackageReference Include="xunit.analyzers" Version="1.26.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.categories" Version="2.0.8" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal async Task Given_business_rule_validation_exception_Then_returns_confli
var exceptionHandler = new GlobalExceptionHandler(_logger);

// Act
await exceptionHandler.TryHandleAsync(_context, new BusinessRuleValidationException(exceptionMessage), default);
await exceptionHandler.TryHandleAsync(_context, new BusinessRuleValidationException(exceptionMessage), TestContext.Current.CancellationToken);

// Assert
_context.Response.StatusCode.ShouldBe((int)HttpStatusCode.Conflict);
Expand All @@ -37,7 +37,7 @@ internal async Task Given_other_than_business_rule_validation_exception_Then_ret
var exceptionHandler = new GlobalExceptionHandler(_logger);

// Act
await exceptionHandler.TryHandleAsync(_context, new InvalidCastException("test"), CancellationToken.None);
await exceptionHandler.TryHandleAsync(_context, new InvalidCastException("test"), TestContext.Current.CancellationToken);

// Assert
_context.Response.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);
Expand Down
Loading