mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-10 17:59:38 +08:00
fix(TestBase):add postgres connection settings for Flight, Identity and Passenger
This commit is contained in:
parent
c91538493b
commit
1fb9558227
@ -0,0 +1,33 @@
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Aircraft.Features;
|
||||
|
||||
public class CreateAircraftTests : FlightIntegrationTestBase
|
||||
{
|
||||
public CreateAircraftTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_create_new_aircraft_to_db_and_publish_message_to_broker()
|
||||
{
|
||||
// Arrange
|
||||
var command = new FakeCreateAircraftCommand().Generate();
|
||||
|
||||
// Act
|
||||
var response = await Fixture.SendAsync(command);
|
||||
|
||||
// Assert
|
||||
response?.Id.Value.Should().Be(command.Id);
|
||||
|
||||
(await Fixture.WaitForPublishing<AircraftCreated>()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Airport.Features;
|
||||
|
||||
public class CreateAirportTests : FlightIntegrationTestBase
|
||||
{
|
||||
public CreateAirportTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_create_new_airport_to_db_and_publish_message_to_broker()
|
||||
{
|
||||
// Arrange
|
||||
var command = new FakeCreateAirportCommand().Generate();
|
||||
|
||||
// Act
|
||||
var response = await Fixture.SendAsync(command);
|
||||
|
||||
// Assert
|
||||
response?.Id.Should().Be(command.Id);
|
||||
|
||||
(await Fixture.WaitForPublishing<AirportCreated>()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
public class CreateFlightTests : FlightIntegrationTestBase
|
||||
{
|
||||
public CreateFlightTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_create_new_flight_to_db_and_publish_message_to_broker()
|
||||
{
|
||||
//Arrange
|
||||
var command = new FakeCreateFlightCommand().Generate();
|
||||
|
||||
// Act
|
||||
var response = await Fixture.SendAsync(command);
|
||||
|
||||
// Assert
|
||||
response.Should().NotBeNull();
|
||||
response?.Id.Should().Be(command.Id);
|
||||
|
||||
(await Fixture.WaitForPublishing<FlightCreated>()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
using global::Flight.Data.Seed;
|
||||
using global::Flight.Flights.Features.DeletingFlight.V1;
|
||||
using global::Flight.Flights.Models;
|
||||
using global::Flight.Flights.ValueObjects;
|
||||
|
||||
public class DeleteFlightTests : FlightIntegrationTestBase
|
||||
{
|
||||
public DeleteFlightTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_delete_flight_from_db()
|
||||
{
|
||||
// Arrange
|
||||
var flightEntity = await Fixture.FindAsync<Flight, FlightId>(InitialData.Flights.First().Id);
|
||||
var command = new DeleteFlight(flightEntity.Id.Value);
|
||||
|
||||
// Act
|
||||
await Fixture.SendAsync(command);
|
||||
var deletedFlight = (await Fixture.ExecuteDbContextAsync(db => db.Flights
|
||||
.Where(x => x.Id == FlightId.Of(command.Id))
|
||||
.IgnoreQueryFilters()
|
||||
.ToListAsync())
|
||||
).FirstOrDefault();
|
||||
|
||||
// Assert
|
||||
deletedFlight?.IsDeleted.Should().BeTrue();
|
||||
|
||||
(await Fixture.WaitForPublishing<FlightDeleted>()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
using global::Flight.Flights.Features.CreatingFlight.V1;
|
||||
using global::Flight.Flights.Features.GettingAvailableFlights.V1;
|
||||
|
||||
public class GetAvailableFlightsTests : FlightIntegrationTestBase
|
||||
{
|
||||
public GetAvailableFlightsTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_return_available_flights()
|
||||
{
|
||||
// Arrange
|
||||
var command = new FakeCreateFlightMongoCommand().Generate();
|
||||
|
||||
await Fixture.SendAsync(command);
|
||||
|
||||
var query = new GetAvailableFlights();
|
||||
|
||||
// Act
|
||||
var response = (await Fixture.SendAsync(query))?.FlightDtos?.ToList();
|
||||
|
||||
// Assert
|
||||
response?.Should().NotBeNull();
|
||||
response?.Count.Should().BeGreaterOrEqualTo(2);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Flight;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
using global::Flight.Flights.Features.GettingFlightById.V1;
|
||||
|
||||
public class GetFlightByIdTests : FlightIntegrationTestBase
|
||||
{
|
||||
public GetFlightByIdTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_retrive_a_flight_by_id_currectly()
|
||||
{
|
||||
//Arrange
|
||||
var command = new FakeCreateFlightMongoCommand().Generate();
|
||||
|
||||
await Fixture.SendAsync(command);
|
||||
|
||||
var query = new GetFlightById(command.Id);
|
||||
|
||||
// Act
|
||||
var response = await Fixture.SendAsync(query);
|
||||
|
||||
// Assert
|
||||
response.Should().NotBeNull();
|
||||
response?.FlightDto?.Id.Should().Be(command.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_retrive_a_flight_by_id_from_grpc_service()
|
||||
{
|
||||
//Arrange
|
||||
var command = new FakeCreateFlightMongoCommand().Generate();
|
||||
|
||||
await Fixture.SendAsync(command);
|
||||
|
||||
var flightGrpcClient = new FlightGrpcService.FlightGrpcServiceClient(Fixture.Channel);
|
||||
|
||||
// Act
|
||||
var response = await flightGrpcClient.GetByIdAsync(new GetByIdRequest { Id = command.Id.ToString() }).ResponseAsync;
|
||||
|
||||
// Assert
|
||||
response?.Should().NotBeNull();
|
||||
response?.FlightDto.Id.Should().Be(command.Id.ToString());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.TestBase;
|
||||
using Api;
|
||||
using Flight.Data;
|
||||
using FluentAssertions;
|
||||
using Integration.Test.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace Integration.Test.Flight.Features;
|
||||
|
||||
using System.Linq;
|
||||
using global::Flight.Data.Seed;
|
||||
using global::Flight.Flights.Models;
|
||||
using global::Flight.Flights.ValueObjects;
|
||||
|
||||
public class UpdateFlightTests : FlightIntegrationTestBase
|
||||
{
|
||||
public UpdateFlightTests(
|
||||
TestFixture<Program, FlightDbContext, FlightReadDbContext> integrationTestFactory) : base(integrationTestFactory)
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task should_update_flight_to_db_and_publish_message_to_broker()
|
||||
{
|
||||
// Arrange
|
||||
var flightEntity = await Fixture.FindAsync<Flight, FlightId>(InitialData.Flights.First().Id);
|
||||
var command = new FakeUpdateFlightCommand(flightEntity).Generate();
|
||||
|
||||
// Act
|
||||
var response = await Fixture.SendAsync(command);
|
||||
|
||||
// Assert
|
||||
response.Should().NotBeNull();
|
||||
response?.Id.Should().Be(flightEntity.Id);
|
||||
|
||||
(await Fixture.WaitForPublishing<FlightUpdated>()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
@ -339,6 +339,15 @@ where TEntryPoint : class
|
||||
new(
|
||||
"PostgresOptions:ConnectionString",
|
||||
PostgresTestcontainer.GetConnectionString()),
|
||||
new(
|
||||
"PostgresOptions:ConnectionString:Flight",
|
||||
PostgresTestcontainer.GetConnectionString()),
|
||||
new(
|
||||
"PostgresOptions:ConnectionString:Identity",
|
||||
PostgresTestcontainer.GetConnectionString()),
|
||||
new(
|
||||
"PostgresOptions:ConnectionString:Passenger",
|
||||
PostgresTestcontainer.GetConnectionString()),
|
||||
new(
|
||||
"PersistMessageOptions:ConnectionString",
|
||||
PostgresPersistTestContainer.GetConnectionString()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user