mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-11 19:02:15 +08:00
fix bug booking test
This commit is contained in:
parent
d4ae8b3568
commit
b40c8ee2ce
@ -2,7 +2,6 @@
|
||||
using BuildingBlocks.Core.Event;
|
||||
using BuildingBlocks.Core.Model;
|
||||
using BuildingBlocks.EFCore;
|
||||
using BuildingBlocks.EventStoreDB.Projections;
|
||||
using BuildingBlocks.MassTransit;
|
||||
using BuildingBlocks.Mongo;
|
||||
using BuildingBlocks.PersistMessageProcessor;
|
||||
@ -51,7 +50,6 @@ public class IntegrationTestFixture<TEntryPoint> : IAsyncLifetime
|
||||
{
|
||||
TestRegistrationServices?.Invoke(services);
|
||||
services.ReplaceSingleton(AddHttpContextAccessorMock);
|
||||
services.Unregister<IProjectionProcessor>();
|
||||
services.AddMassTransitTestHarness(x =>
|
||||
{
|
||||
x.UsingRabbitMq((context, cfg) =>
|
||||
@ -327,6 +325,17 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
||||
private Checkpoint _checkpointPersistMessageDB;
|
||||
private MongoDbRunner _mongoRunner;
|
||||
|
||||
private string MongoConnectionString
|
||||
{
|
||||
get => Fixture.ServiceProvider.GetRequiredService<IOptions<MongoOptions>>()?.Value?.ConnectionString;
|
||||
set => Fixture.ServiceProvider.GetRequiredService<IOptions<MongoOptions>>().Value.ConnectionString = value;
|
||||
}
|
||||
|
||||
private string PersistConnectionString => Fixture.ServiceProvider
|
||||
.GetRequiredService<IOptions<PersistMessageOptions>>()?.Value.ConnectionString;
|
||||
|
||||
private string DefaultConnectionString => Fixture.Configuration?.GetConnectionString("DefaultConnection");
|
||||
|
||||
public IntegrationTestFixtureCore(IntegrationTestFixture<TEntryPoint> integrationTestFixture)
|
||||
{
|
||||
Fixture = integrationTestFixture;
|
||||
@ -341,17 +350,21 @@ public class IntegrationTestFixtureCore<TEntryPoint> : IAsyncLifetime
|
||||
_checkpointPersistMessageDB = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
|
||||
|
||||
_mongoRunner = MongoDbRunner.Start();
|
||||
var mongoOptions = Fixture.ServiceProvider.GetRequiredService<IOptions<MongoOptions>>();
|
||||
if (mongoOptions.Value.ConnectionString != null)
|
||||
mongoOptions.Value.ConnectionString = _mongoRunner.ConnectionString;
|
||||
|
||||
if (MongoConnectionString != null)
|
||||
MongoConnectionString = _mongoRunner.ConnectionString;
|
||||
|
||||
await SeedDataAsync();
|
||||
}
|
||||
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
await _checkpointDefaultDB.Reset(Fixture.Configuration?.GetConnectionString("DefaultConnection"));
|
||||
await _checkpointPersistMessageDB.Reset(Fixture.ServiceProvider.GetRequiredService<IOptions<PersistMessageOptions>>()?.Value?.ConnectionString);
|
||||
if (!string.IsNullOrEmpty(DefaultConnectionString))
|
||||
await _checkpointDefaultDB.Reset(DefaultConnectionString);
|
||||
|
||||
if (!string.IsNullOrEmpty(PersistConnectionString))
|
||||
await _checkpointPersistMessageDB.Reset(PersistConnectionString);
|
||||
|
||||
_mongoRunner.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@ -6,9 +6,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=db;Database=BookingDB;User ID=sa;Password=@Aa123456"
|
||||
},
|
||||
"RabbitMq": {
|
||||
"HostName": "rabbitmq",
|
||||
"ExchangeName": "booking",
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=.\\sqlexpress;Database=BookingDB_Test;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
},
|
||||
"RabbitMq": {
|
||||
"HostName": "localhost",
|
||||
"ExchangeName": "booking",
|
||||
@ -24,5 +21,8 @@
|
||||
"MongoOptions": {
|
||||
"ConnectionString": "mongodb://localhost:27017",
|
||||
"DatabaseName": "booking-db-test"
|
||||
},
|
||||
"EventStore": {
|
||||
"ConnectionString": "esdb://localhost:2113?tls=false"
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using Booking.Booking.Events.Domain;
|
||||
using Booking.Booking.Exceptions;
|
||||
using Booking.Booking.Models.ValueObjects;
|
||||
using BuildingBlocks.Contracts.Grpc;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.Core.CQRS;
|
||||
using BuildingBlocks.EventStoreDB.Repository;
|
||||
using BuildingBlocks.Utils;
|
||||
@ -14,17 +15,20 @@ public class CreateBookingCommandHandler : ICommandHandler<CreateBookingCommand,
|
||||
private readonly IEventStoreDBRepository<Models.Booking> _eventStoreDbRepository;
|
||||
private readonly IFlightGrpcService _flightGrpcService;
|
||||
private readonly ICurrentUserProvider _currentUserProvider;
|
||||
private readonly IEventDispatcher _eventDispatcher;
|
||||
private readonly IPassengerGrpcService _passengerGrpcService;
|
||||
|
||||
public CreateBookingCommandHandler(IEventStoreDBRepository<Models.Booking> eventStoreDbRepository,
|
||||
IPassengerGrpcService passengerGrpcService,
|
||||
IFlightGrpcService flightGrpcService,
|
||||
ICurrentUserProvider currentUserProvider)
|
||||
ICurrentUserProvider currentUserProvider,
|
||||
IEventDispatcher eventDispatcher)
|
||||
{
|
||||
_eventStoreDbRepository = eventStoreDbRepository;
|
||||
_passengerGrpcService = passengerGrpcService;
|
||||
_flightGrpcService = flightGrpcService;
|
||||
_currentUserProvider = currentUserProvider;
|
||||
_eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
public async Task<ulong> Handle(CreateBookingCommand command,
|
||||
@ -47,10 +51,12 @@ public class CreateBookingCommandHandler : ICommandHandler<CreateBookingCommand,
|
||||
throw new BookingAlreadyExistException();
|
||||
|
||||
var aggrigate = Models.Booking.Create(command.Id, new PassengerInfo(passenger.Name), new Trip(
|
||||
flight.FlightNumber, flight.AircraftId, flight.DepartureAirportId,
|
||||
flight.ArriveAirportId, flight.FlightDate, flight.Price, command.Description, emptySeat?.SeatNumber),
|
||||
flight.FlightNumber, flight.AircraftId, flight.DepartureAirportId,
|
||||
flight.ArriveAirportId, flight.FlightDate, flight.Price, command.Description, emptySeat?.SeatNumber),
|
||||
false, _currentUserProvider.GetCurrentUserId());
|
||||
|
||||
await _eventDispatcher.SendAsync(aggrigate.DomainEvents, cancellationToken: cancellationToken);
|
||||
|
||||
await _flightGrpcService.ReserveSeat(new ReserveSeatRequestDto
|
||||
{
|
||||
FlightId = flight.FlightId, SeatNumber = emptySeat?.SeatNumber
|
||||
|
||||
@ -3,12 +3,15 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Booking.Booking.Models.Reads;
|
||||
using Booking.Data;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.Contracts.Grpc;
|
||||
using BuildingBlocks.PersistMessageProcessor.Data;
|
||||
using BuildingBlocks.TestBase;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using MagicOnion;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using NSubstitute;
|
||||
@ -18,10 +21,12 @@ namespace Integration.Test.Booking.Features;
|
||||
|
||||
public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbContext, BookingReadDbContext>
|
||||
{
|
||||
private readonly ITestHarness _testHarness;
|
||||
public CreateBookingTests(
|
||||
IntegrationTestFixture<Program, PersistMessageDbContext, BookingReadDbContext> integrationTestFixture) : base(
|
||||
integrationTestFixture)
|
||||
{
|
||||
_testHarness = Fixture.TestHarness;
|
||||
}
|
||||
|
||||
protected override void RegisterTestsServices(IServiceCollection services)
|
||||
@ -42,6 +47,8 @@ public class CreateBookingTests : IntegrationTestBase<Program, PersistMessageDbC
|
||||
|
||||
// Assert
|
||||
response.Should().BeGreaterOrEqualTo(0);
|
||||
(await _testHarness.Published.Any<Fault<BookingCreated>>()).Should().BeFalse();
|
||||
(await _testHarness.Published.Any<BookingCreated>()).Should().BeTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user