diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index 8ff3265..ed75c63 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -133,14 +133,10 @@ public class TestFixture : IAsyncLifetime { CancellationTokenSource = new CancellationTokenSource(); await StartTestContainerAsync(); - - await TestHarness.Start(); } public async Task DisposeAsync() { - await TestHarness.Stop(); - await StopTestContainerAsync(); await _factory.DisposeAsync(); await CancellationTokenSource.CancelAsync(); @@ -277,14 +273,11 @@ public class TestFixture : IAsyncLifetime MongoDbTestContainer = TestContainers.MongoTestContainer(); EventStoreDbTestContainer = TestContainers.EventStoreTestContainer(); - await Task.WhenAll( - MongoDbTestContainer.StartAsync(), - PostgresTestcontainer.StartAsync(), - PostgresPersistTestContainer.StartAsync(), - EventStoreDbTestContainer.StartAsync() - ); - + await MongoDbTestContainer.StartAsync(); + await PostgresTestcontainer.StartAsync(); + await PostgresPersistTestContainer.StartAsync(); await RabbitMqTestContainer.StartAsync(); + await EventStoreDbTestContainer.StartAsync(); } private async Task StopTestContainerAsync() diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/GrpcClientExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/GrpcClientExtensions.cs index 19ea193..557abd6 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/GrpcClientExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/GrpcClientExtensions.cs @@ -13,9 +13,12 @@ public static class GrpcClientExtensions public static IServiceCollection AddGrpcClients(this IServiceCollection services) { var grpcOptions = services.GetOptions("Grpc"); - var resilienceOptions = services.GetOptions(nameof(HttpStandardResilienceOptions)); + var resilienceOptions = services.GetOptions( + nameof(HttpStandardResilienceOptions) + ); - services.AddGrpcClient(o => + services + .AddGrpcClient(o => { o.Address = new Uri(grpcOptions.FlightAddress); }) @@ -25,54 +28,37 @@ public static class GrpcClientExtensions { var timeSpan = TimeSpan.FromMinutes(1); - options.AddRetry( - new HttpRetryStrategyOptions - { - MaxRetryAttempts = 3, - }); + options.AddRetry(new HttpRetryStrategyOptions { MaxRetryAttempts = 3 }); options.AddCircuitBreaker( - new HttpCircuitBreakerStrategyOptions - { - SamplingDuration = timeSpan * 2, - }); + new HttpCircuitBreakerStrategyOptions { SamplingDuration = timeSpan * 2 } + ); - options.AddTimeout( - new HttpTimeoutStrategyOptions - { - Timeout = timeSpan * 3, - }); - }); + options.AddTimeout(new HttpTimeoutStrategyOptions { Timeout = timeSpan * 3 }); + } + ); - services.AddGrpcClient(o => - { - o.Address = new Uri(grpcOptions.PassengerAddress); - }) - .AddResilienceHandler( - "grpc-passenger-resilience", - options => + services + .AddGrpcClient(o => { - var timeSpan = TimeSpan.FromMinutes(1); + o.Address = new Uri(grpcOptions.PassengerAddress); + }) + .AddResilienceHandler( + "grpc-passenger-resilience", + options => + { + var timeSpan = TimeSpan.FromMinutes(1); - options.AddRetry( - new HttpRetryStrategyOptions - { - MaxRetryAttempts = 3, - }); + options.AddRetry(new HttpRetryStrategyOptions { MaxRetryAttempts = 3 }); - options.AddCircuitBreaker( - new HttpCircuitBreakerStrategyOptions - { - SamplingDuration = timeSpan * 2, - }); + options.AddCircuitBreaker( + new HttpCircuitBreakerStrategyOptions { SamplingDuration = timeSpan * 2 } + ); - options.AddTimeout( - new HttpTimeoutStrategyOptions - { - Timeout = timeSpan * 3, - }); - }); + options.AddTimeout(new HttpTimeoutStrategyOptions { Timeout = timeSpan * 3 }); + } + ); return services; } -} \ No newline at end of file +} diff --git a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs index 608e419..cd26e4a 100644 --- a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs +++ b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs @@ -19,10 +19,8 @@ namespace Integration.Test.Booking.Features { public class CreateBookingTests : BookingIntegrationTestBase { - public CreateBookingTests(TestReadFixture integrationTestFixture) : base( - integrationTestFixture) - { - } + public CreateBookingTests(TestReadFixture integrationTestFixture) + : base(integrationTestFixture) { } protected override void RegisterTestsServices(IServiceCollection services) { @@ -45,41 +43,76 @@ namespace Integration.Test.Booking.Features (await Fixture.WaitForPublishing()).Should().Be(true); } - private void MockPassengerGrpcServices(IServiceCollection services) { - services.Replace(ServiceDescriptor.Singleton(x => - { - var mockPassenger = Substitute.For(); + services.Replace( + ServiceDescriptor.Singleton(x => + { + var mockPassenger = Substitute.For(); - mockPassenger.GetByIdAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakePassengerResponse.Generate()), - Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); + mockPassenger + .GetByIdAsync(Arg.Any()) + .Returns( + TestCalls.AsyncUnaryCall( + Task.FromResult(FakePassengerResponse.Generate()), + Task.FromResult(new Metadata()), + () => Status.DefaultSuccess, + () => new Metadata(), + () => { } + ) + ); - return mockPassenger; - })); + return mockPassenger; + }) + ); } private void MockFlightGrpcServices(IServiceCollection services) { - services.Replace(ServiceDescriptor.Singleton(x => - { - var mockFlight = Substitute.For(); + services.Replace( + ServiceDescriptor.Singleton(x => + { + var mockFlight = Substitute.For(); - mockFlight.GetByIdAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeFlightResponse.Generate()), - Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); + mockFlight + .GetByIdAsync(Arg.Any()) + .Returns( + TestCalls.AsyncUnaryCall( + Task.FromResult(FakeFlightResponse.Generate()), + Task.FromResult(new Metadata()), + () => Status.DefaultSuccess, + () => new Metadata(), + () => { } + ) + ); - mockFlight.GetAvailableSeatsAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeGetAvailableSeatsResponse.Generate()), - Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); + mockFlight + .GetAvailableSeatsAsync(Arg.Any()) + .Returns( + TestCalls.AsyncUnaryCall( + Task.FromResult(FakeGetAvailableSeatsResponse.Generate()), + Task.FromResult(new Metadata()), + () => Status.DefaultSuccess, + () => new Metadata(), + () => { } + ) + ); - mockFlight.ReserveSeatAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeReserveSeatResponse.Generate()), - Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); + mockFlight + .ReserveSeatAsync(Arg.Any()) + .Returns( + TestCalls.AsyncUnaryCall( + Task.FromResult(FakeReserveSeatResponse.Generate()), + Task.FromResult(new Metadata()), + () => Status.DefaultSuccess, + () => new Metadata(), + () => { } + ) + ); - return mockFlight; - })); + return mockFlight; + }) + ); } } -} \ No newline at end of file +} diff --git a/src/Services/Booking/tests/IntegrationTest/BookingIntegrationTestBase.cs b/src/Services/Booking/tests/IntegrationTest/BookingIntegrationTestBase.cs index db09b76..1991921 100644 --- a/src/Services/Booking/tests/IntegrationTest/BookingIntegrationTestBase.cs +++ b/src/Services/Booking/tests/IntegrationTest/BookingIntegrationTestBase.cs @@ -1,4 +1,3 @@ -using Booking.Api; using Booking.Data; using BuildingBlocks.TestBase; using Xunit; @@ -8,13 +7,12 @@ namespace Integration.Test; [Collection(IntegrationTestCollection.Name)] public class BookingIntegrationTestBase : TestReadBase { - public BookingIntegrationTestBase(TestReadFixture integrationTestFixture) : base(integrationTestFixture) - { - } + public BookingIntegrationTestBase(TestReadFixture integrationTestFixture) + : base(integrationTestFixture) { } } [CollectionDefinition(Name)] public class IntegrationTestCollection : ICollectionFixture> { public const string Name = "Booking Integration Test"; -} \ No newline at end of file +}