mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-16 16:10:34 +08:00
Merge pull request #65 from meysamhadeli/develop
- add test container for RabbitMq in test base
This commit is contained in:
commit
68bb28d715
@ -18,62 +18,76 @@ public static class Extensions
|
||||
bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), out var 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 =>
|
||||
{
|
||||
configure.AddConsumers(assembly);
|
||||
|
||||
configure.UsingRabbitMq((context, configurator) =>
|
||||
{
|
||||
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
|
||||
var host = IsRunningInContainer ? "rabbitmq" : rabbitMqOptions.HostName;
|
||||
|
||||
configurator.Host(host, h =>
|
||||
{
|
||||
h.Username(rabbitMqOptions.UserName);
|
||||
h.Password(rabbitMqOptions.Password);
|
||||
});
|
||||
|
||||
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
|
||||
.Where(x => x.IsAssignableTo(typeof(IIntegrationEvent))
|
||||
&& !x.IsInterface
|
||||
&& !x.IsAbstract
|
||||
&& !x.IsGenericType);
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var consumers = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
|
||||
.Where(x => x.IsAssignableTo(typeof(IConsumer<>).MakeGenericType(type))).ToList();
|
||||
|
||||
if (consumers.Any())
|
||||
configurator.ReceiveEndpoint(
|
||||
string.IsNullOrEmpty(rabbitMqOptions.ExchangeName)
|
||||
? type.Name.Underscore()
|
||||
: $"{rabbitMqOptions.ExchangeName}_{type.Name.Underscore()}", e =>
|
||||
{
|
||||
e.UseConsumeFilter(typeof(ConsumeFilter<>), context); //generic filter
|
||||
|
||||
foreach (var consumer in consumers)
|
||||
{
|
||||
configurator.ConfigureEndpoints(context, x => x.Exclude(consumer));
|
||||
var methodInfo = typeof(DependencyInjectionReceiveEndpointExtensions)
|
||||
.GetMethods()
|
||||
.Where(x => x.GetParameters()
|
||||
.Any(p => p.ParameterType == typeof(IServiceProvider)))
|
||||
.FirstOrDefault(x => x.Name == "Consumer" && x.IsGenericMethod);
|
||||
|
||||
var generic = methodInfo?.MakeGenericMethod(consumer);
|
||||
generic?.Invoke(e, new object[] {e, context, null});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
SetupMasstransitConfigurations(services, assembly, configure);
|
||||
});
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static void SetupMasstransitConfigurations(IServiceCollection services, Assembly assembly,
|
||||
IBusRegistrationConfigurator configure)
|
||||
{
|
||||
configure.AddConsumers(assembly);
|
||||
|
||||
configure.UsingRabbitMq((context, configurator) =>
|
||||
{
|
||||
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
|
||||
var host = IsRunningInContainer ? "rabbitmq" : rabbitMqOptions.HostName;
|
||||
|
||||
configurator.Host(host, rabbitMqOptions?.Port ?? 5672, "/", h =>
|
||||
{
|
||||
h.Username(rabbitMqOptions.UserName);
|
||||
h.Password(rabbitMqOptions.Password);
|
||||
});
|
||||
|
||||
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
|
||||
.Where(x => x.IsAssignableTo(typeof(IIntegrationEvent))
|
||||
&& !x.IsInterface
|
||||
&& !x.IsAbstract
|
||||
&& !x.IsGenericType);
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var consumers = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
|
||||
.Where(x => x.IsAssignableTo(typeof(IConsumer<>).MakeGenericType(type))).ToList();
|
||||
|
||||
if (consumers.Any())
|
||||
configurator.ReceiveEndpoint(
|
||||
string.IsNullOrEmpty(rabbitMqOptions.ExchangeName)
|
||||
? type.Name.Underscore()
|
||||
: $"{rabbitMqOptions.ExchangeName}_{type.Name.Underscore()}", e =>
|
||||
{
|
||||
e.UseConsumeFilter(typeof(ConsumeFilter<>), context); //generic filter
|
||||
|
||||
foreach (var consumer in consumers)
|
||||
{
|
||||
configurator.ConfigureEndpoints(context, x => x.Exclude(consumer));
|
||||
var methodInfo = typeof(DependencyInjectionReceiveEndpointExtensions)
|
||||
.GetMethods()
|
||||
.Where(x => x.GetParameters()
|
||||
.Any(p => p.ParameterType == typeof(IServiceProvider)))
|
||||
.FirstOrDefault(x => x.Name == "Consumer" && x.IsGenericMethod);
|
||||
|
||||
var generic = methodInfo?.MakeGenericMethod(consumer);
|
||||
generic?.Invoke(e, new object[] {e, context, null});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,4 +6,5 @@ public class RabbitMqOptions
|
||||
public string ExchangeName { get; set; }
|
||||
public string UserName { 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 int Timeout => 180;
|
||||
|
||||
private int Timeout => 60; // Second
|
||||
private ITestHarness TestHarness => ServiceProvider.GetTestHarness();
|
||||
public HttpClient HttpClient => _factory.CreateClient();
|
||||
public ITestHarness TestHarness => ServiceProvider.GetTestHarness();
|
||||
|
||||
public GrpcChannel Channel =>
|
||||
GrpcChannel.ForAddress(HttpClient.BaseAddress!, new GrpcChannelOptions {HttpClient = HttpClient});
|
||||
@ -46,6 +47,7 @@ public class IntegrationTestFixture<TEntryPoint> : IDisposable
|
||||
public MsSqlTestcontainer SqlTestContainer;
|
||||
public MsSqlTestcontainer SqlPersistTestContainer;
|
||||
public MongoDbTestcontainer MongoTestContainer;
|
||||
public RabbitMqTestcontainer RabbitMqTestContainer;
|
||||
|
||||
public IntegrationTestFixture()
|
||||
{
|
||||
@ -57,21 +59,6 @@ public class IntegrationTestFixture<TEntryPoint> : IDisposable
|
||||
{
|
||||
TestRegistrationServices?.Invoke(services);
|
||||
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/
|
||||
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;
|
||||
}
|
||||
|
||||
private RabbitMqOptions RabbitMqOptions =>
|
||||
Fixture.ServiceProvider.GetRequiredService<IOptions<RabbitMqOptions>>()?.Value;
|
||||
|
||||
public IntegrationTestFixtureCore(IntegrationTestFixture<TEntryPoint> integrationTestFixture)
|
||||
{
|
||||
Fixture = integrationTestFixture;
|
||||
@ -349,48 +369,66 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
||||
_checkpointDefaultDB = 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))
|
||||
await _checkpointDefaultDB.Reset(DefaultConnectionString);
|
||||
|
||||
if (!string.IsNullOrEmpty(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))
|
||||
_mongoRunner.Dispose();
|
||||
|
||||
// <<For using test-container base>>
|
||||
// await Fixture.SqlTestContainer.StopAsync();
|
||||
// await Fixture.SqlPersistTestContainer.StopAsync();
|
||||
// await Fixture.MongoTestContainer.StopAsync();
|
||||
//await StopTestContainerAsync();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
using var scope = Fixture.ServiceProvider.CreateScope();
|
||||
|
||||
@ -10,7 +10,8 @@ public static class TestContainers
|
||||
.WithDatabase(
|
||||
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")
|
||||
.Build();
|
||||
@ -32,4 +33,13 @@ public static class TestContainers
|
||||
})
|
||||
.WithImage("mongo")
|
||||
.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",
|
||||
"ExchangeName": "booking",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Grpc": {
|
||||
"FlightAddress": "https://localhost:5003",
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "booking",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Grpc": {
|
||||
"FlightAddress": "https://localhost:5003",
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "booking",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
@ -24,13 +24,10 @@ namespace Integration.Test.Booking.Features;
|
||||
|
||||
public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbContext, BookingReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public CreateBookingTests(
|
||||
IntegrationTestFixture<Program, PersistMessageDbContext, BookingReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
protected override void RegisterTestsServices(IServiceCollection services)
|
||||
@ -51,8 +48,8 @@ public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbC
|
||||
|
||||
// Assert
|
||||
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",
|
||||
"ExchangeName": "flight",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
@ -30,7 +30,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "flight",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"PersistMessageOptions": {
|
||||
"Interval": 30,
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "flight",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Logging": {
|
||||
"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 f = _mapper.Map<FlightResponseDto>(newFlight.Entity);
|
||||
|
||||
return f;
|
||||
return _mapper.Map<FlightResponseDto>(newFlight.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,9 @@ public class FlightMappings : IRegister
|
||||
.Map(d => d.Id, s => SnowFlakIdGenerator.NewId())
|
||||
.Map(d => d.FlightId, s => s.Id);
|
||||
|
||||
config.NewConfig<FlightReadModel, FlightResponseDto>()
|
||||
.Map(d => d.Id, s => s.FlightId);
|
||||
|
||||
config.NewConfig<UpdateFlightMongoCommand, FlightReadModel>()
|
||||
.Map(d => d.FlightId, s => s.Id);
|
||||
|
||||
|
||||
@ -6,19 +6,16 @@ using Flight.Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Aircraft.Features;
|
||||
|
||||
public class CreateAircraftTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public CreateAircraftTests(IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(integrationTestFixture)
|
||||
public CreateAircraftTests(
|
||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -33,8 +30,8 @@ public class CreateAircraftTests : IntegrationTestBase<Program, FlightDbContext,
|
||||
// Assert
|
||||
response?.Should().NotBeNull();
|
||||
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>();
|
||||
}
|
||||
|
||||
@ -6,21 +6,16 @@ using Flight.Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Airport.Features;
|
||||
|
||||
public class CreateAirportTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public CreateAirportTests(
|
||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -35,8 +30,8 @@ public class CreateAirportTests : IntegrationTestBase<Program, FlightDbContext,
|
||||
// Assert
|
||||
response?.Should().NotBeNull();
|
||||
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>();
|
||||
}
|
||||
|
||||
@ -6,22 +6,16 @@ using Flight.Data;
|
||||
using Flight.Flights.Features.CreateFlight.Commands.V1.Reads;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
public class CreateFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public CreateFlightTests(
|
||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
{ }
|
||||
|
||||
[Fact]
|
||||
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?.FlightNumber.Should().Be(command.FlightNumber);
|
||||
|
||||
(await _testHarness.Published.Any<Fault<FlightCreated>>()).Should().BeFalse();
|
||||
(await _testHarness.Published.Any<FlightCreated>()).Should().BeTrue();
|
||||
await Fixture.WaitForPublishing<FlightCreated>();
|
||||
await Fixture.WaitForConsuming<FlightCreated>();
|
||||
|
||||
await Fixture.ShouldProcessedPersistInternalCommand<CreateFlightMongoCommand>();
|
||||
}
|
||||
|
||||
@ -4,12 +4,9 @@ using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Flight.Api;
|
||||
using Flight.Data;
|
||||
using Flight.Flights.Features.DeleteFlight;
|
||||
using Flight.Flights.Features.DeleteFlight.Commands.V1;
|
||||
using Flight.Flights.Features.DeleteFlight.Commands.V1.Reads;
|
||||
using FluentAssertions;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
|
||||
@ -17,13 +14,10 @@ namespace Integration.Test.Flight.Features;
|
||||
|
||||
public class DeleteFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public DeleteFlightTests(
|
||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -43,8 +37,9 @@ public class DeleteFlightTests : IntegrationTestBase<Program, FlightDbContext, F
|
||||
|
||||
// Assert
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +58,6 @@ public class GetFlightByIdTests : IntegrationTestBase<Program, FlightDbContext,
|
||||
|
||||
// Assert
|
||||
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 FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
public class UpdateFlightTests : IntegrationTestBase<Program, FlightDbContext, FlightReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public UpdateFlightTests(IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(integrationTestFixture)
|
||||
public UpdateFlightTests(
|
||||
IntegrationTestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
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?.Id.Should().Be(flightEntity?.Id);
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
"HostName": "rabbitmq",
|
||||
"ExchangeName": "identity",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "identity",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "https://localhost:5005",
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "identity",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
@ -13,11 +13,9 @@ namespace Integration.Test.Identity.Features;
|
||||
|
||||
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]
|
||||
@ -32,7 +30,7 @@ public class RegisterNewUserTests : IntegrationTestBase<Program, IdentityContext
|
||||
// Assert
|
||||
response?.Should().NotBeNull();
|
||||
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",
|
||||
"ExchangeName": "passenger",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "passenger",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"LogOptions": {
|
||||
"Level": "information",
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "passenger",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
@ -6,18 +6,16 @@ using Integration.Test.Fakes;
|
||||
using MassTransit.Testing;
|
||||
using Passenger.Api;
|
||||
using Passenger.Data;
|
||||
using Passenger.Passengers.Features.CompleteRegisterPassenger.Commands.V1.Reads;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Passenger.Features;
|
||||
|
||||
public class CompleteRegisterPassengerTests : IntegrationTestBase<Program, PassengerDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public CompleteRegisterPassengerTests(IntegrationTestFixture<Program, PassengerDbContext> integrationTestFixture) :
|
||||
base(integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -25,9 +23,10 @@ public class CompleteRegisterPassengerTests : IntegrationTestBase<Program, Passe
|
||||
{
|
||||
// Arrange
|
||||
var userCreated = new FakeUserCreated().Generate();
|
||||
await _testHarness.Bus.Publish(userCreated);
|
||||
await _testHarness.Consumed.Any<UserCreated>();
|
||||
await Fixture.InsertAsync(FakePassengerCreated.Generate(userCreated));
|
||||
|
||||
await Fixture.Publish(userCreated);
|
||||
await Fixture.WaitForPublishing<UserCreated>();
|
||||
await Fixture.WaitForConsuming<UserCreated>();
|
||||
|
||||
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
|
||||
|
||||
|
||||
@ -16,18 +16,12 @@ namespace Integration.Test.Passenger.Features;
|
||||
|
||||
public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
private readonly GrpcChannel _channel;
|
||||
|
||||
public GetPassengerByIdTests(IntegrationTestFixture<Program, PassengerDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_channel = Fixture.Channel;
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
protected override void RegisterTestsServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -36,8 +30,7 @@ public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbCon
|
||||
{
|
||||
// Arrange
|
||||
var userCreated = new FakeUserCreated().Generate();
|
||||
await _testHarness.Bus.Publish(userCreated);
|
||||
await _testHarness.Consumed.Any<UserCreated>();
|
||||
|
||||
var passengerEntity = FakePassengerCreated.Generate(userCreated);
|
||||
await Fixture.InsertAsync(passengerEntity);
|
||||
|
||||
@ -56,8 +49,7 @@ public class GetPassengerByIdTests : IntegrationTestBase<Program, PassengerDbCon
|
||||
{
|
||||
// Arrange
|
||||
var userCreated = new FakeUserCreated().Generate();
|
||||
await _testHarness.Bus.Publish(userCreated);
|
||||
await _testHarness.Consumed.Any<UserCreated>();
|
||||
|
||||
var passengerEntity = FakePassengerCreated.Generate(userCreated);
|
||||
await Fixture.InsertAsync(passengerEntity);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user