mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-27 08:00:52 +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.Seq" Version="5.1.0" />
|
||||
<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.SwaggerGen" Version="6.2.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
|
||||
|
||||
@ -6,6 +6,7 @@ namespace BuildingBlocks.EventStoreDB;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
||||
public static IServiceCollection AddEventStore(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration,
|
||||
|
||||
@ -53,7 +53,7 @@ builder.Services.AddCustomOpenTelemetry();
|
||||
builder.Services.AddTransient<AuthHeaderHandler>();
|
||||
SnowFlakIdGenerator.Configure(3);
|
||||
|
||||
// EventStoreDB Configuration
|
||||
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
||||
builder.Services.AddEventStore(configuration, typeof(BookingRoot).Assembly)
|
||||
.AddEventStoreDBSubscriptionToAll();
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using Flight.Flights.Features.CreateFlight;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.Domain.Model;
|
||||
using BuildingBlocks.EFCore;
|
||||
using BuildingBlocks.MassTransit;
|
||||
using BuildingBlocks.Web;
|
||||
using Flight;
|
||||
using Flight.Data;
|
||||
using Flight.Data.Seed;
|
||||
using MassTransit;
|
||||
@ -19,10 +17,11 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Respawn;
|
||||
using Serilog;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Integration.Test;
|
||||
|
||||
@ -37,15 +36,11 @@ public class TestFixtureCollection : ICollectionFixture<TestFixture>
|
||||
public class TestFixture : IAsyncLifetime
|
||||
{
|
||||
private Checkpoint _checkpoint;
|
||||
private HttpClient _client;
|
||||
private IConfiguration _configuration;
|
||||
private WebApplicationFactory<Program> _factory;
|
||||
private ITestHarness _harness;
|
||||
private IServiceScopeFactory _scopeFactory;
|
||||
|
||||
public ILogger<TestFixture> Logger =>
|
||||
_scopeFactory.CreateScope().ServiceProvider.GetRequiredService<ILogger<TestFixture>>();
|
||||
|
||||
private HttpClient _httpClient;
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
@ -81,7 +76,7 @@ public class TestFixture : IAsyncLifetime
|
||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||
_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"}};
|
||||
|
||||
@ -95,6 +90,20 @@ public class TestFixture : IAsyncLifetime
|
||||
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)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user