diff --git a/src/BuildingBlocks/MassTransit/Extensions.cs b/src/BuildingBlocks/MassTransit/Extensions.cs index edcd4c4..66b9ed8 100644 --- a/src/BuildingBlocks/MassTransit/Extensions.cs +++ b/src/BuildingBlocks/MassTransit/Extensions.cs @@ -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("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("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}); + } + }); + } + }); + } } diff --git a/src/BuildingBlocks/MassTransit/RabbitMqOptions.cs b/src/BuildingBlocks/MassTransit/RabbitMqOptions.cs index 6156b6a..1f8f6a6 100644 --- a/src/BuildingBlocks/MassTransit/RabbitMqOptions.cs +++ b/src/BuildingBlocks/MassTransit/RabbitMqOptions.cs @@ -6,4 +6,5 @@ public class RabbitMqOptions public string ExchangeName { get; set; } public string UserName { get; set; } public string Password { get; set; } -} \ No newline at end of file + public ushort? Port { get; set; } +} diff --git a/src/BuildingBlocks/TestBase/IntegrationTestBase.cs b/src/BuildingBlocks/TestBase/IntegrationTestBase.cs index 04ea21f..83dd3fc 100644 --- a/src/BuildingBlocks/TestBase/IntegrationTestBase.cs +++ b/src/BuildingBlocks/TestBase/IntegrationTestBase.cs @@ -32,9 +32,10 @@ public class IntegrationTestFixture : IDisposable { private readonly WebApplicationFactory _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 : IDisposable public MsSqlTestcontainer SqlTestContainer; public MsSqlTestcontainer SqlPersistTestContainer; public MongoDbTestcontainer MongoTestContainer; + public RabbitMqTestcontainer RabbitMqTestContainer; public IntegrationTestFixture() { @@ -57,21 +59,6 @@ public class IntegrationTestFixture : IDisposable { TestRegistrationServices?.Invoke(services); services.ReplaceSingleton(AddHttpContextAccessorMock); - services.AddMassTransitTestHarness(x => - { - x.UsingRabbitMq((context, cfg) => - { - var rabbitMqOptions = services.GetOptions("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 : IDisposable }); } + public async Task Publish(TMessage message, CancellationToken cancellationToken = default) + where TMessage : class, IEvent + { + await TestHarness.Bus.Publish(message, cancellationToken); + } + + public async Task WaitForPublishing(CancellationToken cancellationToken = default) + where TMessage : class, IEvent + { + await WaitUntilConditionMet(async () => + { + var published = await TestHarness.Published.Any(cancellationToken); + var faulty = await TestHarness.Published.Any>(cancellationToken); + + return published && faulty == false; + }); + } + + public async Task WaitForConsuming(CancellationToken cancellationToken = default) + where TMessage : class, IEvent + { + await WaitUntilConditionMet(async () => + { + var consumed = await TestHarness.Consumed.Any(cancellationToken); + var faulty = await TestHarness.Consumed.Any>(cancellationToken); + + return consumed && faulty == false; + }); + } + // Ref: https://tech.energyhelpline.com/in-memory-testing-with-masstransit/ public async ValueTask WaitUntilConditionMet(Func> conditionToMet, int? timeoutSecond = null) { @@ -336,6 +353,9 @@ public class IntegrationTestFixtureCore : IAsyncLifetime set => Fixture.ServiceProvider.GetRequiredService>().Value.ConnectionString = value; } + private RabbitMqOptions RabbitMqOptions => + Fixture.ServiceProvider.GetRequiredService>()?.Value; + public IntegrationTestFixtureCore(IntegrationTestFixture integrationTestFixture) { Fixture = integrationTestFixture; @@ -349,48 +369,66 @@ public class IntegrationTestFixtureCore : IAsyncLifetime _checkpointDefaultDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}}; _checkpointPersistMessageDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}}; - _mongoRunner = MongoDbRunner.Start(); - - if (MongoConnectionString != null) - MongoConnectionString = _mongoRunner.ConnectionString; - - // <> - // 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(); - // <> - // await Fixture.SqlTestContainer.StopAsync(); - // await Fixture.SqlPersistTestContainer.StopAsync(); - // await Fixture.MongoTestContainer.StopAsync(); + //await StopTestContainerAsync(); } protected virtual void RegisterTestsServices(IServiceCollection services) { } + private async Task StartTestContainerAsync() + { + // <> + 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() + { + // <> + 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(); diff --git a/src/BuildingBlocks/TestBase/TestContainers.cs b/src/BuildingBlocks/TestBase/TestContainers.cs index 3495b8c..0044487 100644 --- a/src/BuildingBlocks/TestBase/TestContainers.cs +++ b/src/BuildingBlocks/TestBase/TestContainers.cs @@ -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() + .WithMessageBroker(new RabbitMqTestcontainerConfiguration() + { + Password = "guest", + Username = "guest" + }) + .WithImage("rabbitmq:3-management") + .Build(); } diff --git a/src/Services/Booking/src/Booking.Api/appsettings.docker.json b/src/Services/Booking/src/Booking.Api/appsettings.docker.json index e57caf6..c1d2f8f 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.docker.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.docker.json @@ -10,7 +10,8 @@ "HostName": "rabbitmq", "ExchangeName": "booking", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Grpc": { "FlightAddress": "https://localhost:5003", diff --git a/src/Services/Booking/src/Booking.Api/appsettings.json b/src/Services/Booking/src/Booking.Api/appsettings.json index 1cfcba1..6c425a4 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.json @@ -23,7 +23,8 @@ "HostName": "localhost", "ExchangeName": "booking", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Grpc": { "FlightAddress": "https://localhost:5003", diff --git a/src/Services/Booking/src/Booking.Api/appsettings.test.json b/src/Services/Booking/src/Booking.Api/appsettings.test.json index 4673fd0..1c2df13 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.test.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.test.json @@ -3,7 +3,8 @@ "HostName": "localhost", "ExchangeName": "booking", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Logging": { "LogLevel": { diff --git a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs index 3e4af47..c77f594 100644 --- a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs +++ b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs @@ -24,13 +24,10 @@ namespace Integration.Test.Booking.Features; public class CreateBookingTests : IntegrationTestBase { - private readonly ITestHarness _testHarness; - public CreateBookingTests( IntegrationTestFixture integrationTestFixture) : base( integrationTestFixture) { - _testHarness = Fixture.TestHarness; } protected override void RegisterTestsServices(IServiceCollection services) @@ -51,8 +48,8 @@ public class CreateBookingTests : IntegrationTestBase>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + + await Fixture.WaitForPublishing(); } diff --git a/src/Services/Flight/src/Flight.Api/appsettings.docker.json b/src/Services/Flight/src/Flight.Api/appsettings.docker.json index 489dba8..485ca97 100644 --- a/src/Services/Flight/src/Flight.Api/appsettings.docker.json +++ b/src/Services/Flight/src/Flight.Api/appsettings.docker.json @@ -17,7 +17,8 @@ "HostName": "rabbitmq", "ExchangeName": "flight", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "AllowedHosts": "*" } diff --git a/src/Services/Flight/src/Flight.Api/appsettings.json b/src/Services/Flight/src/Flight.Api/appsettings.json index 95ff233..ef2d916 100644 --- a/src/Services/Flight/src/Flight.Api/appsettings.json +++ b/src/Services/Flight/src/Flight.Api/appsettings.json @@ -30,7 +30,8 @@ "HostName": "localhost", "ExchangeName": "flight", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "PersistMessageOptions": { "Interval": 30, diff --git a/src/Services/Flight/src/Flight.Api/appsettings.test.json b/src/Services/Flight/src/Flight.Api/appsettings.test.json index cebe947..5ec0530 100644 --- a/src/Services/Flight/src/Flight.Api/appsettings.test.json +++ b/src/Services/Flight/src/Flight.Api/appsettings.test.json @@ -6,7 +6,8 @@ "HostName": "localhost", "ExchangeName": "flight", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Logging": { "LogLevel": { diff --git a/src/Services/Flight/src/Flight/CreateFlightConsumerHandler.cs b/src/Services/Flight/src/Flight/CreateFlightConsumerHandler.cs new file mode 100644 index 0000000..5d9caaf --- /dev/null +++ b/src/Services/Flight/src/Flight/CreateFlightConsumerHandler.cs @@ -0,0 +1,15 @@ +using System; +using System.Threading.Tasks; +using BuildingBlocks.Contracts.EventBus.Messages; +using MassTransit; + +namespace Flight; + +public class CreateFlightConsumerHandler : IConsumer +{ + public Task Consume(ConsumeContext context) + { + Console.WriteLine("It's for test"); + return Task.CompletedTask; + } +} diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs index 0673242..c176dfe 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs @@ -40,8 +40,6 @@ public class CreateFlightCommandHandler : ICommandHandler(newFlight.Entity); - - return f; + return _mapper.Map(newFlight.Entity); } } diff --git a/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs b/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs index cd223ae..9d04ce3 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs @@ -29,6 +29,9 @@ public class FlightMappings : IRegister .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.FlightId, s => s.Id); + config.NewConfig() + .Map(d => d.Id, s => s.FlightId); + config.NewConfig() .Map(d => d.FlightId, s => s.Id); diff --git a/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs b/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs index 932743c..2006d7d 100644 --- a/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs @@ -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 { - private readonly ITestHarness _testHarness; - - public CreateAircraftTests(IntegrationTestFixture integrationTestFixture) : base(integrationTestFixture) + public CreateAircraftTests( + IntegrationTestFixture integrationTestFixture) : base( + integrationTestFixture) { - _testHarness = Fixture.TestHarness; } [Fact] @@ -33,8 +30,8 @@ public class CreateAircraftTests : IntegrationTestBase>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + + await Fixture.WaitForPublishing(); await Fixture.ShouldProcessedPersistInternalCommand(); } diff --git a/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs b/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs index 260644d..6d54704 100644 --- a/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs @@ -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 { - private readonly ITestHarness _testHarness; - public CreateAirportTests( IntegrationTestFixture integrationTestFixture) : base( integrationTestFixture) { - _testHarness = Fixture.TestHarness; } [Fact] @@ -35,8 +30,8 @@ public class CreateAirportTests : IntegrationTestBase>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + + await Fixture.WaitForPublishing(); await Fixture.ShouldProcessedPersistInternalCommand(); } diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs index 36d0d2d..8c9d092 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs @@ -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 { - private readonly ITestHarness _testHarness; - public CreateFlightTests( IntegrationTestFixture 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>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + await Fixture.WaitForPublishing(); + await Fixture.WaitForConsuming(); await Fixture.ShouldProcessedPersistInternalCommand(); } diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs index 1e3da0b..d5299f6 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs @@ -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 { - private readonly ITestHarness _testHarness; - public DeleteFlightTests( IntegrationTestFixture integrationTestFixture) : base( integrationTestFixture) { - _testHarness = Fixture.TestHarness; } [Fact] @@ -43,8 +37,9 @@ public class DeleteFlightTests : IntegrationTestBase>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + + await Fixture.WaitForPublishing(); + await Fixture.ShouldProcessedPersistInternalCommand(); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs index c1eb678..1711133 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs @@ -58,6 +58,6 @@ public class GetFlightByIdTests : IntegrationTestBase { - private readonly ITestHarness _testHarness; - - public UpdateFlightTests(IntegrationTestFixture integrationTestFixture) : base(integrationTestFixture) + public UpdateFlightTests( + IntegrationTestFixture 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>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + + await Fixture.WaitForPublishing(); + await Fixture.ShouldProcessedPersistInternalCommand(); } } diff --git a/src/Services/Identity/src/Identity.Api/appsettings.docker.json b/src/Services/Identity/src/Identity.Api/appsettings.docker.json index 9123110..58232c8 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.docker.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.docker.json @@ -7,7 +7,8 @@ "HostName": "rabbitmq", "ExchangeName": "identity", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "AllowedHosts": "*" } diff --git a/src/Services/Identity/src/Identity.Api/appsettings.json b/src/Services/Identity/src/Identity.Api/appsettings.json index eec0635..548ed48 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.json @@ -9,7 +9,8 @@ "HostName": "localhost", "ExchangeName": "identity", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Jwt": { "Authority": "https://localhost:5005", diff --git a/src/Services/Identity/src/Identity.Api/appsettings.test.json b/src/Services/Identity/src/Identity.Api/appsettings.test.json index e6dacae..92b31cc 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.test.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.test.json @@ -6,7 +6,8 @@ "HostName": "localhost", "ExchangeName": "identity", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Logging": { "LogLevel": { diff --git a/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs b/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs index 36cabbf..c7386f3 100644 --- a/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs +++ b/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs @@ -13,11 +13,9 @@ namespace Integration.Test.Identity.Features; public class RegisterNewUserTests : IntegrationTestBase { - private readonly ITestHarness _testHarness; - - public RegisterNewUserTests(IntegrationTestFixture integrationTestFixture) : base(integrationTestFixture) + public RegisterNewUserTests(IntegrationTestFixture integrationTestFixture) : base( + integrationTestFixture) { - _testHarness = Fixture.TestHarness; } [Fact] @@ -32,7 +30,7 @@ public class RegisterNewUserTests : IntegrationTestBase>()).Should().BeFalse(); - (await _testHarness.Published.Any()).Should().BeTrue(); + + await Fixture.WaitForPublishing(); } } diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json b/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json index d7bea44..2b748ff 100644 --- a/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json +++ b/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json @@ -11,7 +11,8 @@ "HostName": "rabbitmq", "ExchangeName": "passenger", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "AllowedHosts": "*" } diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.json b/src/Services/Passenger/src/Passenger.Api/appsettings.json index 31dc86a..f2d6d95 100644 --- a/src/Services/Passenger/src/Passenger.Api/appsettings.json +++ b/src/Services/Passenger/src/Passenger.Api/appsettings.json @@ -17,7 +17,8 @@ "HostName": "localhost", "ExchangeName": "passenger", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "LogOptions": { "Level": "information", diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.test.json b/src/Services/Passenger/src/Passenger.Api/appsettings.test.json index 859397a..15db2aa 100644 --- a/src/Services/Passenger/src/Passenger.Api/appsettings.test.json +++ b/src/Services/Passenger/src/Passenger.Api/appsettings.test.json @@ -6,7 +6,8 @@ "HostName": "localhost", "ExchangeName": "passenger", "UserName": "guest", - "Password": "guest" + "Password": "guest", + "Port": 5672 }, "Logging": { "LogLevel": { diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs index a1f2205..fd22476 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs @@ -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 { - private readonly ITestHarness _testHarness; - public CompleteRegisterPassengerTests(IntegrationTestFixture integrationTestFixture) : base(integrationTestFixture) { - _testHarness = Fixture.TestHarness; } [Fact] @@ -25,9 +23,10 @@ public class CompleteRegisterPassengerTests : IntegrationTestBase(); - await Fixture.InsertAsync(FakePassengerCreated.Generate(userCreated)); + + await Fixture.Publish(userCreated); + await Fixture.WaitForPublishing(); + await Fixture.WaitForConsuming(); var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate(); diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs index 49209bb..1758051 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs @@ -16,18 +16,12 @@ namespace Integration.Test.Passenger.Features; public class GetPassengerByIdTests : IntegrationTestBase { - private readonly ITestHarness _testHarness; private readonly GrpcChannel _channel; public GetPassengerByIdTests(IntegrationTestFixture integrationTestFixture) : base( integrationTestFixture) { _channel = Fixture.Channel; - _testHarness = Fixture.TestHarness; - } - - protected override void RegisterTestsServices(IServiceCollection services) - { } @@ -36,8 +30,7 @@ public class GetPassengerByIdTests : IntegrationTestBase(); + var passengerEntity = FakePassengerCreated.Generate(userCreated); await Fixture.InsertAsync(passengerEntity); @@ -56,8 +49,7 @@ public class GetPassengerByIdTests : IntegrationTestBase(); + var passengerEntity = FakePassengerCreated.Generate(userCreated); await Fixture.InsertAsync(passengerEntity);