mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-12 03:12:11 +08:00
fix bug tests
This commit is contained in:
parent
1be144f005
commit
30abb169af
@ -65,7 +65,7 @@ public class EfTxBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TRe
|
||||
|
||||
return response;
|
||||
}
|
||||
catch
|
||||
catch(System.Exception ex)
|
||||
{
|
||||
await _dbContextBase.RollbackTransactionAsync(cancellationToken);
|
||||
throw;
|
||||
|
||||
@ -13,9 +13,7 @@ using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Booking.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class CreateBookingTests
|
||||
public class CreateBookingTests: IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly GrpcChannel _channel;
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
|
||||
@ -5,6 +5,12 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
||||
|
||||
@ -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<IntegrationTestFixture>
|
||||
{
|
||||
}
|
||||
|
||||
public class IntegrationTestFixture : IAsyncLifetime
|
||||
{
|
||||
private WebApplicationFactory<Program> _factory;
|
||||
private Checkpoint _checkpoint;
|
||||
private IConfiguration _configuration;
|
||||
private WebApplicationFactory<Program> _factory;
|
||||
private MongoDbRunner _mongoRunner;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private Action<IServiceCollection>? _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<Program>()
|
||||
.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<IConfiguration>();
|
||||
|
||||
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<IServiceCollection> 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<IServiceCollection> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parallelizeAssembly": false,
|
||||
"parallelizeTestCollections": false
|
||||
}
|
||||
@ -7,13 +7,10 @@ using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Aircraft.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class CreateAircraftTests
|
||||
public class CreateAircraftTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
public CreateAircraftTests(IntegrationTestFixture fixture)
|
||||
{
|
||||
_fixture = fixture;
|
||||
|
||||
@ -7,9 +7,7 @@ using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Airport.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class CreateAirportTests
|
||||
public class CreateAirportTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
@ -8,8 +8,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class CreateFlightTests
|
||||
public class CreateFlightTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
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<Fault<FlightCreated>>()).Should().BeFalse();
|
||||
(await _testHarness.Published.Any<FlightCreated>()).Should().BeTrue();
|
||||
}
|
||||
|
||||
@ -11,8 +11,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class DeleteFlightTests
|
||||
public class DeleteFlightTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
@ -10,8 +10,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class GetAvailableFlightsTests
|
||||
public class GetAvailableFlightsTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly GrpcChannel _channel;
|
||||
|
||||
@ -9,8 +9,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class GetFlightByIdTests
|
||||
public class GetFlightByIdTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly GrpcChannel _channel;
|
||||
|
||||
@ -7,9 +7,7 @@ using MassTransit.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class UpdateFlightTests
|
||||
public class UpdateFlightTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
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]
|
||||
|
||||
@ -5,6 +5,12 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
||||
|
||||
@ -25,11 +25,6 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace Integration.Test;
|
||||
|
||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
||||
{
|
||||
}
|
||||
|
||||
public class IntegrationTestFixture : IAsyncLifetime
|
||||
{
|
||||
private Checkpoint _checkpoint;
|
||||
@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
private MongoDbRunner _mongoRunner;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private Action<IServiceCollection>? _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<Program>()
|
||||
.WithWebHostBuilder(builder =>
|
||||
@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
_serviceProvider = _factory.Services;
|
||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||
|
||||
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<IServiceCollection> services)
|
||||
@ -255,7 +251,6 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
private ITestHarness CreateHarness()
|
||||
{
|
||||
var harness = _serviceProvider.GetTestHarness();
|
||||
harness.Start().GetAwaiter().GetResult();
|
||||
return harness;
|
||||
}
|
||||
|
||||
|
||||
@ -9,8 +9,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Seat.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class GetAvailableSeatsTests
|
||||
public class GetAvailableSeatsTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly GrpcChannel _channel;
|
||||
|
||||
@ -7,9 +7,7 @@ using MagicOnion.Client;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Seat.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class ReserveSeatTests
|
||||
public class ReserveSeatTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly GrpcChannel _channel;
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parallelizeAssembly": false,
|
||||
"parallelizeTestCollections": false
|
||||
}
|
||||
@ -5,6 +5,12 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
|
||||
4
src/Services/Flight/tests/UnitTest/xunit.runner.json
Normal file
4
src/Services/Flight/tests/UnitTest/xunit.runner.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parallelizeAssembly": false,
|
||||
"parallelizeTestCollections": false
|
||||
}
|
||||
@ -8,8 +8,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Identity.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class RegisterNewUserTests
|
||||
public class RegisterNewUserTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
@ -5,7 +5,12 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
||||
|
||||
@ -25,11 +25,6 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace Integration.Test;
|
||||
|
||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
||||
{
|
||||
}
|
||||
|
||||
public class IntegrationTestFixture : IAsyncLifetime
|
||||
{
|
||||
private Checkpoint _checkpoint;
|
||||
@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
private MongoDbRunner _mongoRunner;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private Action<IServiceCollection>? _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<Program>()
|
||||
.WithWebHostBuilder(builder =>
|
||||
@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
_serviceProvider = _factory.Services;
|
||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||
|
||||
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<IServiceCollection> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parallelizeAssembly": false,
|
||||
"parallelizeTestCollections": false
|
||||
}
|
||||
@ -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<UserCreated>();
|
||||
// }
|
||||
// }
|
||||
@ -5,6 +5,12 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
||||
|
||||
@ -25,11 +25,6 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace Integration.Test;
|
||||
|
||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
||||
{
|
||||
}
|
||||
|
||||
public class IntegrationTestFixture : IAsyncLifetime
|
||||
{
|
||||
private Checkpoint _checkpoint;
|
||||
@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
private MongoDbRunner _mongoRunner;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private Action<IServiceCollection>? _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<Program>()
|
||||
.WithWebHostBuilder(builder =>
|
||||
@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
_serviceProvider = _factory.Services;
|
||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||
|
||||
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<IServiceCollection> services)
|
||||
@ -255,7 +251,6 @@ public class IntegrationTestFixture : IAsyncLifetime
|
||||
private ITestHarness CreateHarness()
|
||||
{
|
||||
var harness = _serviceProvider.GetTestHarness();
|
||||
harness.Start().GetAwaiter().GetResult();
|
||||
return harness;
|
||||
}
|
||||
|
||||
|
||||
@ -7,8 +7,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Passenger.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class CompleteRegisterPassengerTests
|
||||
public class CompleteRegisterPassengerTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
@ -11,8 +11,7 @@ using Xunit;
|
||||
|
||||
namespace Integration.Test.Passenger.Features;
|
||||
|
||||
[Collection(nameof(IntegrationTestFixture))]
|
||||
public class GetPassengerByIdTests
|
||||
public class GetPassengerByIdTests : IClassFixture<IntegrationTestFixture>
|
||||
{
|
||||
private readonly IntegrationTestFixture _fixture;
|
||||
private readonly ITestHarness _testHarness;
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"parallelizeAssembly": false,
|
||||
"parallelizeTestCollections": false
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user