mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-03 11:21:53 +08:00
commit
710146f6e8
@ -245,7 +245,7 @@ csharp_preserve_single_line_statements = false
|
|||||||
csharp_preserve_single_line_blocks = true
|
csharp_preserve_single_line_blocks = true
|
||||||
# Namespace options
|
# Namespace options
|
||||||
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#namespace-options
|
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#namespace-options
|
||||||
csharp_style_namespace_declarations = block_scoped:silent
|
csharp_style_namespace_declarations = file_scoped:warning
|
||||||
|
|
||||||
##########################################
|
##########################################
|
||||||
# .NET Naming Rules
|
# .NET Naming Rules
|
||||||
|
|||||||
38
src/BuildingBlocks/Utils/ServiceLocator.cs
Normal file
38
src/BuildingBlocks/Utils/ServiceLocator.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace BuildingBlocks.Utils;
|
||||||
|
|
||||||
|
//ref: https://dotnetcoretutorials.com/2018/05/06/servicelocator-shim-for-net-core/
|
||||||
|
public class ServiceLocator
|
||||||
|
{
|
||||||
|
private IServiceProvider _currentServiceProvider;
|
||||||
|
private static IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
|
public ServiceLocator(IServiceProvider currentServiceProvider)
|
||||||
|
{
|
||||||
|
_currentServiceProvider = currentServiceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServiceLocator Current
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new ServiceLocator(_serviceProvider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLocatorProvider(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetInstance(Type serviceType)
|
||||||
|
{
|
||||||
|
return _currentServiceProvider.GetService(serviceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TService GetInstance<TService>()
|
||||||
|
{
|
||||||
|
return _currentServiceProvider.GetService<TService>();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/Services/Flight/tests/UnitTest/Fakes/FakeFlightCreate.cs
Normal file
14
src/Services/Flight/tests/UnitTest/Fakes/FakeFlightCreate.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace Unit.Test.Fakes;
|
||||||
|
|
||||||
|
public static class FakeFlightCreate
|
||||||
|
{
|
||||||
|
public static global::Flight.Flights.Models.Flight Generate()
|
||||||
|
{
|
||||||
|
var command = new FakeCreateFlightCommand().Generate();
|
||||||
|
|
||||||
|
return global::Flight.Flights.Models.Flight.Create(command.Id, command.FlightNumber,
|
||||||
|
command.AircraftId, command.DepartureAirportId, command.DepartureDate,
|
||||||
|
command.ArriveDate, command.ArriveAirportId, command.DurationMinutes,
|
||||||
|
command.FlightDate, command.Status, command.Price);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/Services/Flight/tests/UnitTest/Fakes/FakeFlightUpdate.cs
Normal file
12
src/Services/Flight/tests/UnitTest/Fakes/FakeFlightUpdate.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace Unit.Test.Fakes;
|
||||||
|
|
||||||
|
using global::Flight.Flights.Models;
|
||||||
|
|
||||||
|
public static class FakeFlightUpdate
|
||||||
|
{
|
||||||
|
public static void Generate(Flight flight)
|
||||||
|
{
|
||||||
|
flight.Update(flight.Id, flight.FlightNumber, 3, flight.DepartureAirportId, flight.DepartureDate,
|
||||||
|
flight.ArriveDate, 3, flight.DurationMinutes, flight.FlightDate, flight.Status, flight.Price, flight.IsDeleted);;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,18 +1,15 @@
|
|||||||
using System;
|
namespace Unit.Test.Flight.Features.Commands.CreateFlight;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Flight.Flights.Dtos;
|
|
||||||
using Flight.Flights.Features.CreateFlight;
|
|
||||||
using Flight.Flights.Features.CreateFlight.Commands.V1;
|
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.AspNetCore.Http;
|
using global::Flight.Flights.Dtos;
|
||||||
using NSubstitute;
|
using global::Flight.Flights.Features.CreateFlight.Commands.V1;
|
||||||
using Unit.Test.Common;
|
using Unit.Test.Common;
|
||||||
using Unit.Test.Fakes;
|
using Unit.Test.Fakes;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Unit.Test.Flight.Features.CreateFlight;
|
|
||||||
|
|
||||||
[Collection(nameof(UnitTestFixture))]
|
[Collection(nameof(UnitTestFixture))]
|
||||||
public class CreateFlightCommandHandlerTests
|
public class CreateFlightCommandHandlerTests
|
||||||
{
|
{
|
||||||
@ -1,13 +1,12 @@
|
|||||||
using Flight.Flights.Features.CreateFlight;
|
namespace Unit.Test.Flight.Features.Commands.CreateFlight;
|
||||||
using Flight.Flights.Features.CreateFlight.Commands.V1;
|
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using FluentValidation.TestHelper;
|
using FluentValidation.TestHelper;
|
||||||
|
using global::Flight.Flights.Features.CreateFlight.Commands.V1;
|
||||||
using Unit.Test.Common;
|
using Unit.Test.Common;
|
||||||
using Unit.Test.Fakes;
|
using Unit.Test.Fakes;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Unit.Test.Flight.Features.CreateFlight;
|
|
||||||
|
|
||||||
[Collection(nameof(UnitTestFixture))]
|
[Collection(nameof(UnitTestFixture))]
|
||||||
public class CreateFlightCommandValidatorTests
|
public class CreateFlightCommandValidatorTests
|
||||||
{
|
{
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
namespace Unit.Test.Flight.Features.Domain
|
||||||
|
{
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using global::Flight.Flights.Features.CreateFlight.Events.Domain.V1;
|
||||||
|
using Unit.Test.Common;
|
||||||
|
using Unit.Test.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
[Collection(nameof(UnitTestFixture))]
|
||||||
|
public class CreateFlightTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void can_create_valid_flight()
|
||||||
|
{
|
||||||
|
// Arrange + Act
|
||||||
|
var fakeFlight = FakeFlightCreate.Generate();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
fakeFlight.Should().NotBeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void queue_domain_event_on_create()
|
||||||
|
{
|
||||||
|
// Arrange + Act
|
||||||
|
var fakeFlight = FakeFlightCreate.Generate();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
fakeFlight.DomainEvents.Count.Should().Be(1);
|
||||||
|
fakeFlight.DomainEvents.FirstOrDefault().Should().BeOfType(typeof(FlightCreatedDomainEvent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
namespace Unit.Test.Flight.Features.Domain;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using global::Flight.Flights.Features.UpdateFlight.Events.V1;
|
||||||
|
using Unit.Test.Common;
|
||||||
|
using Unit.Test.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
[Collection(nameof(UnitTestFixture))]
|
||||||
|
public class UpdateFlightTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void can_update_valid_flight()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var fakeFlight = FakeFlightCreate.Generate();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
FakeFlightUpdate.Generate(fakeFlight);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
fakeFlight.ArriveAirportId.Should().Be(3);
|
||||||
|
fakeFlight.AircraftId.Should().Be(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void queue_domain_event_on_update()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var fakeFlight = FakeFlightCreate.Generate();
|
||||||
|
fakeFlight.ClearDomainEvents();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
FakeFlightUpdate.Generate(fakeFlight);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
fakeFlight.DomainEvents.Count.Should().Be(1);
|
||||||
|
fakeFlight.DomainEvents.FirstOrDefault().Should().BeOfType(typeof(FlightUpdatedDomainEvent));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,4 +21,8 @@
|
|||||||
<ProjectReference Include="..\..\src\Flight.Api\Flight.Api.csproj" />
|
<ProjectReference Include="..\..\src\Flight.Api\Flight.Api.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Flight\Features\Commands" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user