mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-09 07:51:14 +08:00
add logger to base integration test fixture
This commit is contained in:
parent
f325dd18ee
commit
b779e6b11a
@ -67,7 +67,7 @@
|
|||||||
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
|
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
|
||||||
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.0" />
|
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.SpectreConsole" Version="0.1.1" />
|
<PackageReference Include="Serilog.Sinks.SpectreConsole" Version="0.1.1" />
|
||||||
<PackageReference Include="Serilog.Sinks.Xunit2" Version="1.1.0" />
|
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
|
||||||
|
|||||||
@ -6,6 +6,7 @@ namespace BuildingBlocks.EventStoreDB;
|
|||||||
|
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
|
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
||||||
public static IServiceCollection AddEventStore(
|
public static IServiceCollection AddEventStore(
|
||||||
this IServiceCollection services,
|
this IServiceCollection services,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
|
|||||||
@ -53,7 +53,7 @@ builder.Services.AddCustomOpenTelemetry();
|
|||||||
builder.Services.AddTransient<AuthHeaderHandler>();
|
builder.Services.AddTransient<AuthHeaderHandler>();
|
||||||
SnowFlakIdGenerator.Configure(3);
|
SnowFlakIdGenerator.Configure(3);
|
||||||
|
|
||||||
// EventStoreDB Configuration
|
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
||||||
builder.Services.AddEventStore(configuration, typeof(BookingRoot).Assembly)
|
builder.Services.AddEventStore(configuration, typeof(BookingRoot).Assembly)
|
||||||
.AddEventStoreDBSubscriptionToAll();
|
.AddEventStoreDBSubscriptionToAll();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||||
using Flight.Flights.Features.CreateFlight;
|
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Integration.Test.Fakes;
|
using Integration.Test.Fakes;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
|
||||||
using BuildingBlocks.Domain.Model;
|
using BuildingBlocks.Domain.Model;
|
||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
using BuildingBlocks.MassTransit;
|
using BuildingBlocks.MassTransit;
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using Flight;
|
|
||||||
using Flight.Data;
|
using Flight.Data;
|
||||||
using Flight.Data.Seed;
|
using Flight.Data.Seed;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
@ -19,10 +17,11 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Respawn;
|
using Respawn;
|
||||||
|
using Serilog;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace Integration.Test;
|
namespace Integration.Test;
|
||||||
|
|
||||||
@ -37,15 +36,11 @@ public class TestFixtureCollection : ICollectionFixture<TestFixture>
|
|||||||
public class TestFixture : IAsyncLifetime
|
public class TestFixture : IAsyncLifetime
|
||||||
{
|
{
|
||||||
private Checkpoint _checkpoint;
|
private Checkpoint _checkpoint;
|
||||||
private HttpClient _client;
|
|
||||||
private IConfiguration _configuration;
|
private IConfiguration _configuration;
|
||||||
private WebApplicationFactory<Program> _factory;
|
private WebApplicationFactory<Program> _factory;
|
||||||
private ITestHarness _harness;
|
private ITestHarness _harness;
|
||||||
private IServiceScopeFactory _scopeFactory;
|
private IServiceScopeFactory _scopeFactory;
|
||||||
|
private HttpClient _httpClient;
|
||||||
public ILogger<TestFixture> Logger =>
|
|
||||||
_scopeFactory.CreateScope().ServiceProvider.GetRequiredService<ILogger<TestFixture>>();
|
|
||||||
|
|
||||||
|
|
||||||
public async Task InitializeAsync()
|
public async Task InitializeAsync()
|
||||||
{
|
{
|
||||||
@ -81,7 +76,7 @@ public class TestFixture : IAsyncLifetime
|
|||||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||||
_scopeFactory = _factory.Services.GetRequiredService<IServiceScopeFactory>();
|
_scopeFactory = _factory.Services.GetRequiredService<IServiceScopeFactory>();
|
||||||
|
|
||||||
_client = _factory.CreateClient(new WebApplicationFactoryClientOptions {AllowAutoRedirect = false});
|
_httpClient = _factory.CreateClient(new WebApplicationFactoryClientOptions {AllowAutoRedirect = false});
|
||||||
|
|
||||||
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
|
|
||||||
@ -95,6 +90,20 @@ public class TestFixture : IAsyncLifetime
|
|||||||
await _checkpoint.Reset(_configuration.GetConnectionString("DefaultConnection"));
|
await _checkpoint.Reset(_configuration.GetConnectionString("DefaultConnection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ref: https://github.com/trbenning/serilog-sinks-xunit
|
||||||
|
public ILogger CreateLogger(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
if (output != null)
|
||||||
|
{
|
||||||
|
return new LoggerConfiguration()
|
||||||
|
.WriteTo.TestOutput(output)
|
||||||
|
.CreateLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpClient CreateClient() => _httpClient;
|
||||||
|
|
||||||
public async Task ExecuteScopeAsync(Func<IServiceProvider, Task> action)
|
public async Task ExecuteScopeAsync(Func<IServiceProvider, Task> action)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user