Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade Fitnet.Contracts to dotnet 8 #47

Merged
merged 2 commits into from
Nov 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>EvolutionaryArchitecture.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AnalysisLevel>latest</AnalysisLevel>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.analyzers" Version="1.1.0" />
<PackageReference Include="xunit.categories" Version="2.0.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.analyzers" Version="1.6.0" />
<PackageReference Include="xunit.categories" Version="2.0.8" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="evolutionaryarchitecture.fitnet.common.api" Version="1.1.7" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="MediatR" Version="12.0.1" />
<PackageReference Include="evolutionaryarchitecture.fitnet.common.api" Version="1.1.8" />
<PackageReference Include="evolutionaryarchitecture.fitnet.contracts.integrationevents" Version="1.0.7" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="MassTransit.Abstractions" Version="8.1.2" />
<PackageReference Include="MediatR" Version="12.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fitnet.Contracts.Core\Fitnet.Contracts.Core.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.Application.Prepare;
using Core;

[UsedImplicitly]
internal sealed class PrepareContractCommandHandler : IRequestHandler<PrepareContractCommand, Guid>
internal sealed class PrepareContractCommandHandler(IContractsRepository contractsRepository) : IRequestHandler<PrepareContractCommand, Guid>
{
private readonly IContractsRepository _contractsRepository;

public PrepareContractCommandHandler(IContractsRepository contractsRepository) =>
_contractsRepository = contractsRepository;

public async Task<Guid> Handle(PrepareContractCommand command, CancellationToken cancellationToken)
{
var previousContract = await _contractsRepository.GetPreviousForCustomerAsync(command.CustomerId, cancellationToken);
var previousContract = await contractsRepository.GetPreviousForCustomerAsync(command.CustomerId, cancellationToken);
var contract = Contract.Prepare(command.CustomerId, command.CustomerAge, command.CustomerHeight, command.PreparedAt, previousContract?.IsSigned);
await _contractsRepository.AddAsync(contract, cancellationToken);
await contractsRepository.AddAsync(contract, cancellationToken);

return contract.Id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,21 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.Application.Sign;
using MassTransit;

[UsedImplicitly]
internal sealed class SignContractCommandHandler : IRequestHandler<SignContractCommand>
internal sealed class SignContractCommandHandler(
IContractsRepository contractsRepository,
ISystemClock systemClock,
IPublishEndpoint publishEndpoint) : IRequestHandler<SignContractCommand>
{
private readonly IContractsRepository _contractsRepository;
private readonly ISystemClock _systemClock;
private readonly IPublishEndpoint _publishEndpoint;

public SignContractCommandHandler(
IContractsRepository contractsRepository,
ISystemClock systemClock,
IPublishEndpoint publishEndpoint)
{
_contractsRepository = contractsRepository;
_systemClock = systemClock;
_publishEndpoint = publishEndpoint;
}

public async Task Handle(SignContractCommand command, CancellationToken cancellationToken)
{
var contract = await _contractsRepository.GetByIdAsync(command.Id, cancellationToken) ??
var contract = await contractsRepository.GetByIdAsync(command.Id, cancellationToken) ??
throw new ResourceNotFoundException(command.Id);
contract.Sign(command.SignedAt, _systemClock.Now);
await _contractsRepository.CommitAsync(cancellationToken);
contract.Sign(command.SignedAt, systemClock.Now);
await contractsRepository.CommitAsync(cancellationToken);
var @event = ContractSignedEvent.Create(contract.Id,
contract.CustomerId,
contract.SignedAt!.Value,
contract.ExpiringAt!.Value);
await _publishEndpoint.Publish(@event, cancellationToken);
await publishEndpoint.Publish(@event, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="1.1.7" />
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.analyzers" Version="1.1.0" />
<PackageReference Include="xunit.categories" Version="2.0.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="1.1.8" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.analyzers" Version="1.6.0" />
<PackageReference Include="xunit.categories" Version="2.0.8" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.SignContract;

internal sealed class SignContractTestData : IEnumerable<object[]>
{
private readonly List<object[]> _data = new()
{
new object[]
{
private readonly List<object[]> _data =
[
[
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)
},
new object[]
{
],
[
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)
},
new object[]
{
],
[
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)
}
};
]
];

public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="1.1.7" />
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="1.1.8" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
using Application;
using MediatR;

internal sealed class ContractsModule : IContractsModule
internal sealed class ContractsModule(IMediator mediator) : IContractsModule
{
private readonly IMediator _mediator;

public ContractsModule(IMediator mediator) =>
_mediator = mediator;

public async Task ExecuteCommandAsync(ICommand command, CancellationToken cancellationToken = default) =>
await _mediator.Send(command, cancellationToken);
await mediator.Send(command, cancellationToken);

public async Task<TResult> ExecuteCommandAsync<TResult>(ICommand<TResult> command, CancellationToken cancellationToken = default) =>
await _mediator.Send(command, cancellationToken);
await mediator.Send(command, cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.Infrastructure.Database;
using Core;
using Microsoft.EntityFrameworkCore;

public sealed class ContractsPersistence : DbContext
public sealed class ContractsPersistence(DbContextOptions<ContractsPersistence> options) : DbContext(options)
{
private const string Schema = "Contracts";

public ContractsPersistence(DbContextOptions<ContractsPersistence> options)
: base(options)
{
}

public DbSet<Contract> Contracts => Set<Contract>();

protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.Infrastructure.Database.Repo
using Core;
using Microsoft.EntityFrameworkCore;

internal sealed class ContractsRepository : IContractsRepository
internal sealed class ContractsRepository(ContractsPersistence persistence) : IContractsRepository
{
private readonly ContractsPersistence _persistence;

public ContractsRepository(ContractsPersistence persistence) =>
_persistence = persistence;

public async Task<Contract?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default) =>
await _persistence.Contracts.FindAsync(new object?[] { id }, cancellationToken);
await persistence.Contracts.FindAsync([id], cancellationToken);

public async Task<Contract?> GetPreviousForCustomerAsync(Guid customerId, CancellationToken cancellationToken = default) =>
await _persistence.Contracts
await persistence.Contracts
.OrderByDescending(contract => contract.PreparedAt)
.SingleOrDefaultAsync(contract => contract.CustomerId == customerId, cancellationToken);

public async Task AddAsync(Contract contract, CancellationToken cancellationToken = default)
{
await _persistence.Contracts.AddAsync(contract, cancellationToken);
await _persistence.SaveChangesAsync(cancellationToken);
await persistence.Contracts.AddAsync(contract, cancellationToken);
await persistence.SaveChangesAsync(cancellationToken);
}

public async Task CommitAsync(CancellationToken cancellationToken = default) =>
await _persistence.SaveChangesAsync(cancellationToken);
await persistence.SaveChangesAsync(cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.0.1" />
<PackageReference Include="MassTransit" Version="8.1.2" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.1.2" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<Version>1.0.7</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Infrastructure" Version="1.1.7" />
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Infrastructure" Version="1.1.8" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="evolutionaryarchitecture.fitnet.common.api" Version="1.1.7" />
<PackageReference Include="evolutionaryarchitecture.fitnet.common.integrationteststoolbox" Version="1.1.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="evolutionaryarchitecture.fitnet.common.api" Version="1.1.8" />
<PackageReference Include="evolutionaryarchitecture.fitnet.common.integrationteststoolbox" Version="1.1.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.IntegrationTests.PrepareCont
using Api;
using Api.Prepare;

public sealed class PrepareContractTests : IClassFixture<FitnetWebApplicationFactory<Program>>,
public sealed class PrepareContractTests(FitnetWebApplicationFactory<Program> applicationInMemoryFactory,
DatabaseContainer database) : IClassFixture<FitnetWebApplicationFactory<Program>>,
IClassFixture<DatabaseContainer>
{
private readonly HttpClient _applicationHttpClient;

public PrepareContractTests(FitnetWebApplicationFactory<Program> applicationInMemoryFactory,
DatabaseContainer database) =>
_applicationHttpClient = applicationInMemoryFactory
private readonly HttpClient _applicationHttpClient = applicationInMemoryFactory
.WithContainerDatabaseConfigured(new ContractsDatabaseConfiguration(database.ConnectionString!))
.WithTestEventBus()
.CreateClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.IntegrationTests.SignContrac
using Api.Sign;
using PrepareContract;

public sealed class SignContractTests : IClassFixture<FitnetWebApplicationFactory<Program>>, IClassFixture<DatabaseContainer>
public sealed class SignContractTests(FitnetWebApplicationFactory<Program> applicationInMemoryFactory,
DatabaseContainer database) : IClassFixture<FitnetWebApplicationFactory<Program>>, IClassFixture<DatabaseContainer>
{
private readonly HttpClient _applicationHttpClient;

public SignContractTests(FitnetWebApplicationFactory<Program> applicationInMemoryFactory,
DatabaseContainer database) =>
_applicationHttpClient = applicationInMemoryFactory
private readonly HttpClient _applicationHttpClient = applicationInMemoryFactory
.WithContainerDatabaseConfigured(new ContractsDatabaseConfiguration(database.ConnectionString!))
.WithTestEventBus()
.CreateClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fitnet.Contracts.Infrastruc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fitnet.Contracts.Api.UnitTests", "Fitnet.Contracts.Api.UnitTests\Fitnet.Contracts.Api.UnitTests.csproj", "{27C6CD2F-9252-42F0-B952-188F848FBD39}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fitnet.Contracts.IntegrationEvents", "Fitnet.Contracts.IntegrationEvents\Fitnet.Contracts.IntegrationEvents.csproj", "{0A0A7C05-D0FB-4FC3-95D3-1B1511D0B24D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -56,6 +58,10 @@ Global
{27C6CD2F-9252-42F0-B952-188F848FBD39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27C6CD2F-9252-42F0-B952-188F848FBD39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27C6CD2F-9252-42F0-B952-188F848FBD39}.Release|Any CPU.Build.0 = Release|Any CPU
{0A0A7C05-D0FB-4FC3-95D3-1B1511D0B24D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A0A7C05-D0FB-4FC3-95D3-1B1511D0B24D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A0A7C05-D0FB-4FC3-95D3-1B1511D0B24D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A0A7C05-D0FB-4FC3-95D3-1B1511D0B24D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ABC9D0F9-7D4F-4C89-8A68-B2DCB5DF93A8} = {FA67FD7C-D24A-4733-B6A5-FF78713CBFCD}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Api" Version="1.1.7" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Api" Version="1.1.8" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="evolutionaryarchitecture.fitnet.common.core" Version="1.1.5" />
<PackageReference Include="evolutionaryarchitecture.fitnet.common.core" Version="1.1.8" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
</ItemGroup>
</Project>
Loading