diff --git a/src/BuildingBlocks/EFCore/EfTxBehavior.cs b/src/BuildingBlocks/EFCore/EfTxBehavior.cs index 5226651..6916c57 100644 --- a/src/BuildingBlocks/EFCore/EfTxBehavior.cs +++ b/src/BuildingBlocks/EFCore/EfTxBehavior.cs @@ -65,7 +65,7 @@ public class EfTxBehavior : IPipelineBehavior { private readonly GrpcChannel _channel; private readonly IntegrationTestFixture _fixture; diff --git a/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj index 6f7dfd6..c48e4af 100644 --- a/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj @@ -5,6 +5,12 @@ false + + + PreserveNewest + + + diff --git a/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs b/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs index 0ee813c..6c7a791 100644 --- a/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs +++ b/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Mongo2Go; using NSubstitute; @@ -32,24 +31,19 @@ using Xunit.Abstractions; namespace Integration.Test; -[CollectionDefinition(nameof(IntegrationTestFixture))] -public class FixtureCollection : ICollectionFixture -{ -} - public class IntegrationTestFixture : IAsyncLifetime { - private WebApplicationFactory _factory; private Checkpoint _checkpoint; + private IConfiguration _configuration; + private WebApplicationFactory _factory; private MongoDbRunner _mongoRunner; private IServiceProvider _serviceProvider; private Action? _testRegistrationServices; - private IConfiguration _configuration; - public HttpClient HttpClient => _factory.CreateClient(); - public ITestHarness TestHarness => CreateHarness(); - public GrpcChannel Channel => CreateChannel(); + public ITestHarness TestHarness { get; private set; } + public HttpClient HttpClient { get; private set; } + public GrpcChannel Channel { get; private set; } - public virtual Task InitializeAsync() + public Task InitializeAsync() { _factory = new WebApplicationFactory() .WithWebHostBuilder(builder => @@ -65,6 +59,7 @@ public class IntegrationTestFixture : IAsyncLifetime { MockFlightGrpcServices(services); MockPassengerGrpcServices(services); + services.ReplaceSingleton(AddHttpContextAccessorMock); services.AddMassTransitTestHarness(x => { @@ -86,6 +81,10 @@ public class IntegrationTestFixture : IAsyncLifetime _serviceProvider = _factory.Services; _configuration = _factory.Services.GetRequiredService(); + HttpClient = _factory.CreateClient(); + Channel = CreateChannel(); + TestHarness = CreateHarness(); + _checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}}; _mongoRunner = MongoDbRunner.Start(); @@ -96,15 +95,16 @@ public class IntegrationTestFixture : IAsyncLifetime return Task.CompletedTask; } - public void RegisterServices(Action services) => _testRegistrationServices = services; - - public virtual async Task DisposeAsync() + public async Task DisposeAsync() { - if (!string.IsNullOrEmpty(_configuration?.GetConnectionString("DefaultConnection"))) - await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); - - await _factory.DisposeAsync(); + await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); _mongoRunner.Dispose(); + await _factory.DisposeAsync(); + } + + public void RegisterServices(Action services) + { + _testRegistrationServices = services; } // ref: https://github.com/trbenning/serilog-sinks-xunit @@ -260,7 +260,6 @@ public class IntegrationTestFixture : IAsyncLifetime private ITestHarness CreateHarness() { var harness = _serviceProvider.GetTestHarness(); - harness.Start().GetAwaiter().GetResult(); return harness; } diff --git a/src/Services/Booking/tests/IntegrationTest/xunit.runner.json b/src/Services/Booking/tests/IntegrationTest/xunit.runner.json new file mode 100644 index 0000000..9db029b --- /dev/null +++ b/src/Services/Booking/tests/IntegrationTest/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "parallelizeAssembly": false, + "parallelizeTestCollections": false +} diff --git a/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs b/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs index b96aa6c..c361124 100644 --- a/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Aircraft/Features/CreateAircraftTests.cs @@ -7,13 +7,10 @@ using MassTransit.Testing; using Xunit; namespace Integration.Test.Aircraft.Features; - -[Collection(nameof(IntegrationTestFixture))] -public class CreateAircraftTests +public class CreateAircraftTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; - public CreateAircraftTests(IntegrationTestFixture fixture) { _fixture = fixture; diff --git a/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs b/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs index 5232c4c..73ae343 100644 --- a/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Airport/Features/CreateAirportTests.cs @@ -7,9 +7,7 @@ using MassTransit.Testing; using Xunit; namespace Integration.Test.Airport.Features; - -[Collection(nameof(IntegrationTestFixture))] -public class CreateAirportTests +public class CreateAirportTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs index ab8124a..33b311d 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/CreateFlightTests.cs @@ -8,8 +8,7 @@ using Xunit; namespace Integration.Test.Flight.Features; -[Collection(nameof(IntegrationTestFixture))] -public class CreateFlightTests +public class CreateFlightTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; @@ -17,7 +16,7 @@ public class CreateFlightTests public CreateFlightTests(IntegrationTestFixture fixture) { _fixture = fixture; - _testHarness = _fixture.TestHarness; + _testHarness = fixture.TestHarness; } [Fact] @@ -32,6 +31,7 @@ public class CreateFlightTests // Assert response.Should().NotBeNull(); response?.FlightNumber.Should().Be(command.FlightNumber); + (await _testHarness.Published.Any>()).Should().BeFalse(); (await _testHarness.Published.Any()).Should().BeTrue(); } diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs index 60cbee8..3a1b7e3 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs @@ -11,8 +11,7 @@ using Xunit; namespace Integration.Test.Flight.Features; -[Collection(nameof(IntegrationTestFixture))] -public class DeleteFlightTests +public class DeleteFlightTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs index 55a2c37..03ae34c 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs @@ -10,8 +10,7 @@ using Xunit; namespace Integration.Test.Flight.Features; -[Collection(nameof(IntegrationTestFixture))] -public class GetAvailableFlightsTests +public class GetAvailableFlightsTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly GrpcChannel _channel; diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs index ecee2d1..8a41901 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs @@ -9,8 +9,7 @@ using Xunit; namespace Integration.Test.Flight.Features; -[Collection(nameof(IntegrationTestFixture))] -public class GetFlightByIdTests +public class GetFlightByIdTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly GrpcChannel _channel; diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs index 74883ba..de00712 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs @@ -7,9 +7,7 @@ using MassTransit.Testing; using Xunit; namespace Integration.Test.Flight.Features; - -[Collection(nameof(IntegrationTestFixture))] -public class UpdateFlightTests +public class UpdateFlightTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; @@ -17,7 +15,7 @@ public class UpdateFlightTests public UpdateFlightTests(IntegrationTestFixture fixture) { _fixture = fixture; - _testHarness = _fixture.TestHarness; + _testHarness = fixture.TestHarness; } [Fact] diff --git a/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj index 4053e9a..368989b 100644 --- a/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj @@ -5,6 +5,12 @@ false + + + PreserveNewest + + + diff --git a/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs b/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs index 89ec2c1..6d65768 100644 --- a/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs +++ b/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs @@ -25,11 +25,6 @@ using Xunit.Abstractions; namespace Integration.Test; -[CollectionDefinition(nameof(IntegrationTestFixture))] -public class FixtureCollection : ICollectionFixture -{ -} - public class IntegrationTestFixture : IAsyncLifetime { private Checkpoint _checkpoint; @@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime private MongoDbRunner _mongoRunner; private IServiceProvider _serviceProvider; private Action? _testRegistrationServices; - public HttpClient HttpClient => _factory.CreateClient(); - public ITestHarness TestHarness => CreateHarness(); - public GrpcChannel Channel => CreateChannel(); + public ITestHarness TestHarness { get; private set; } + public HttpClient HttpClient { get; private set; } + public GrpcChannel Channel { get; private set; } - - public virtual Task InitializeAsync() + public Task InitializeAsync() { _factory = new WebApplicationFactory() .WithWebHostBuilder(builder => @@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime _serviceProvider = _factory.Services; _configuration = _factory.Services.GetRequiredService(); + HttpClient = _factory.CreateClient(); + Channel = CreateChannel(); + TestHarness = CreateHarness(); + _checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}}; _mongoRunner = MongoDbRunner.Start(); @@ -88,13 +86,11 @@ public class IntegrationTestFixture : IAsyncLifetime return Task.CompletedTask; } - public virtual async Task DisposeAsync() + public async Task DisposeAsync() { - if (!string.IsNullOrEmpty(_configuration?.GetConnectionString("DefaultConnection"))) - await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); - - await _factory.DisposeAsync(); + await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); _mongoRunner.Dispose(); + await _factory.DisposeAsync(); } public void RegisterServices(Action services) @@ -255,7 +251,6 @@ public class IntegrationTestFixture : IAsyncLifetime private ITestHarness CreateHarness() { var harness = _serviceProvider.GetTestHarness(); - harness.Start().GetAwaiter().GetResult(); return harness; } diff --git a/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs b/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs index a5a2d35..3e11b38 100644 --- a/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs @@ -9,8 +9,7 @@ using Xunit; namespace Integration.Test.Seat.Features; -[Collection(nameof(IntegrationTestFixture))] -public class GetAvailableSeatsTests +public class GetAvailableSeatsTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly GrpcChannel _channel; diff --git a/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs b/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs index 2822e32..5a4bcc1 100644 --- a/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs @@ -7,9 +7,7 @@ using MagicOnion.Client; using Xunit; namespace Integration.Test.Seat.Features; - -[Collection(nameof(IntegrationTestFixture))] -public class ReserveSeatTests +public class ReserveSeatTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly GrpcChannel _channel; diff --git a/src/Services/Flight/tests/IntegrationTest/xunit.runner.json b/src/Services/Flight/tests/IntegrationTest/xunit.runner.json new file mode 100644 index 0000000..9db029b --- /dev/null +++ b/src/Services/Flight/tests/IntegrationTest/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "parallelizeAssembly": false, + "parallelizeTestCollections": false +} diff --git a/src/Services/Flight/tests/UnitTest/Unit.Test.csproj b/src/Services/Flight/tests/UnitTest/Unit.Test.csproj index ee72bae..7bbbfad 100644 --- a/src/Services/Flight/tests/UnitTest/Unit.Test.csproj +++ b/src/Services/Flight/tests/UnitTest/Unit.Test.csproj @@ -5,6 +5,12 @@ false + + + PreserveNewest + + + diff --git a/src/Services/Flight/tests/UnitTest/xunit.runner.json b/src/Services/Flight/tests/UnitTest/xunit.runner.json new file mode 100644 index 0000000..9db029b --- /dev/null +++ b/src/Services/Flight/tests/UnitTest/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "parallelizeAssembly": false, + "parallelizeTestCollections": false +} diff --git a/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs b/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs index 9456de1..ab55719 100644 --- a/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs +++ b/src/Services/Identity/tests/IntegrationTest/Identity/Features/RegisterNewUserTests.cs @@ -8,8 +8,7 @@ using Xunit; namespace Integration.Test.Identity.Features; -[Collection(nameof(IntegrationTestFixture))] -public class RegisterNewUserTests +public class RegisterNewUserTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; diff --git a/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj index d51304a..26fcae7 100644 --- a/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj @@ -5,7 +5,12 @@ false - + + + PreserveNewest + + + diff --git a/src/Services/Identity/tests/IntegrationTest/IntegrationTestFixture.cs b/src/Services/Identity/tests/IntegrationTest/IntegrationTestFixture.cs index cbce2d3..6933645 100644 --- a/src/Services/Identity/tests/IntegrationTest/IntegrationTestFixture.cs +++ b/src/Services/Identity/tests/IntegrationTest/IntegrationTestFixture.cs @@ -25,11 +25,6 @@ using Xunit.Abstractions; namespace Integration.Test; -[CollectionDefinition(nameof(IntegrationTestFixture))] -public class FixtureCollection : ICollectionFixture -{ -} - public class IntegrationTestFixture : IAsyncLifetime { private Checkpoint _checkpoint; @@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime private MongoDbRunner _mongoRunner; private IServiceProvider _serviceProvider; private Action? _testRegistrationServices; - public HttpClient HttpClient => _factory.CreateClient(); - public ITestHarness TestHarness => CreateHarness(); - public GrpcChannel Channel => CreateChannel(); + public ITestHarness TestHarness { get; private set; } + public HttpClient HttpClient { get; private set; } + public GrpcChannel Channel { get; private set; } - - public virtual Task InitializeAsync() + public Task InitializeAsync() { _factory = new WebApplicationFactory() .WithWebHostBuilder(builder => @@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime _serviceProvider = _factory.Services; _configuration = _factory.Services.GetRequiredService(); + HttpClient = _factory.CreateClient(); + Channel = CreateChannel(); + TestHarness = CreateHarness(); + _checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}}; _mongoRunner = MongoDbRunner.Start(); @@ -88,13 +86,11 @@ public class IntegrationTestFixture : IAsyncLifetime return Task.CompletedTask; } - public virtual async Task DisposeAsync() + public async Task DisposeAsync() { - if (!string.IsNullOrEmpty(_configuration?.GetConnectionString("DefaultConnection"))) - await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); - - await _factory.DisposeAsync(); + await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); _mongoRunner.Dispose(); + await _factory.DisposeAsync(); } public void RegisterServices(Action services) @@ -106,11 +102,9 @@ public class IntegrationTestFixture : IAsyncLifetime public ILogger CreateLogger(ITestOutputHelper output) { if (output != null) - { return new LoggerConfiguration() .WriteTo.TestOutput(output) .CreateLogger(); - } return null; } @@ -255,7 +249,6 @@ public class IntegrationTestFixture : IAsyncLifetime private ITestHarness CreateHarness() { var harness = _serviceProvider.GetTestHarness(); - harness.Start().GetAwaiter().GetResult(); return harness; } diff --git a/src/Services/Identity/tests/IntegrationTest/xunit.runner.json b/src/Services/Identity/tests/IntegrationTest/xunit.runner.json new file mode 100644 index 0000000..9db029b --- /dev/null +++ b/src/Services/Identity/tests/IntegrationTest/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "parallelizeAssembly": false, + "parallelizeTestCollections": false +} diff --git a/src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs b/src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs deleted file mode 100644 index cea2042..0000000 --- a/src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -// using System.Threading.Tasks; -// using BuildingBlocks.Contracts.EventBus.Messages; -// using Integration.Test.Fakes; -// using MassTransit.Testing; -// using Xunit; -// -// namespace Integration.Test.Identity.Features; -// -// [Collection(nameof(TestFixture))] -// public class RegisterNewUserConsumerTests -// { -// private readonly TestFixture _fixture; -// private readonly ITestHarness _testHarness; -// -// public RegisterNewUserConsumerTests(TestFixture fixture) -// { -// _fixture = fixture; -// _testHarness = _fixture.TestHarness; -// } -// -// [Fact] -// public async Task should_register_new_user_consume_handler_consume_user_created_message() -// { -// // // Arrange -// var message = new FakeUserCreated().Generate(); -// -// // // Act -// await _testHarness.Bus.Publish(message); -// -// // // Assert -// await _testHarness.Consumed.Any(); -// } -// } diff --git a/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj index 7144cd8..c1d3846 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj @@ -5,6 +5,12 @@ false + + + PreserveNewest + + + diff --git a/src/Services/Passenger/tests/IntegrationTest/IntegrationTestFixture.cs b/src/Services/Passenger/tests/IntegrationTest/IntegrationTestFixture.cs index 3e00083..78d0c4e 100644 --- a/src/Services/Passenger/tests/IntegrationTest/IntegrationTestFixture.cs +++ b/src/Services/Passenger/tests/IntegrationTest/IntegrationTestFixture.cs @@ -25,11 +25,6 @@ using Xunit.Abstractions; namespace Integration.Test; -[CollectionDefinition(nameof(IntegrationTestFixture))] -public class FixtureCollection : ICollectionFixture -{ -} - public class IntegrationTestFixture : IAsyncLifetime { private Checkpoint _checkpoint; @@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime private MongoDbRunner _mongoRunner; private IServiceProvider _serviceProvider; private Action? _testRegistrationServices; - public HttpClient HttpClient => _factory.CreateClient(); - public ITestHarness TestHarness => CreateHarness(); - public GrpcChannel Channel => CreateChannel(); + public ITestHarness TestHarness { get; private set; } + public HttpClient HttpClient { get; private set; } + public GrpcChannel Channel { get; private set; } - - public virtual Task InitializeAsync() + public Task InitializeAsync() { _factory = new WebApplicationFactory() .WithWebHostBuilder(builder => @@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime _serviceProvider = _factory.Services; _configuration = _factory.Services.GetRequiredService(); + HttpClient = _factory.CreateClient(); + Channel = CreateChannel(); + TestHarness = CreateHarness(); + _checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}}; _mongoRunner = MongoDbRunner.Start(); @@ -88,13 +86,11 @@ public class IntegrationTestFixture : IAsyncLifetime return Task.CompletedTask; } - public virtual async Task DisposeAsync() + public async Task DisposeAsync() { - if (!string.IsNullOrEmpty(_configuration?.GetConnectionString("DefaultConnection"))) - await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); - - await _factory.DisposeAsync(); + await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection")); _mongoRunner.Dispose(); + await _factory.DisposeAsync(); } public void RegisterServices(Action services) @@ -255,7 +251,6 @@ public class IntegrationTestFixture : IAsyncLifetime private ITestHarness CreateHarness() { var harness = _serviceProvider.GetTestHarness(); - harness.Start().GetAwaiter().GetResult(); return harness; } diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs index d91c523..15a911c 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs @@ -7,8 +7,7 @@ using Xunit; namespace Integration.Test.Passenger.Features; -[Collection(nameof(IntegrationTestFixture))] -public class CompleteRegisterPassengerTests +public class CompleteRegisterPassengerTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs index 2d60cb4..bae4192 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs @@ -11,8 +11,7 @@ using Xunit; namespace Integration.Test.Passenger.Features; -[Collection(nameof(IntegrationTestFixture))] -public class GetPassengerByIdTests +public class GetPassengerByIdTests : IClassFixture { private readonly IntegrationTestFixture _fixture; private readonly ITestHarness _testHarness; diff --git a/src/Services/Passenger/tests/IntegrationTest/xunit.runner.json b/src/Services/Passenger/tests/IntegrationTest/xunit.runner.json new file mode 100644 index 0000000..9db029b --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "parallelizeAssembly": false, + "parallelizeTestCollections": false +}