Added a-frame-architecture usiung wolverine sample.
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Interfaces;
|
||||
using FinancialApi.Domain.Entities;
|
||||
using FinancialApi.Domain.Events;
|
||||
using FluentAssertions;
|
||||
using Wolverine;
|
||||
using Wolverine.Tracking;
|
||||
|
||||
namespace FinancialApi.Infrastructure.Tests;
|
||||
|
||||
internal class FakeAccountQuery : IAccountQuery
|
||||
{
|
||||
public Task<Account?> FindByIdAsync(int id) => Task.FromResult(new Account(id, 100.00m, AccountType.Spend))!;
|
||||
}
|
||||
|
||||
public class ApplyFeeIntegrationTests(WolverineTestFixture fixture) : IClassFixture<WolverineTestFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task GivenValidCommand_WhenApplyingFee_ShouldPublishFeeAppliedEvent()
|
||||
{
|
||||
// Arrange
|
||||
var command = new ApplyFeeCommand(1, 100);
|
||||
|
||||
// Act
|
||||
var session = await fixture.Host.InvokeMessageAndWaitAsync(command);
|
||||
|
||||
// Assert
|
||||
session.Sent.AllMessages()
|
||||
.ShouldHaveMessageOfType<FeeAppliedEvent>();
|
||||
session.Sent.MessagesOf<FeeAppliedEvent>()
|
||||
.Count()
|
||||
.Should()
|
||||
.Be(1);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4"/>
|
||||
<PackageReference Include="FluentAssertions" Version="8.10.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
|
||||
<PackageReference Include="NSubstitute" Version="6.0.0" />
|
||||
<PackageReference Include="WolverineFx" Version="6.24.1" />
|
||||
<PackageReference Include="WolverineFx.RuntimeCompilation" Version="6.24.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Extensions.Hosting">
|
||||
<HintPath>..\..\..\..\..\..\.nuget\packages\microsoft.extensions.hosting\10.0.0\lib\net10.0\Microsoft.Extensions.Hosting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
||||
<Reference Include="Microsoft.Extensions.TimeProvider.Testing">
|
||||
<HintPath>..\..\..\..\..\..\.nuget\packages\microsoft.extensions.timeprovider.testing\10.6.0\lib\net10.0\Microsoft.Extensions.TimeProvider.Testing.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FinancialApi.Application\FinancialApi.Application.csproj" />
|
||||
<ProjectReference Include="..\FinancialApi.Infrastructure\FinancialApi.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
using FinancialApi.Application.Handlers;
|
||||
using FinancialApi.Application.Interfaces;
|
||||
using FinancialApi.Domain.Events;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Time.Testing;
|
||||
using Wolverine;
|
||||
|
||||
namespace FinancialApi.Infrastructure.Tests;
|
||||
|
||||
public class WolverineTestFixture : IDisposable
|
||||
{
|
||||
public IHost Host { get; }
|
||||
|
||||
public WolverineTestFixture()
|
||||
{
|
||||
// We build and start the host ONCE here
|
||||
Host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddSingleton<IAccountQuery>(_ => new FakeAccountQuery());
|
||||
services.AddSingleton<TimeProvider>(_ => new FakeTimeProvider());
|
||||
services.AddSingleton<IEventTracker>(_ => new DemoEventStore());
|
||||
}
|
||||
)
|
||||
.UseWolverine(opts => { opts.Discovery.IncludeAssembly(typeof(ApplyFeeHandler).Assembly); })
|
||||
.Start();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Host.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user