mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-28 00:20:24 +08:00
- add test container for rabbitmq in test base
- refactor all tests
This commit is contained in:
parent
5cad00d052
commit
b4d475aebc
@ -18,11 +18,29 @@ public static class Extensions
|
|||||||
bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), out var inContainer) &&
|
bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), out var inContainer) &&
|
||||||
inContainer;
|
inContainer;
|
||||||
|
|
||||||
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services, Assembly assembly, IWebHostEnvironment env)
|
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services, Assembly assembly,
|
||||||
|
IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
if (!env.IsEnvironment("test"))
|
if (env.IsEnvironment("test"))
|
||||||
|
{
|
||||||
|
services.AddMassTransitTestHarness(configure =>
|
||||||
|
{
|
||||||
|
SetupMasstransitConfigurations(services, assembly, configure);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
services.AddMassTransit(configure =>
|
services.AddMassTransit(configure =>
|
||||||
|
{
|
||||||
|
SetupMasstransitConfigurations(services, assembly, configure);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetupMasstransitConfigurations(IServiceCollection services, Assembly assembly,
|
||||||
|
IBusRegistrationConfigurator configure)
|
||||||
{
|
{
|
||||||
configure.AddConsumers(assembly);
|
configure.AddConsumers(assembly);
|
||||||
|
|
||||||
@ -31,7 +49,7 @@ public static class Extensions
|
|||||||
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
|
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
|
||||||
var host = IsRunningInContainer ? "rabbitmq" : rabbitMqOptions.HostName;
|
var host = IsRunningInContainer ? "rabbitmq" : rabbitMqOptions.HostName;
|
||||||
|
|
||||||
configurator.Host(host, h =>
|
configurator.Host(host, rabbitMqOptions?.Port ?? 5672, "/", h =>
|
||||||
{
|
{
|
||||||
h.Username(rabbitMqOptions.UserName);
|
h.Username(rabbitMqOptions.UserName);
|
||||||
h.Password(rabbitMqOptions.Password);
|
h.Password(rabbitMqOptions.Password);
|
||||||
@ -71,9 +89,5 @@ public static class Extensions
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,4 +6,5 @@ public class RabbitMqOptions
|
|||||||
public string ExchangeName { get; set; }
|
public string ExchangeName { get; set; }
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
public ushort? Port { get; set; }
|
||||||
}
|
}
|
||||||
@ -32,9 +32,10 @@ public class IntegrationTestFixture<TEntryPoint> : IDisposable
|
|||||||
{
|
{
|
||||||
private readonly WebApplicationFactory<TEntryPoint> _factory;
|
private readonly WebApplicationFactory<TEntryPoint> _factory;
|
||||||
|
|
||||||
private int Timeout => 180;
|
|
||||||
|
private int Timeout => 60; // Second
|
||||||
|
private ITestHarness TestHarness => ServiceProvider.GetTestHarness();
|
||||||
public HttpClient HttpClient => _factory.CreateClient();
|
public HttpClient HttpClient => _factory.CreateClient();
|
||||||
public ITestHarness TestHarness => ServiceProvider.GetTestHarness();
|
|
||||||
|
|
||||||
public GrpcChannel Channel =>
|
public GrpcChannel Channel =>
|
||||||
GrpcChannel.ForAddress(HttpClient.BaseAddress!, new GrpcChannelOptions {HttpClient = HttpClient});
|
GrpcChannel.ForAddress(HttpClient.BaseAddress!, new GrpcChannelOptions {HttpClient = HttpClient});
|
||||||
@ -46,6 +47,7 @@ public class IntegrationTestFixture<TEntryPoint> : IDisposable
|
|||||||
public MsSqlTestcontainer SqlTestContainer;
|
public MsSqlTestcontainer SqlTestContainer;
|
||||||
public MsSqlTestcontainer SqlPersistTestContainer;
|
public MsSqlTestcontainer SqlPersistTestContainer;
|
||||||
public MongoDbTestcontainer MongoTestContainer;
|
public MongoDbTestcontainer MongoTestContainer;
|
||||||
|
public RabbitMqTestcontainer RabbitMqTestContainer;
|
||||||
|
|
||||||
public IntegrationTestFixture()
|
public IntegrationTestFixture()
|
||||||
{
|
{
|
||||||
@ -57,21 +59,6 @@ public class IntegrationTestFixture<TEntryPoint> : IDisposable
|
|||||||
{
|
{
|
||||||
TestRegistrationServices?.Invoke(services);
|
TestRegistrationServices?.Invoke(services);
|
||||||
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
||||||
services.AddMassTransitTestHarness(x =>
|
|
||||||
{
|
|
||||||
x.UsingRabbitMq((context, cfg) =>
|
|
||||||
{
|
|
||||||
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
|
|
||||||
var host = rabbitMqOptions.HostName;
|
|
||||||
|
|
||||||
cfg.Host(host, h =>
|
|
||||||
{
|
|
||||||
h.Username(rabbitMqOptions.UserName);
|
|
||||||
h.Password(rabbitMqOptions.Password);
|
|
||||||
});
|
|
||||||
cfg.ConfigureEndpoints(context);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -134,6 +121,36 @@ public class IntegrationTestFixture<TEntryPoint> : IDisposable
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Publish<TMessage>(TMessage message, CancellationToken cancellationToken = default)
|
||||||
|
where TMessage : class, IEvent
|
||||||
|
{
|
||||||
|
await TestHarness.Bus.Publish<TMessage>(message, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task WaitForPublishing<TMessage>(CancellationToken cancellationToken = default)
|
||||||
|
where TMessage : class, IEvent
|
||||||
|
{
|
||||||
|
await WaitUntilConditionMet(async () =>
|
||||||
|
{
|
||||||
|
var published = await TestHarness.Published.Any<TMessage>(cancellationToken);
|
||||||
|
var faulty = await TestHarness.Published.Any<Fault<TMessage>>(cancellationToken);
|
||||||
|
|
||||||
|
return published && faulty == false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task WaitForConsuming<TMessage>(CancellationToken cancellationToken = default)
|
||||||
|
where TMessage : class, IEvent
|
||||||
|
{
|
||||||
|
await WaitUntilConditionMet(async () =>
|
||||||
|
{
|
||||||
|
var consumed = await TestHarness.Consumed.Any<TMessage>(cancellationToken);
|
||||||
|
var faulty = await TestHarness.Consumed.Any<Fault<TMessage>>(cancellationToken);
|
||||||
|
|
||||||
|
return consumed && faulty == false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Ref: https://tech.energyhelpline.com/in-memory-testing-with-masstransit/
|
// Ref: https://tech.energyhelpline.com/in-memory-testing-with-masstransit/
|
||||||
public async ValueTask WaitUntilConditionMet(Func<Task<bool>> conditionToMet, int? timeoutSecond = null)
|
public async ValueTask WaitUntilConditionMet(Func<Task<bool>> conditionToMet, int? timeoutSecond = null)
|
||||||
{
|
{
|
||||||
@ -336,6 +353,9 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
|||||||
set => Fixture.ServiceProvider.GetRequiredService<IOptions<MongoOptions>>().Value.ConnectionString = value;
|
set => Fixture.ServiceProvider.GetRequiredService<IOptions<MongoOptions>>().Value.ConnectionString = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RabbitMqOptions RabbitMqOptions =>
|
||||||
|
Fixture.ServiceProvider.GetRequiredService<IOptions<RabbitMqOptions>>()?.Value;
|
||||||
|
|
||||||
public IntegrationTestFixtureCore(IntegrationTestFixture<TEntryPoint> integrationTestFixture)
|
public IntegrationTestFixtureCore(IntegrationTestFixture<TEntryPoint> integrationTestFixture)
|
||||||
{
|
{
|
||||||
Fixture = integrationTestFixture;
|
Fixture = integrationTestFixture;
|
||||||
@ -349,48 +369,66 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
|||||||
_checkpointDefaultDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpointDefaultDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
_checkpointPersistMessageDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpointPersistMessageDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
|
|
||||||
_mongoRunner = MongoDbRunner.Start();
|
|
||||||
|
|
||||||
if (MongoConnectionString != null)
|
|
||||||
MongoConnectionString = _mongoRunner.ConnectionString;
|
|
||||||
|
|
||||||
// <<For using test-container base>>
|
|
||||||
// Fixture.SqlTestContainer = TestContainers.SqlTestContainer;
|
|
||||||
// Fixture.SqlPersistTestContainer = TestContainers.SqlPersistTestContainer;
|
|
||||||
// Fixture.MongoTestContainer = TestContainers.MongoTestContainer;
|
|
||||||
//
|
|
||||||
// await Fixture.SqlTestContainer.StartAsync();
|
|
||||||
// await Fixture.SqlPersistTestContainer.StartAsync();
|
|
||||||
// await Fixture.MongoTestContainer.StartAsync();
|
|
||||||
//
|
|
||||||
// DefaultConnectionString = Fixture.SqlTestContainer?.ConnectionString;
|
|
||||||
// PersistConnectionString = Fixture.SqlPersistTestContainer?.ConnectionString;
|
|
||||||
// MongoConnectionString = Fixture.MongoTestContainer?.ConnectionString;
|
|
||||||
|
|
||||||
await SeedDataAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task DisposeAsync()
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(DefaultConnectionString))
|
if (!string.IsNullOrEmpty(DefaultConnectionString))
|
||||||
await _checkpointDefaultDB.Reset(DefaultConnectionString);
|
await _checkpointDefaultDB.Reset(DefaultConnectionString);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(PersistConnectionString))
|
if (!string.IsNullOrEmpty(PersistConnectionString))
|
||||||
await _checkpointPersistMessageDB.Reset(PersistConnectionString);
|
await _checkpointPersistMessageDB.Reset(PersistConnectionString);
|
||||||
|
|
||||||
|
_mongoRunner = MongoDbRunner.Start();
|
||||||
|
|
||||||
|
if (MongoConnectionString != null)
|
||||||
|
MongoConnectionString = _mongoRunner.ConnectionString;
|
||||||
|
|
||||||
|
//await StartTestContainerAsync();
|
||||||
|
|
||||||
|
await SeedDataAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DisposeAsync()
|
||||||
|
{
|
||||||
if (!string.IsNullOrEmpty(PersistConnectionString))
|
if (!string.IsNullOrEmpty(PersistConnectionString))
|
||||||
_mongoRunner.Dispose();
|
_mongoRunner.Dispose();
|
||||||
|
|
||||||
// <<For using test-container base>>
|
//await StopTestContainerAsync();
|
||||||
// await Fixture.SqlTestContainer.StopAsync();
|
|
||||||
// await Fixture.SqlPersistTestContainer.StopAsync();
|
|
||||||
// await Fixture.MongoTestContainer.StopAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RegisterTestsServices(IServiceCollection services)
|
protected virtual void RegisterTestsServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task StartTestContainerAsync()
|
||||||
|
{
|
||||||
|
// <<For using test-container base>>
|
||||||
|
Fixture.SqlTestContainer = TestContainers.SqlTestContainer;
|
||||||
|
Fixture.SqlPersistTestContainer = TestContainers.SqlPersistTestContainer;
|
||||||
|
Fixture.MongoTestContainer = TestContainers.MongoTestContainer;
|
||||||
|
Fixture.RabbitMqTestContainer = TestContainers.RabbitMqTestContainer;
|
||||||
|
|
||||||
|
await Fixture.SqlTestContainer.StartAsync();
|
||||||
|
await Fixture.SqlPersistTestContainer.StartAsync();
|
||||||
|
await Fixture.MongoTestContainer.StartAsync();
|
||||||
|
await Fixture.RabbitMqTestContainer.StartAsync();
|
||||||
|
|
||||||
|
DefaultConnectionString = Fixture.SqlTestContainer?.ConnectionString;
|
||||||
|
PersistConnectionString = Fixture.SqlPersistTestContainer?.ConnectionString;
|
||||||
|
MongoConnectionString = Fixture.MongoTestContainer?.ConnectionString;
|
||||||
|
|
||||||
|
RabbitMqOptions.Password = Fixture.RabbitMqTestContainer.Password;
|
||||||
|
RabbitMqOptions.UserName = Fixture.RabbitMqTestContainer.Username;
|
||||||
|
RabbitMqOptions.HostName = Fixture.RabbitMqTestContainer.Hostname;
|
||||||
|
RabbitMqOptions.Port = (ushort)Fixture.RabbitMqTestContainer.Port;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task StopTestContainerAsync()
|
||||||
|
{
|
||||||
|
// <<For using test-container base>>
|
||||||
|
await Fixture.SqlTestContainer.StopAsync();
|
||||||
|
await Fixture.SqlPersistTestContainer.StopAsync();
|
||||||
|
await Fixture.MongoTestContainer.StopAsync();
|
||||||
|
await Fixture.RabbitMqTestContainer.StopAsync();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SeedDataAsync()
|
private async Task SeedDataAsync()
|
||||||
{
|
{
|
||||||
using var scope = Fixture.ServiceProvider.CreateScope();
|
using var scope = Fixture.ServiceProvider.CreateScope();
|
||||||
|
|||||||
@ -10,7 +10,8 @@ public static class TestContainers
|
|||||||
.WithDatabase(
|
.WithDatabase(
|
||||||
new MsSqlTestcontainerConfiguration
|
new MsSqlTestcontainerConfiguration
|
||||||
{
|
{
|
||||||
Database = Guid.NewGuid().ToString("D"), Password = Guid.NewGuid().ToString("D")
|
Database = Guid.NewGuid().ToString("D"),
|
||||||
|
Password = Guid.NewGuid().ToString("D")
|
||||||
})
|
})
|
||||||
.WithImage("mcr.microsoft.com/mssql/server:2017-latest")
|
.WithImage("mcr.microsoft.com/mssql/server:2017-latest")
|
||||||
.Build();
|
.Build();
|
||||||
@ -32,4 +33,13 @@ public static class TestContainers
|
|||||||
})
|
})
|
||||||
.WithImage("mongo")
|
.WithImage("mongo")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
public static RabbitMqTestcontainer RabbitMqTestContainer => new TestcontainersBuilder<RabbitMqTestcontainer>()
|
||||||
|
.WithMessageBroker(new RabbitMqTestcontainerConfiguration()
|
||||||
|
{
|
||||||
|
Password = "guest",
|
||||||
|
Username = "guest"
|
||||||
|
})
|
||||||
|
.WithImage("rabbitmq:3-management")
|
||||||
|
.Build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,8 @@
|
|||||||
"HostName": "rabbitmq",
|
"HostName": "rabbitmq",
|
||||||
"ExchangeName": "booking",
|
"ExchangeName": "booking",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Grpc": {
|
"Grpc": {
|
||||||
"FlightAddress": "https://localhost:5003",
|
"FlightAddress": "https://localhost:5003",
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "booking",
|
"ExchangeName": "booking",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Grpc": {
|
"Grpc": {
|
||||||
"FlightAddress": "https://localhost:5003",
|
"FlightAddress": "https://localhost:5003",
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "booking",
|
"ExchangeName": "booking",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
@ -24,13 +24,10 @@ namespace Integration.Test.Booking.Features;
|
|||||||
|
|
||||||
public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbContext, BookingReadDbContext>
|
public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbContext, BookingReadDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
|
||||||
|
|
||||||
public CreateBookingTests(
|
public CreateBookingTests(
|
||||||
IntegrationTestFixture<Program, PersistMessageDbContext, BookingReadDbContext> integrationTestFixture) : base(
|
IntegrationTestFixture<Program, PersistMessageDbContext, BookingReadDbContext> integrationTestFixture) : base(
|
||||||
integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void RegisterTestsServices(IServiceCollection services)
|
protected override void RegisterTestsServices(IServiceCollection services)
|
||||||
@ -51,8 +48,8 @@ public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbC
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.Should().BeGreaterOrEqualTo(0);
|
response.Should().BeGreaterOrEqualTo(0);
|
||||||
(await _testHarness.Published.Any<Fault<BookingCreated>>()).Should().BeFalse();
|
|
||||||
(await _testHarness.Published.Any<BookingCreated>()).Should().BeTrue();
|
await Fixture.WaitForPublishing<BookingCreated>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,8 @@
|
|||||||
"HostName": "rabbitmq",
|
"HostName": "rabbitmq",
|
||||||
"ExchangeName": "flight",
|
"ExchangeName": "flight",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "flight",
|
"ExchangeName": "flight",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"PersistMessageOptions": {
|
"PersistMessageOptions": {
|
||||||
"Interval": 30,
|
"Interval": 30,
|
||||||
|
|||||||
@ -6,7 +6,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "flight",
|
"ExchangeName": "flight",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||||
|
using MassTransit;
|
||||||
|
|
||||||
|
namespace Flight;
|
||||||
|
|
||||||
|
public class CreateFlightConsumerHandler : IConsumer<FlightCreated>
|
||||||
|
{
|
||||||
|
public Task Consume(ConsumeContext<FlightCreated> context)
|
||||||
|
{
|
||||||
|
Console.WriteLine("It's for test");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,8 +40,6 @@ public class CreateFlightCommandHandler : ICommandHandler<CreateFlightCommand, F
|
|||||||
|
|
||||||
var newFlight = await _flightDbContext.Flights.AddAsync(flightEntity, cancellationToken);
|
var newFlight = await _flightDbContext.Flights.AddAsync(flightEntity, cancellationToken);
|
||||||
|
|
||||||
var f = _mapper.Map<FlightResponseDto>(newFlight.Entity);
|
return _mapper.Map<FlightResponseDto>(newFlight.Entity);
|
||||||
|
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,9 @@ public class FlightMappings : IRegister
|
|||||||
.Map(d => d.Id, s => SnowFlakIdGenerator.NewId())
|
.Map(d => d.Id, s => SnowFlakIdGenerator.NewId())
|
||||||
.Map(d => d.FlightId, s => s.Id);
|
.Map(d => d.FlightId, s => s.Id);
|
||||||
|
|
||||||
|
config.NewConfig<FlightReadModel, FlightResponseDto>()
|
||||||
|
.Map(d => d.Id, s => s.FlightId);
|
||||||
|
|
||||||
config.NewConfig<UpdateFlightMongoCommand, FlightReadModel>()
|
config.NewConfig<UpdateFlightMongoCommand, FlightReadModel>()
|
||||||
.Map(d => d.FlightId, s => s.Id);
|
.Map(d => d.FlightId, s => s.Id);
|
||||||
|
|
||||||
|
|||||||
@ -6,19 +6,16 @@ using Flight.Api;
|
|||||||
using Flight.Data;
|
using Flight.Data;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Integration.Test.Fakes;
|
using Integration.Test.Fakes;
|
||||||
using MassTransit;
|
|
||||||
using MassTransit.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Aircraft.Features;
|
namespace Integration.Test.Aircraft.Features;
|
||||||
|
|
||||||
public class CreateAircraftTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
public class CreateAircraftTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
public CreateAircraftTests(
|
||||||
|
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||||
public CreateAircraftTests(IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -33,8 +30,8 @@ public class CreateAircraftTests : IntegrationTestBase<Program, FlightDbContext,
|
|||||||
// Assert
|
// Assert
|
||||||
response?.Should().NotBeNull();
|
response?.Should().NotBeNull();
|
||||||
response?.Name.Should().Be(command.Name);
|
response?.Name.Should().Be(command.Name);
|
||||||
(await _testHarness.Published.Any<Fault<AircraftCreated>>()).Should().BeFalse();
|
|
||||||
(await _testHarness.Published.Any<AircraftCreated>()).Should().BeTrue();
|
await Fixture.WaitForPublishing<AircraftCreated>();
|
||||||
|
|
||||||
await Fixture.ShouldProcessedPersistInternalCommand<CreateAircraftMongoCommand>();
|
await Fixture.ShouldProcessedPersistInternalCommand<CreateAircraftMongoCommand>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,21 +6,16 @@ using Flight.Api;
|
|||||||
using Flight.Data;
|
using Flight.Data;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Integration.Test.Fakes;
|
using Integration.Test.Fakes;
|
||||||
using MassTransit;
|
|
||||||
using MassTransit.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Airport.Features;
|
namespace Integration.Test.Airport.Features;
|
||||||
|
|
||||||
public class CreateAirportTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
public class CreateAirportTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
|
||||||
|
|
||||||
public CreateAirportTests(
|
public CreateAirportTests(
|
||||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||||
integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -35,8 +30,8 @@ public class CreateAirportTests : IntegrationTestBase<Program, FlightDbContext,
|
|||||||
// Assert
|
// Assert
|
||||||
response?.Should().NotBeNull();
|
response?.Should().NotBeNull();
|
||||||
response?.Name.Should().Be(command.Name);
|
response?.Name.Should().Be(command.Name);
|
||||||
(await _testHarness.Published.Any<Fault<AirportCreated>>()).Should().BeFalse();
|
|
||||||
(await _testHarness.Published.Any<AirportCreated>()).Should().BeTrue();
|
await Fixture.WaitForPublishing<AirportCreated>();
|
||||||
|
|
||||||
await Fixture.ShouldProcessedPersistInternalCommand<CreateAirportMongoCommand>();
|
await Fixture.ShouldProcessedPersistInternalCommand<CreateAirportMongoCommand>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,22 +6,16 @@ using Flight.Data;
|
|||||||
using Flight.Flights.Features.CreateFlight.Commands.V1.Reads;
|
using Flight.Flights.Features.CreateFlight.Commands.V1.Reads;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Integration.Test.Fakes;
|
using Integration.Test.Fakes;
|
||||||
using MassTransit;
|
|
||||||
using MassTransit.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
|
||||||
public class CreateFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
public class CreateFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
|
||||||
|
|
||||||
public CreateFlightTests(
|
public CreateFlightTests(
|
||||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||||
integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{ }
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task should_create_new_flight_to_db_and_publish_message_to_broker()
|
public async Task should_create_new_flight_to_db_and_publish_message_to_broker()
|
||||||
@ -36,8 +30,8 @@ public class CreateFlightTests : IntegrationTestBase<Program, FlightDbContext, F
|
|||||||
response.Should().NotBeNull();
|
response.Should().NotBeNull();
|
||||||
response?.FlightNumber.Should().Be(command.FlightNumber);
|
response?.FlightNumber.Should().Be(command.FlightNumber);
|
||||||
|
|
||||||
(await _testHarness.Published.Any<Fault<FlightCreated>>()).Should().BeFalse();
|
await Fixture.WaitForPublishing<FlightCreated>();
|
||||||
(await _testHarness.Published.Any<FlightCreated>()).Should().BeTrue();
|
await Fixture.WaitForConsuming<FlightCreated>();
|
||||||
|
|
||||||
await Fixture.ShouldProcessedPersistInternalCommand<CreateFlightMongoCommand>();
|
await Fixture.ShouldProcessedPersistInternalCommand<CreateFlightMongoCommand>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,9 @@ using BuildingBlocks.Contracts.EventBus.Messages;
|
|||||||
using BuildingBlocks.TestBase;
|
using BuildingBlocks.TestBase;
|
||||||
using Flight.Api;
|
using Flight.Api;
|
||||||
using Flight.Data;
|
using Flight.Data;
|
||||||
using Flight.Flights.Features.DeleteFlight;
|
|
||||||
using Flight.Flights.Features.DeleteFlight.Commands.V1;
|
using Flight.Flights.Features.DeleteFlight.Commands.V1;
|
||||||
using Flight.Flights.Features.DeleteFlight.Commands.V1.Reads;
|
using Flight.Flights.Features.DeleteFlight.Commands.V1.Reads;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using MassTransit;
|
|
||||||
using MassTransit.Testing;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -17,13 +14,10 @@ namespace Integration.Test.Flight.Features;
|
|||||||
|
|
||||||
public class DeleteFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
public class DeleteFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
|
||||||
|
|
||||||
public DeleteFlightTests(
|
public DeleteFlightTests(
|
||||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||||
integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -43,8 +37,9 @@ public class DeleteFlightTests : IntegrationTestBase<Program, FlightDbContext, F
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
deletedFlight?.IsDeleted.Should().BeTrue();
|
deletedFlight?.IsDeleted.Should().BeTrue();
|
||||||
(await _testHarness.Published.Any<Fault<FlightDeleted>>()).Should().BeFalse();
|
|
||||||
(await _testHarness.Published.Any<FlightDeleted>()).Should().BeTrue();
|
await Fixture.WaitForPublishing<FlightDeleted>();
|
||||||
|
|
||||||
await Fixture.ShouldProcessedPersistInternalCommand<DeleteFlightMongoCommand>();
|
await Fixture.ShouldProcessedPersistInternalCommand<DeleteFlightMongoCommand>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,6 @@ public class GetFlightByIdTests : IntegrationTestBase<Program, FlightDbContext,
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response?.Should().NotBeNull();
|
response?.Should().NotBeNull();
|
||||||
response?.FlightId.Should().Be(command.Id);
|
response?.Id.Should().Be(command.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,21 +6,18 @@ using Flight.Data;
|
|||||||
using Flight.Flights.Features.UpdateFlight.Commands.V1.Reads;
|
using Flight.Flights.Features.UpdateFlight.Commands.V1.Reads;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Integration.Test.Fakes;
|
using Integration.Test.Fakes;
|
||||||
using MassTransit;
|
|
||||||
using MassTransit.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
|
||||||
public class UpdateFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
public class UpdateFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
public UpdateFlightTests(
|
||||||
|
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||||
public UpdateFlightTests(IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task should_update_flight_to_db_and_publish_message_to_broker()
|
public async Task should_update_flight_to_db_and_publish_message_to_broker()
|
||||||
{
|
{
|
||||||
@ -35,8 +32,9 @@ public class UpdateFlightTests : IntegrationTestBase<Program, FlightDbContext, F
|
|||||||
response.Should().NotBeNull();
|
response.Should().NotBeNull();
|
||||||
response?.Id.Should().Be(flightEntity?.Id);
|
response?.Id.Should().Be(flightEntity?.Id);
|
||||||
response?.Price.Should().NotBe(flightEntity?.Price);
|
response?.Price.Should().NotBe(flightEntity?.Price);
|
||||||
(await _testHarness.Published.Any<Fault<FlightUpdated>>()).Should().BeFalse();
|
|
||||||
(await _testHarness.Published.Any<FlightUpdated>()).Should().BeTrue();
|
await Fixture.WaitForPublishing<FlightUpdated>();
|
||||||
|
|
||||||
await Fixture.ShouldProcessedPersistInternalCommand<UpdateFlightMongoCommand>();
|
await Fixture.ShouldProcessedPersistInternalCommand<UpdateFlightMongoCommand>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
"HostName": "rabbitmq",
|
"HostName": "rabbitmq",
|
||||||
"ExchangeName": "identity",
|
"ExchangeName": "identity",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "identity",
|
"ExchangeName": "identity",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Authority": "https://localhost:5005",
|
"Authority": "https://localhost:5005",
|
||||||
|
|||||||
@ -6,7 +6,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "identity",
|
"ExchangeName": "identity",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
@ -13,11 +13,9 @@ namespace Integration.Test.Identity.Features;
|
|||||||
|
|
||||||
public class RegisterNewUserTests : IntegrationTestBase<Program, IdentityContext>
|
public class RegisterNewUserTests : IntegrationTestBase<Program, IdentityContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
public RegisterNewUserTests(IntegrationTestFixture<Program, IdentityContext> integrationTestFixture) : base(
|
||||||
|
integrationTestFixture)
|
||||||
public RegisterNewUserTests(IntegrationTestFixture<Program, IdentityContext> integrationTestFixture) : base(integrationTestFixture)
|
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -32,7 +30,7 @@ public class RegisterNewUserTests : IntegrationTestBase<Program, IdentityContext
|
|||||||
// Assert
|
// Assert
|
||||||
response?.Should().NotBeNull();
|
response?.Should().NotBeNull();
|
||||||
response?.Username.Should().Be(command.Username);
|
response?.Username.Should().Be(command.Username);
|
||||||
(await _testHarness.Published.Any<Fault<UserCreated>>()).Should().BeFalse();
|
|
||||||
(await _testHarness.Published.Any<UserCreated>()).Should().BeTrue();
|
await Fixture.WaitForPublishing<UserCreated>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,8 @@
|
|||||||
"HostName": "rabbitmq",
|
"HostName": "rabbitmq",
|
||||||
"ExchangeName": "passenger",
|
"ExchangeName": "passenger",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "passenger",
|
"ExchangeName": "passenger",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"LogOptions": {
|
"LogOptions": {
|
||||||
"Level": "information",
|
"Level": "information",
|
||||||
|
|||||||
@ -6,7 +6,8 @@
|
|||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
"ExchangeName": "passenger",
|
"ExchangeName": "passenger",
|
||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest",
|
||||||
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
@ -6,18 +6,16 @@ using Integration.Test.Fakes;
|
|||||||
using MassTransit.Testing;
|
using MassTransit.Testing;
|
||||||
using Passenger.Api;
|
using Passenger.Api;
|
||||||
using Passenger.Data;
|
using Passenger.Data;
|
||||||
|
using Passenger.Passengers.Features.CompleteRegisterPassenger.Commands.V1.Reads;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Passenger.Features;
|
namespace Integration.Test.Passenger.Features;
|
||||||
|
|
||||||
public class CompleteRegisterPassengerTests : IntegrationTestBase<Program, PassengerDbContext>
|
public class CompleteRegisterPassengerTests : IntegrationTestBase<Program, PassengerDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
|
||||||
|
|
||||||
public CompleteRegisterPassengerTests(IntegrationTestFixture<Program, PassengerDbContext> integrationTestFixture) :
|
public CompleteRegisterPassengerTests(IntegrationTestFixture<Program, PassengerDbContext> integrationTestFixture) :
|
||||||
base(integrationTestFixture)
|
base(integrationTestFixture)
|
||||||
{
|
{
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -25,9 +23,10 @@ public class CompleteRegisterPassengerTests : IntegrationTestBase<Program, Passe
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var userCreated = new FakeUserCreated().Generate();
|
var userCreated = new FakeUserCreated().Generate();
|
||||||
await _testHarness.Bus.Publish(userCreated);
|
|
||||||
await _testHarness.Consumed.Any<UserCreated>();
|
await Fixture.Publish(userCreated);
|
||||||
await Fixture.InsertAsync(FakePassengerCreated.Generate(userCreated));
|
await Fixture.WaitForPublishing<UserCreated>();
|
||||||
|
await Fixture.WaitForConsuming<UserCreated>();
|
||||||
|
|
||||||
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
|
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
|
||||||
|
|
||||||
|
|||||||
@ -16,18 +16,12 @@ namespace Integration.Test.Passenger.Features;
|
|||||||
|
|
||||||
public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbContext>
|
public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbContext>
|
||||||
{
|
{
|
||||||
private readonly ITestHarness _testHarness;
|
|
||||||
private readonly GrpcChannel _channel;
|
private readonly GrpcChannel _channel;
|
||||||
|
|
||||||
public GetPassengerByIdTests(IntegrationTestFixture<Program, PassengerDbContext> integrationTestFixture) : base(
|
public GetPassengerByIdTests(IntegrationTestFixture<Program, PassengerDbContext> integrationTestFixture) : base(
|
||||||
integrationTestFixture)
|
integrationTestFixture)
|
||||||
{
|
{
|
||||||
_channel = Fixture.Channel;
|
_channel = Fixture.Channel;
|
||||||
_testHarness = Fixture.TestHarness;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void RegisterTestsServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -36,8 +30,7 @@ public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbCon
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var userCreated = new FakeUserCreated().Generate();
|
var userCreated = new FakeUserCreated().Generate();
|
||||||
await _testHarness.Bus.Publish(userCreated);
|
|
||||||
await _testHarness.Consumed.Any<UserCreated>();
|
|
||||||
var passengerEntity = FakePassengerCreated.Generate(userCreated);
|
var passengerEntity = FakePassengerCreated.Generate(userCreated);
|
||||||
await Fixture.InsertAsync(passengerEntity);
|
await Fixture.InsertAsync(passengerEntity);
|
||||||
|
|
||||||
@ -56,8 +49,7 @@ public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbCon
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var userCreated = new FakeUserCreated().Generate();
|
var userCreated = new FakeUserCreated().Generate();
|
||||||
await _testHarness.Bus.Publish(userCreated);
|
|
||||||
await _testHarness.Consumed.Any<UserCreated>();
|
|
||||||
var passengerEntity = FakePassengerCreated.Generate(userCreated);
|
var passengerEntity = FakePassengerCreated.Generate(userCreated);
|
||||||
await Fixture.InsertAsync(passengerEntity);
|
await Fixture.InsertAsync(passengerEntity);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user