mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-29 01:04:56 +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;
|
return response;
|
||||||
}
|
}
|
||||||
catch
|
catch(System.Exception ex)
|
||||||
{
|
{
|
||||||
await _dbContextBase.RollbackTransactionAsync(cancellationToken);
|
await _dbContextBase.RollbackTransactionAsync(cancellationToken);
|
||||||
throw;
|
throw;
|
||||||
|
|||||||
@ -13,9 +13,7 @@ using NSubstitute;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Booking.Features;
|
namespace Integration.Test.Booking.Features;
|
||||||
|
public class CreateBookingTests: IClassFixture<IntegrationTestFixture>
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
|
||||||
public class CreateBookingTests
|
|
||||||
{
|
{
|
||||||
private readonly GrpcChannel _channel;
|
private readonly GrpcChannel _channel;
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
|
|||||||
@ -5,6 +5,12 @@
|
|||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
<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.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Mongo2Go;
|
using Mongo2Go;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
@ -32,24 +31,19 @@ using Xunit.Abstractions;
|
|||||||
|
|
||||||
namespace Integration.Test;
|
namespace Integration.Test;
|
||||||
|
|
||||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
|
||||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IntegrationTestFixture : IAsyncLifetime
|
public class IntegrationTestFixture : IAsyncLifetime
|
||||||
{
|
{
|
||||||
private WebApplicationFactory<Program> _factory;
|
|
||||||
private Checkpoint _checkpoint;
|
private Checkpoint _checkpoint;
|
||||||
|
private IConfiguration _configuration;
|
||||||
|
private WebApplicationFactory<Program> _factory;
|
||||||
private MongoDbRunner _mongoRunner;
|
private MongoDbRunner _mongoRunner;
|
||||||
private IServiceProvider _serviceProvider;
|
private IServiceProvider _serviceProvider;
|
||||||
private Action<IServiceCollection>? _testRegistrationServices;
|
private Action<IServiceCollection>? _testRegistrationServices;
|
||||||
private IConfiguration _configuration;
|
public ITestHarness TestHarness { get; private set; }
|
||||||
public HttpClient HttpClient => _factory.CreateClient();
|
public HttpClient HttpClient { get; private set; }
|
||||||
public ITestHarness TestHarness => CreateHarness();
|
public GrpcChannel Channel { get; private set; }
|
||||||
public GrpcChannel Channel => CreateChannel();
|
|
||||||
|
|
||||||
public virtual Task InitializeAsync()
|
public Task InitializeAsync()
|
||||||
{
|
{
|
||||||
_factory = new WebApplicationFactory<Program>()
|
_factory = new WebApplicationFactory<Program>()
|
||||||
.WithWebHostBuilder(builder =>
|
.WithWebHostBuilder(builder =>
|
||||||
@ -65,6 +59,7 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
{
|
{
|
||||||
MockFlightGrpcServices(services);
|
MockFlightGrpcServices(services);
|
||||||
MockPassengerGrpcServices(services);
|
MockPassengerGrpcServices(services);
|
||||||
|
|
||||||
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
||||||
services.AddMassTransitTestHarness(x =>
|
services.AddMassTransitTestHarness(x =>
|
||||||
{
|
{
|
||||||
@ -86,6 +81,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
_serviceProvider = _factory.Services;
|
_serviceProvider = _factory.Services;
|
||||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||||
|
|
||||||
|
HttpClient = _factory.CreateClient();
|
||||||
|
Channel = CreateChannel();
|
||||||
|
TestHarness = CreateHarness();
|
||||||
|
|
||||||
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
|
|
||||||
_mongoRunner = MongoDbRunner.Start();
|
_mongoRunner = MongoDbRunner.Start();
|
||||||
@ -96,15 +95,16 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterServices(Action<IServiceCollection> services) => _testRegistrationServices = services;
|
public async Task DisposeAsync()
|
||||||
|
|
||||||
public virtual async Task DisposeAsync()
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(_configuration?.GetConnectionString("DefaultConnection")))
|
await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection"));
|
||||||
await _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection"));
|
|
||||||
|
|
||||||
await _factory.DisposeAsync();
|
|
||||||
_mongoRunner.Dispose();
|
_mongoRunner.Dispose();
|
||||||
|
await _factory.DisposeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegisterServices(Action<IServiceCollection> services)
|
||||||
|
{
|
||||||
|
_testRegistrationServices = services;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ref: https://github.com/trbenning/serilog-sinks-xunit
|
// ref: https://github.com/trbenning/serilog-sinks-xunit
|
||||||
@ -260,7 +260,6 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private ITestHarness CreateHarness()
|
private ITestHarness CreateHarness()
|
||||||
{
|
{
|
||||||
var harness = _serviceProvider.GetTestHarness();
|
var harness = _serviceProvider.GetTestHarness();
|
||||||
harness.Start().GetAwaiter().GetResult();
|
|
||||||
return harness;
|
return harness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parallelizeAssembly": false,
|
||||||
|
"parallelizeTestCollections": false
|
||||||
|
}
|
||||||
@ -7,13 +7,10 @@ using MassTransit.Testing;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Aircraft.Features;
|
namespace Integration.Test.Aircraft.Features;
|
||||||
|
public class CreateAircraftTests : IClassFixture<IntegrationTestFixture>
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
|
||||||
public class CreateAircraftTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
|
|
||||||
public CreateAircraftTests(IntegrationTestFixture fixture)
|
public CreateAircraftTests(IntegrationTestFixture fixture)
|
||||||
{
|
{
|
||||||
_fixture = fixture;
|
_fixture = fixture;
|
||||||
|
|||||||
@ -7,9 +7,7 @@ using MassTransit.Testing;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Airport.Features;
|
namespace Integration.Test.Airport.Features;
|
||||||
|
public class CreateAirportTests : IClassFixture<IntegrationTestFixture>
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
|
||||||
public class CreateAirportTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
|
|||||||
@ -8,8 +8,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class CreateFlightTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class CreateFlightTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
@ -17,7 +16,7 @@ public class CreateFlightTests
|
|||||||
public CreateFlightTests(IntegrationTestFixture fixture)
|
public CreateFlightTests(IntegrationTestFixture fixture)
|
||||||
{
|
{
|
||||||
_fixture = fixture;
|
_fixture = fixture;
|
||||||
_testHarness = _fixture.TestHarness;
|
_testHarness = fixture.TestHarness;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -32,6 +31,7 @@ public class CreateFlightTests
|
|||||||
// Assert
|
// Assert
|
||||||
response.Should().NotBeNull();
|
response.Should().NotBeNull();
|
||||||
response?.FlightNumber.Should().Be(command.FlightNumber);
|
response?.FlightNumber.Should().Be(command.FlightNumber);
|
||||||
|
|
||||||
(await _testHarness.Published.Any<Fault<FlightCreated>>()).Should().BeFalse();
|
(await _testHarness.Published.Any<Fault<FlightCreated>>()).Should().BeFalse();
|
||||||
(await _testHarness.Published.Any<FlightCreated>()).Should().BeTrue();
|
(await _testHarness.Published.Any<FlightCreated>()).Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class DeleteFlightTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class DeleteFlightTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
|
|||||||
@ -10,8 +10,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class GetAvailableFlightsTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class GetAvailableFlightsTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly GrpcChannel _channel;
|
private readonly GrpcChannel _channel;
|
||||||
|
|||||||
@ -9,8 +9,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class GetFlightByIdTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class GetFlightByIdTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly GrpcChannel _channel;
|
private readonly GrpcChannel _channel;
|
||||||
|
|||||||
@ -7,9 +7,7 @@ using MassTransit.Testing;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Flight.Features;
|
namespace Integration.Test.Flight.Features;
|
||||||
|
public class UpdateFlightTests : IClassFixture<IntegrationTestFixture>
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
|
||||||
public class UpdateFlightTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
@ -17,7 +15,7 @@ public class UpdateFlightTests
|
|||||||
public UpdateFlightTests(IntegrationTestFixture fixture)
|
public UpdateFlightTests(IntegrationTestFixture fixture)
|
||||||
{
|
{
|
||||||
_fixture = fixture;
|
_fixture = fixture;
|
||||||
_testHarness = _fixture.TestHarness;
|
_testHarness = fixture.TestHarness;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@ -5,6 +5,12 @@
|
|||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
||||||
|
|||||||
@ -25,11 +25,6 @@ using Xunit.Abstractions;
|
|||||||
|
|
||||||
namespace Integration.Test;
|
namespace Integration.Test;
|
||||||
|
|
||||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
|
||||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IntegrationTestFixture : IAsyncLifetime
|
public class IntegrationTestFixture : IAsyncLifetime
|
||||||
{
|
{
|
||||||
private Checkpoint _checkpoint;
|
private Checkpoint _checkpoint;
|
||||||
@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private MongoDbRunner _mongoRunner;
|
private MongoDbRunner _mongoRunner;
|
||||||
private IServiceProvider _serviceProvider;
|
private IServiceProvider _serviceProvider;
|
||||||
private Action<IServiceCollection>? _testRegistrationServices;
|
private Action<IServiceCollection>? _testRegistrationServices;
|
||||||
public HttpClient HttpClient => _factory.CreateClient();
|
public ITestHarness TestHarness { get; private set; }
|
||||||
public ITestHarness TestHarness => CreateHarness();
|
public HttpClient HttpClient { get; private set; }
|
||||||
public GrpcChannel Channel => CreateChannel();
|
public GrpcChannel Channel { get; private set; }
|
||||||
|
|
||||||
|
public Task InitializeAsync()
|
||||||
public virtual Task InitializeAsync()
|
|
||||||
{
|
{
|
||||||
_factory = new WebApplicationFactory<Program>()
|
_factory = new WebApplicationFactory<Program>()
|
||||||
.WithWebHostBuilder(builder =>
|
.WithWebHostBuilder(builder =>
|
||||||
@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
_serviceProvider = _factory.Services;
|
_serviceProvider = _factory.Services;
|
||||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||||
|
|
||||||
|
HttpClient = _factory.CreateClient();
|
||||||
|
Channel = CreateChannel();
|
||||||
|
TestHarness = CreateHarness();
|
||||||
|
|
||||||
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
|
|
||||||
_mongoRunner = MongoDbRunner.Start();
|
_mongoRunner = MongoDbRunner.Start();
|
||||||
@ -88,13 +86,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
return Task.CompletedTask;
|
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 _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection"));
|
|
||||||
|
|
||||||
await _factory.DisposeAsync();
|
|
||||||
_mongoRunner.Dispose();
|
_mongoRunner.Dispose();
|
||||||
|
await _factory.DisposeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterServices(Action<IServiceCollection> services)
|
public void RegisterServices(Action<IServiceCollection> services)
|
||||||
@ -255,7 +251,6 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private ITestHarness CreateHarness()
|
private ITestHarness CreateHarness()
|
||||||
{
|
{
|
||||||
var harness = _serviceProvider.GetTestHarness();
|
var harness = _serviceProvider.GetTestHarness();
|
||||||
harness.Start().GetAwaiter().GetResult();
|
|
||||||
return harness;
|
return harness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Seat.Features;
|
namespace Integration.Test.Seat.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class GetAvailableSeatsTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class GetAvailableSeatsTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly GrpcChannel _channel;
|
private readonly GrpcChannel _channel;
|
||||||
|
|||||||
@ -7,9 +7,7 @@ using MagicOnion.Client;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Integration.Test.Seat.Features;
|
namespace Integration.Test.Seat.Features;
|
||||||
|
public class ReserveSeatTests : IClassFixture<IntegrationTestFixture>
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
|
||||||
public class ReserveSeatTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly GrpcChannel _channel;
|
private readonly GrpcChannel _channel;
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parallelizeAssembly": false,
|
||||||
|
"parallelizeTestCollections": false
|
||||||
|
}
|
||||||
@ -5,6 +5,12 @@
|
|||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<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;
|
namespace Integration.Test.Identity.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class RegisterNewUserTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class RegisterNewUserTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
|
|||||||
@ -5,6 +5,11 @@
|
|||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||||
|
|||||||
@ -25,11 +25,6 @@ using Xunit.Abstractions;
|
|||||||
|
|
||||||
namespace Integration.Test;
|
namespace Integration.Test;
|
||||||
|
|
||||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
|
||||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IntegrationTestFixture : IAsyncLifetime
|
public class IntegrationTestFixture : IAsyncLifetime
|
||||||
{
|
{
|
||||||
private Checkpoint _checkpoint;
|
private Checkpoint _checkpoint;
|
||||||
@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private MongoDbRunner _mongoRunner;
|
private MongoDbRunner _mongoRunner;
|
||||||
private IServiceProvider _serviceProvider;
|
private IServiceProvider _serviceProvider;
|
||||||
private Action<IServiceCollection>? _testRegistrationServices;
|
private Action<IServiceCollection>? _testRegistrationServices;
|
||||||
public HttpClient HttpClient => _factory.CreateClient();
|
public ITestHarness TestHarness { get; private set; }
|
||||||
public ITestHarness TestHarness => CreateHarness();
|
public HttpClient HttpClient { get; private set; }
|
||||||
public GrpcChannel Channel => CreateChannel();
|
public GrpcChannel Channel { get; private set; }
|
||||||
|
|
||||||
|
public Task InitializeAsync()
|
||||||
public virtual Task InitializeAsync()
|
|
||||||
{
|
{
|
||||||
_factory = new WebApplicationFactory<Program>()
|
_factory = new WebApplicationFactory<Program>()
|
||||||
.WithWebHostBuilder(builder =>
|
.WithWebHostBuilder(builder =>
|
||||||
@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
_serviceProvider = _factory.Services;
|
_serviceProvider = _factory.Services;
|
||||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||||
|
|
||||||
|
HttpClient = _factory.CreateClient();
|
||||||
|
Channel = CreateChannel();
|
||||||
|
TestHarness = CreateHarness();
|
||||||
|
|
||||||
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
|
|
||||||
_mongoRunner = MongoDbRunner.Start();
|
_mongoRunner = MongoDbRunner.Start();
|
||||||
@ -88,13 +86,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
return Task.CompletedTask;
|
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 _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection"));
|
|
||||||
|
|
||||||
await _factory.DisposeAsync();
|
|
||||||
_mongoRunner.Dispose();
|
_mongoRunner.Dispose();
|
||||||
|
await _factory.DisposeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterServices(Action<IServiceCollection> services)
|
public void RegisterServices(Action<IServiceCollection> services)
|
||||||
@ -106,11 +102,9 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
public ILogger CreateLogger(ITestOutputHelper output)
|
public ILogger CreateLogger(ITestOutputHelper output)
|
||||||
{
|
{
|
||||||
if (output != null)
|
if (output != null)
|
||||||
{
|
|
||||||
return new LoggerConfiguration()
|
return new LoggerConfiguration()
|
||||||
.WriteTo.TestOutput(output)
|
.WriteTo.TestOutput(output)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -255,7 +249,6 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private ITestHarness CreateHarness()
|
private ITestHarness CreateHarness()
|
||||||
{
|
{
|
||||||
var harness = _serviceProvider.GetTestHarness();
|
var harness = _serviceProvider.GetTestHarness();
|
||||||
harness.Start().GetAwaiter().GetResult();
|
|
||||||
return harness;
|
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>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
|
||||||
|
|||||||
@ -25,11 +25,6 @@ using Xunit.Abstractions;
|
|||||||
|
|
||||||
namespace Integration.Test;
|
namespace Integration.Test;
|
||||||
|
|
||||||
[CollectionDefinition(nameof(IntegrationTestFixture))]
|
|
||||||
public class FixtureCollection : ICollectionFixture<IntegrationTestFixture>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IntegrationTestFixture : IAsyncLifetime
|
public class IntegrationTestFixture : IAsyncLifetime
|
||||||
{
|
{
|
||||||
private Checkpoint _checkpoint;
|
private Checkpoint _checkpoint;
|
||||||
@ -38,12 +33,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private MongoDbRunner _mongoRunner;
|
private MongoDbRunner _mongoRunner;
|
||||||
private IServiceProvider _serviceProvider;
|
private IServiceProvider _serviceProvider;
|
||||||
private Action<IServiceCollection>? _testRegistrationServices;
|
private Action<IServiceCollection>? _testRegistrationServices;
|
||||||
public HttpClient HttpClient => _factory.CreateClient();
|
public ITestHarness TestHarness { get; private set; }
|
||||||
public ITestHarness TestHarness => CreateHarness();
|
public HttpClient HttpClient { get; private set; }
|
||||||
public GrpcChannel Channel => CreateChannel();
|
public GrpcChannel Channel { get; private set; }
|
||||||
|
|
||||||
|
public Task InitializeAsync()
|
||||||
public virtual Task InitializeAsync()
|
|
||||||
{
|
{
|
||||||
_factory = new WebApplicationFactory<Program>()
|
_factory = new WebApplicationFactory<Program>()
|
||||||
.WithWebHostBuilder(builder =>
|
.WithWebHostBuilder(builder =>
|
||||||
@ -78,6 +72,10 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
_serviceProvider = _factory.Services;
|
_serviceProvider = _factory.Services;
|
||||||
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
|
||||||
|
|
||||||
|
HttpClient = _factory.CreateClient();
|
||||||
|
Channel = CreateChannel();
|
||||||
|
TestHarness = CreateHarness();
|
||||||
|
|
||||||
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
_checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||||
|
|
||||||
_mongoRunner = MongoDbRunner.Start();
|
_mongoRunner = MongoDbRunner.Start();
|
||||||
@ -88,13 +86,11 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
return Task.CompletedTask;
|
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 _checkpoint.Reset(_configuration?.GetConnectionString("DefaultConnection"));
|
|
||||||
|
|
||||||
await _factory.DisposeAsync();
|
|
||||||
_mongoRunner.Dispose();
|
_mongoRunner.Dispose();
|
||||||
|
await _factory.DisposeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterServices(Action<IServiceCollection> services)
|
public void RegisterServices(Action<IServiceCollection> services)
|
||||||
@ -255,7 +251,6 @@ public class IntegrationTestFixture : IAsyncLifetime
|
|||||||
private ITestHarness CreateHarness()
|
private ITestHarness CreateHarness()
|
||||||
{
|
{
|
||||||
var harness = _serviceProvider.GetTestHarness();
|
var harness = _serviceProvider.GetTestHarness();
|
||||||
harness.Start().GetAwaiter().GetResult();
|
|
||||||
return harness;
|
return harness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Passenger.Features;
|
namespace Integration.Test.Passenger.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class CompleteRegisterPassengerTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class CompleteRegisterPassengerTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
|
|||||||
@ -11,8 +11,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Integration.Test.Passenger.Features;
|
namespace Integration.Test.Passenger.Features;
|
||||||
|
|
||||||
[Collection(nameof(IntegrationTestFixture))]
|
public class GetPassengerByIdTests : IClassFixture<IntegrationTestFixture>
|
||||||
public class GetPassengerByIdTests
|
|
||||||
{
|
{
|
||||||
private readonly IntegrationTestFixture _fixture;
|
private readonly IntegrationTestFixture _fixture;
|
||||||
private readonly ITestHarness _testHarness;
|
private readonly ITestHarness _testHarness;
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"parallelizeAssembly": false,
|
||||||
|
"parallelizeTestCollections": false
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user