From 7b1e1f0e4377d4fa6b2047d6ae06a2001eb4714c Mon Sep 17 00:00:00 2001 From: meysamhadeli Date: Tue, 24 May 2022 00:55:05 +0430 Subject: [PATCH] add passenger integration tests --- src/BuildingBlocks/BuildingBlocks.csproj | 204 +++++++++--------- .../Exception/AggregateNotFoundException.cs | 3 +- src/BuildingBlocks/Exception/AppException.cs | 13 +- .../Exception/BadRequestException.cs | 4 +- .../Exception/ConflictException.cs | 6 +- .../Exception/CustomException.cs | 16 +- .../Exception/GrpcExceptionInterceptor.cs | 7 - .../Exception/IdentityException.cs | 8 +- .../Exception/InternalServerException.cs | 9 +- .../Exception/NotFoundException.cs | 4 +- .../Exception/ProblemDetailsWithCode.cs | 8 + .../Exception/ValidationException.cs | 3 +- .../Extensions/ProblemDetailsExtensions.cs | 36 ++-- .../Fakes/FakeFlightCreated.cs | 14 ++ .../Features/GetAvailableFlightsTests.cs | 9 +- .../Flight/Features/GetFlightByIdTests.cs | 4 +- .../Flight/Features/UpdateFlightTests.cs | 5 +- .../IntegrationTest/Integration.Test.csproj | 8 +- .../20220309230648_initial.Designer.cs | 98 --------- .../Data/Migrations/20220416172933_Audit.cs | 85 -------- .../20220422175724_Update-EventId.Designer.cs | 139 ------------ .../20220422175724_Update-EventId.cs | 86 -------- ....cs => 20220523195643_initial.Designer.cs} | 50 +---- ...8_initial.cs => 20220523195643_initial.cs} | 28 +-- .../PassengerDbContextModelSnapshot.cs | 70 ------ .../RegisterNewUserConsumerHandler.cs | 2 +- .../Passenger/src/Passenger/Passenger.csproj | 6 +- .../CompleteRegisterPassengerCommand.cs | 7 +- ...CompleteRegisterPassengerCommandHandler.cs | 3 +- .../FakeCompleteRegisterPassengerCommand.cs | 18 ++ .../Fakes/FakePassengerCreated.cs | 12 ++ .../IntegrationTest/Fakes/FakeUserCreated.cs | 15 ++ .../Features/RegisterNewUserConsumerTests.cs | 33 +++ .../IntegrationTest/Integration.Test.csproj | 13 +- .../CompleteRegisterPassengerTests.cs | 45 ++++ .../Features/GetPassengerByIdTests.cs | 42 ++++ .../tests/IntegrationTest/UnitTest1.cs | 12 -- 37 files changed, 376 insertions(+), 749 deletions(-) create mode 100644 src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs create mode 100644 src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs delete mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.Designer.cs delete mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.cs delete mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.Designer.cs delete mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.cs rename src/Services/Passenger/src/Passenger/Data/Migrations/{20220416172933_Audit.Designer.cs => 20220523195643_initial.Designer.cs} (54%) rename src/Services/Passenger/src/Passenger/Data/Migrations/{20220309230648_initial.cs => 20220523195643_initial.cs} (53%) create mode 100644 src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs create mode 100644 src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs create mode 100644 src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs create mode 100644 src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs create mode 100644 src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs create mode 100644 src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs delete mode 100644 src/Services/Passenger/tests/IntegrationTest/UnitTest1.cs diff --git a/src/BuildingBlocks/BuildingBlocks.csproj b/src/BuildingBlocks/BuildingBlocks.csproj index 655ddae..5279832 100644 --- a/src/BuildingBlocks/BuildingBlocks.csproj +++ b/src/BuildingBlocks/BuildingBlocks.csproj @@ -7,126 +7,126 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + - - - - - - + + + + + + - - + + diff --git a/src/BuildingBlocks/Exception/AggregateNotFoundException.cs b/src/BuildingBlocks/Exception/AggregateNotFoundException.cs index 9ebadc9..1e6d015 100644 --- a/src/BuildingBlocks/Exception/AggregateNotFoundException.cs +++ b/src/BuildingBlocks/Exception/AggregateNotFoundException.cs @@ -2,9 +2,8 @@ namespace BuildingBlocks.Exception; public class AggregateNotFoundException : System.Exception { - public AggregateNotFoundException(string typeName, long id): base($"{typeName} with id '{id}' was not found") + public AggregateNotFoundException(string typeName, long id) : base($"{typeName} with id '{id}' was not found") { - } public static AggregateNotFoundException For(long id) diff --git a/src/BuildingBlocks/Exception/AppException.cs b/src/BuildingBlocks/Exception/AppException.cs index 397ce43..b2a6009 100644 --- a/src/BuildingBlocks/Exception/AppException.cs +++ b/src/BuildingBlocks/Exception/AppException.cs @@ -5,26 +5,19 @@ namespace BuildingBlocks.Exception; public class AppException : CustomException { - public AppException(string message, string code = default!) : base(message) + public AppException(string message, string code = null) : base(message, code: code) { - Code = code; } public AppException() : base() { } - public AppException(string message) : base(message) + public AppException(string message, HttpStatusCode statusCode, string code = null) : base(message, statusCode, code) { } - public AppException(string message, HttpStatusCode statusCode) : base(message, statusCode) + public AppException(string message, System.Exception innerException, string code = null) : base(message, innerException, code: code) { } - - public AppException(string message, System.Exception innerException) : base(message, innerException) - { - } - - public string Code { get; } } diff --git a/src/BuildingBlocks/Exception/BadRequestException.cs b/src/BuildingBlocks/Exception/BadRequestException.cs index f1fe597..bf37562 100644 --- a/src/BuildingBlocks/Exception/BadRequestException.cs +++ b/src/BuildingBlocks/Exception/BadRequestException.cs @@ -4,9 +4,9 @@ namespace BuildingBlocks.Exception { public class BadRequestException : CustomException { - public BadRequestException(string message) : base(message) + public BadRequestException(string message, string code = null) : base(message, code: code) { } } -} \ No newline at end of file +} diff --git a/src/BuildingBlocks/Exception/ConflictException.cs b/src/BuildingBlocks/Exception/ConflictException.cs index a2399c1..7da858d 100644 --- a/src/BuildingBlocks/Exception/ConflictException.cs +++ b/src/BuildingBlocks/Exception/ConflictException.cs @@ -2,10 +2,8 @@ namespace BuildingBlocks.Exception { public class ConflictException : CustomException { - public virtual string Code { get; } - public ConflictException(string message, string code = default!) : base(message) + public ConflictException(string message, string code = null) : base(message, code: code) { - Code = code; } } -} \ No newline at end of file +} diff --git a/src/BuildingBlocks/Exception/CustomException.cs b/src/BuildingBlocks/Exception/CustomException.cs index fb891c4..645bf50 100644 --- a/src/BuildingBlocks/Exception/CustomException.cs +++ b/src/BuildingBlocks/Exception/CustomException.cs @@ -2,28 +2,36 @@ using System.Net; namespace BuildingBlocks.Exception; -public class CustomException: System.Exception +public class CustomException : System.Exception { public CustomException( string message, - HttpStatusCode statusCode = HttpStatusCode.BadRequest) : base(message) + HttpStatusCode statusCode = HttpStatusCode.BadRequest, + string code = null) : base(message) { StatusCode = statusCode; + Code = code; } public CustomException( string message, System.Exception innerException, - HttpStatusCode statusCode = HttpStatusCode.BadRequest) : base(message, innerException) + HttpStatusCode statusCode = HttpStatusCode.BadRequest, + string code = null) : base(message, innerException) { StatusCode = statusCode; + Code = code; } public CustomException( - HttpStatusCode statusCode = HttpStatusCode.BadRequest) : base() + HttpStatusCode statusCode = HttpStatusCode.BadRequest, + string code = null) : base() { StatusCode = statusCode; + Code = code; } public HttpStatusCode StatusCode { get; } + + public string Code { get; } } diff --git a/src/BuildingBlocks/Exception/GrpcExceptionInterceptor.cs b/src/BuildingBlocks/Exception/GrpcExceptionInterceptor.cs index 83e37ba..50f3256 100644 --- a/src/BuildingBlocks/Exception/GrpcExceptionInterceptor.cs +++ b/src/BuildingBlocks/Exception/GrpcExceptionInterceptor.cs @@ -6,13 +6,6 @@ namespace BuildingBlocks.Exception; public class GrpcExceptionInterceptor : Interceptor { - private readonly ILogger _logger; - - public GrpcExceptionInterceptor(ILogger logger) - { - _logger = logger; - } - public override async Task UnaryServerHandler( TRequest request, ServerCallContext context, diff --git a/src/BuildingBlocks/Exception/IdentityException.cs b/src/BuildingBlocks/Exception/IdentityException.cs index 987cd05..65a9bb0 100644 --- a/src/BuildingBlocks/Exception/IdentityException.cs +++ b/src/BuildingBlocks/Exception/IdentityException.cs @@ -2,10 +2,10 @@ using System.Net; namespace BuildingBlocks.Exception; -public class IdentityException: CustomException +public class IdentityException : CustomException { - public IdentityException(string message = default, HttpStatusCode statusCode = default) - : base(message, statusCode) + public IdentityException(string message = default, HttpStatusCode statusCode = default, string code = null) + : base(message, statusCode, code) { } -} \ No newline at end of file +} diff --git a/src/BuildingBlocks/Exception/InternalServerException.cs b/src/BuildingBlocks/Exception/InternalServerException.cs index 963cebc..c370c8c 100644 --- a/src/BuildingBlocks/Exception/InternalServerException.cs +++ b/src/BuildingBlocks/Exception/InternalServerException.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Net; namespace BuildingBlocks.Exception { @@ -7,11 +8,11 @@ namespace BuildingBlocks.Exception { public InternalServerException() : base() { } - public InternalServerException(string message) : base(message) { } + public InternalServerException(string message, string code) : base(message, HttpStatusCode.InternalServerError, code: code) { } - public InternalServerException(string message, params object[] args) - : base(String.Format(CultureInfo.CurrentCulture, message, args)) + public InternalServerException(string message, string code = null, params object[] args) + : base(message:String.Format(CultureInfo.CurrentCulture, message, args, HttpStatusCode.InternalServerError, code)) { } } -} \ No newline at end of file +} diff --git a/src/BuildingBlocks/Exception/NotFoundException.cs b/src/BuildingBlocks/Exception/NotFoundException.cs index e9dc06b..86bb198 100644 --- a/src/BuildingBlocks/Exception/NotFoundException.cs +++ b/src/BuildingBlocks/Exception/NotFoundException.cs @@ -2,8 +2,8 @@ namespace BuildingBlocks.Exception { public class NotFoundException : CustomException { - public NotFoundException(string message) : base(message) + public NotFoundException(string message, string code = null) : base(message, code: code) { } } -} \ No newline at end of file +} diff --git a/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs b/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs new file mode 100644 index 0000000..841c5ad --- /dev/null +++ b/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc; + +namespace BuildingBlocks.Exception; + +public class ProblemDetailsWithCode : ProblemDetails +{ + public string Code { get; set; } +} diff --git a/src/BuildingBlocks/Exception/ValidationException.cs b/src/BuildingBlocks/Exception/ValidationException.cs index baaeb48..b7f7c6a 100644 --- a/src/BuildingBlocks/Exception/ValidationException.cs +++ b/src/BuildingBlocks/Exception/ValidationException.cs @@ -8,6 +8,7 @@ namespace BuildingBlocks.Exception { ValidationResultModel = validationResultModel; } + public ValidationResultModel ValidationResultModel { get; } } -} \ No newline at end of file +} diff --git a/src/Services/Flight/src/Flight/Extensions/ProblemDetailsExtensions.cs b/src/Services/Flight/src/Flight/Extensions/ProblemDetailsExtensions.cs index 78d224e..47cc909 100644 --- a/src/Services/Flight/src/Flight/Extensions/ProblemDetailsExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/ProblemDetailsExtensions.cs @@ -22,60 +22,66 @@ public static class ProblemDetailsExtensions var env = ctx.RequestServices.GetRequiredService(); return env.IsDevelopment() || env.IsStaging(); }; - x.Map(ex => new ProblemDetails + x.Map(ex => new ProblemDetailsWithCode { Title = "Application rule broken", Status = StatusCodes.Status409Conflict, Detail = ex.Message, - Type = "https://somedomain/application-rule-validation-error" + Type = "https://somedomain/application-rule-validation-error", + Code = ex.Code }); // Exception will produce and returns from our FluentValidation RequestValidationBehavior - x.Map(ex => new ProblemDetails + x.Map(ex => new ProblemDetailsWithCode { Title = "input validation rules broken", Status = StatusCodes.Status400BadRequest, Detail = JsonConvert.SerializeObject(ex.ValidationResultModel.Errors), - Type = "https://somedomain/input-validation-rules-error" + Type = "https://somedomain/input-validation-rules-error", + Code = ex.Code }); - x.Map(ex => new ProblemDetails + x.Map(ex => new ProblemDetailsWithCode { Title = "bad request exception", Status = StatusCodes.Status400BadRequest, Detail = ex.Message, - Type = "https://somedomain/bad-request-error" + Type = "https://somedomain/bad-request-error", + Code = ex.Code }); - x.Map(ex => new ProblemDetails + x.Map(ex => new ProblemDetailsWithCode { Title = "not found exception", Status = StatusCodes.Status404NotFound, Detail = ex.Message, - Type = "https://somedomain/not-found-error" + Type = "https://somedomain/not-found-error", + Code = ex.Code }); - x.Map(ex => new ProblemDetails + x.Map(ex => new ProblemDetailsWithCode { Title = "api server exception", Status = StatusCodes.Status500InternalServerError, Detail = ex.Message, - Type = "https://somedomain/api-server-error" + Type = "https://somedomain/api-server-error", + Code = ex.Code }); - x.Map(ex => new ProblemDetails + x.Map(ex => new ProblemDetailsWithCode { Title = "application exception", Status = StatusCodes.Status500InternalServerError, Detail = ex.Message, - Type = "https://somedomain/application-error" + Type = "https://somedomain/application-error", + Code = ex.Code }); x.Map(ex => { - var pd = new ProblemDetails + var pd = new ProblemDetailsWithCode { Status = (int)ex.StatusCode, Title = "identity exception", Detail = ex.Message, - Type = "https://somedomain/identity-error" + Type = "https://somedomain/identity-error", + Code = ex.Code }; - return pd; }); x.MapToStatusCode(StatusCodes.Status400BadRequest); diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs new file mode 100644 index 0000000..6281287 --- /dev/null +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs @@ -0,0 +1,14 @@ +using Flight.Flights.Features.CreateFlight; + +namespace Integration.Test.Fakes; + +public static class FakeFlightCreated +{ + public static global::Flight.Flights.Models.Flight Generate(CreateFlightCommand command) + { + 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); + } +} diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs index 30cc0a3..7f0a561 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetAvailableFlightsTests.cs @@ -24,13 +24,8 @@ public class GetAvailableFlightsTests var flightCommand1 = new FakeCreateFlightCommand().Generate(); var flightCommand2 = new FakeCreateFlightCommand().Generate(); - var flightEntity1 = global::Flight.Flights.Models.Flight.Create( - flightCommand1.Id, flightCommand1.FlightNumber, flightCommand1.AircraftId, flightCommand1.DepartureAirportId, flightCommand1.DepartureDate, - flightCommand1.ArriveDate, flightCommand1.ArriveAirportId, flightCommand1.DurationMinutes, flightCommand1.FlightDate, flightCommand1.Status, flightCommand1.Price); - - var flightEntity2 = global::Flight.Flights.Models.Flight.Create( - flightCommand2.Id, flightCommand2.FlightNumber, flightCommand2.AircraftId, flightCommand2.DepartureAirportId, flightCommand2.DepartureDate, - flightCommand2.ArriveDate, flightCommand2.ArriveAirportId, flightCommand2.DurationMinutes, flightCommand2.FlightDate, flightCommand2.Status, flightCommand2.Price); + var flightEntity1 = FakeFlightCreated.Generate(flightCommand1); + var flightEntity2 = FakeFlightCreated.Generate(flightCommand2); await _fixture.InsertAsync(flightEntity1, flightEntity2); diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs index 7de000d..489356c 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs @@ -21,9 +21,7 @@ public class GetFlightByIdTests { // Arrange var command = new FakeCreateFlightCommand().Generate(); - var flightEntity = 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); + var flightEntity = FakeFlightCreated.Generate(command); await _fixture.InsertAsync(flightEntity); var query = new GetFlightByIdQuery(flightEntity.Id); diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs index 9393bb2..1a03c7c 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs @@ -25,10 +25,7 @@ public class UpdateFlightTests { // Arrange var fakeCreateCommandFlight = new FakeCreateFlightCommand().Generate(); - var flightEntity = global::Flight.Flights.Models.Flight.Create(fakeCreateCommandFlight.Id, fakeCreateCommandFlight.FlightNumber, - fakeCreateCommandFlight.AircraftId, fakeCreateCommandFlight.DepartureAirportId, fakeCreateCommandFlight.DepartureDate, - fakeCreateCommandFlight.ArriveDate, fakeCreateCommandFlight.ArriveAirportId, fakeCreateCommandFlight.DurationMinutes, - fakeCreateCommandFlight.FlightDate, fakeCreateCommandFlight.Status, fakeCreateCommandFlight.Price); + var flightEntity = FakeFlightCreated.Generate(fakeCreateCommandFlight); await _fixture.InsertAsync(flightEntity); var command = new FakeUpdateFlightCommand(flightEntity.Id).Generate(); diff --git a/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj index 13598de..4053e9a 100644 --- a/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj @@ -6,10 +6,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.Designer.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.Designer.cs deleted file mode 100644 index 49f2c4f..0000000 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.Designer.cs +++ /dev/null @@ -1,98 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Passenger.Data; - -#nullable disable - -namespace Passenger.Data.Migrations -{ - [DbContext(typeof(PassengerDbContext))] - [Migration("20220309230648_initial")] - partial class initial - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - - modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("CorrelationId") - .HasColumnType("uniqueidentifier"); - - b.Property("Data") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EventType") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OccurredOn") - .HasColumnType("datetime2"); - - b.Property("ProcessedOn") - .HasColumnType("datetime2"); - - b.Property("Type") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("OutboxMessages", (string)null); - }); - - modelBuilder.Entity("Passenger.Passenger.Models.Passenger", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("Age") - .HasColumnType("int"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("ModifiedBy") - .HasColumnType("int"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PassengerType") - .HasColumnType("int"); - - b.Property("PassportNumber") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Passenger", "dbo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.cs deleted file mode 100644 index 7cd1aaa..0000000 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Passenger.Data.Migrations -{ - public partial class Audit : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "ModifiedBy", - schema: "dbo", - table: "Passenger", - newName: "LastModifiedBy"); - - migrationBuilder.AlterColumn( - name: "LastModified", - schema: "dbo", - table: "Passenger", - type: "datetime2", - nullable: true, - oldClrType: typeof(DateTime), - oldType: "datetime2"); - - migrationBuilder.AddColumn( - name: "CreatedAt", - schema: "dbo", - table: "Passenger", - type: "datetime2", - nullable: true); - - migrationBuilder.AddColumn( - name: "CreatedBy", - schema: "dbo", - table: "Passenger", - type: "int", - nullable: true); - - migrationBuilder.AddColumn( - name: "Version", - schema: "dbo", - table: "Passenger", - type: "bigint", - nullable: false, - defaultValue: 0L); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CreatedAt", - schema: "dbo", - table: "Passenger"); - - migrationBuilder.DropColumn( - name: "CreatedBy", - schema: "dbo", - table: "Passenger"); - - migrationBuilder.DropColumn( - name: "Version", - schema: "dbo", - table: "Passenger"); - - migrationBuilder.RenameColumn( - name: "LastModifiedBy", - schema: "dbo", - table: "Passenger", - newName: "ModifiedBy"); - - migrationBuilder.AlterColumn( - name: "LastModified", - schema: "dbo", - table: "Passenger", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - oldClrType: typeof(DateTime), - oldType: "datetime2", - oldNullable: true); - } - } -} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.Designer.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.Designer.cs deleted file mode 100644 index 0628c6a..0000000 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.Designer.cs +++ /dev/null @@ -1,139 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Passenger.Data; - -#nullable disable - -namespace Passenger.Data.Migrations -{ - [DbContext(typeof(PassengerDbContext))] - [Migration("20220422175724_Update-EventId")] - partial class UpdateEventId - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - - modelBuilder.Entity("BuildingBlocks.InternalProcessor.InternalMessage", b => - { - b.Property("EventId") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("CommandType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CorrelationId") - .HasColumnType("uniqueidentifier"); - - b.Property("Data") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OccurredOn") - .HasColumnType("datetime2"); - - b.Property("ProcessedOn") - .HasColumnType("datetime2"); - - b.HasKey("EventId"); - - b.ToTable("InternalMessages", (string)null); - }); - - modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b => - { - b.Property("EventId") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("CorrelationId") - .HasColumnType("uniqueidentifier"); - - b.Property("Data") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EventType") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OccurredOn") - .HasColumnType("datetime2"); - - b.Property("ProcessedOn") - .HasColumnType("datetime2"); - - b.Property("Type") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("EventId"); - - b.ToTable("OutboxMessages", (string)null); - }); - - modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("Age") - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasColumnType("bigint"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("LastModifiedBy") - .HasColumnType("bigint"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PassengerType") - .HasColumnType("int"); - - b.Property("PassportNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.ToTable("Passenger", "dbo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.cs deleted file mode 100644 index 39709fb..0000000 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20220422175724_Update-EventId.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Passenger.Data.Migrations -{ - public partial class UpdateEventId : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "Id", - table: "OutboxMessages", - newName: "EventId"); - - migrationBuilder.AlterColumn( - name: "LastModifiedBy", - schema: "dbo", - table: "Passenger", - type: "bigint", - nullable: true, - oldClrType: typeof(int), - oldType: "int", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "CreatedBy", - schema: "dbo", - table: "Passenger", - type: "bigint", - nullable: true, - oldClrType: typeof(int), - oldType: "int", - oldNullable: true); - - migrationBuilder.CreateTable( - name: "InternalMessages", - columns: table => new - { - EventId = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - OccurredOn = table.Column(type: "datetime2", nullable: false), - CommandType = table.Column(type: "nvarchar(max)", nullable: false), - Data = table.Column(type: "nvarchar(max)", nullable: false), - ProcessedOn = table.Column(type: "datetime2", nullable: true), - CorrelationId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_InternalMessages", x => x.EventId); - }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "InternalMessages"); - - migrationBuilder.RenameColumn( - name: "EventId", - table: "OutboxMessages", - newName: "Id"); - - migrationBuilder.AlterColumn( - name: "LastModifiedBy", - schema: "dbo", - table: "Passenger", - type: "int", - nullable: true, - oldClrType: typeof(long), - oldType: "bigint", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "CreatedBy", - schema: "dbo", - table: "Passenger", - type: "int", - nullable: true, - oldClrType: typeof(long), - oldType: "bigint", - oldNullable: true); - } - } -} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.Designer.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20220523195643_initial.Designer.cs similarity index 54% rename from src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.Designer.cs rename to src/Services/Passenger/src/Passenger/Data/Migrations/20220523195643_initial.Designer.cs index 7398d42..9e7744e 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20220416172933_Audit.Designer.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/20220523195643_initial.Designer.cs @@ -12,8 +12,8 @@ using Passenger.Data; namespace Passenger.Data.Migrations { [DbContext(typeof(PassengerDbContext))] - [Migration("20220416172933_Audit")] - partial class Audit + [Migration("20220523195643_initial")] + partial class initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -24,44 +24,6 @@ namespace Passenger.Data.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("CorrelationId") - .HasColumnType("uniqueidentifier"); - - b.Property("Data") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EventType") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OccurredOn") - .HasColumnType("datetime2"); - - b.Property("ProcessedOn") - .HasColumnType("datetime2"); - - b.Property("Type") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("OutboxMessages", (string)null); - }); - modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => { b.Property("Id") @@ -73,8 +35,8 @@ namespace Passenger.Data.Migrations b.Property("CreatedAt") .HasColumnType("datetime2"); - b.Property("CreatedBy") - .HasColumnType("int"); + b.Property("CreatedBy") + .HasColumnType("bigint"); b.Property("IsDeleted") .HasColumnType("bit"); @@ -82,8 +44,8 @@ namespace Passenger.Data.Migrations b.Property("LastModified") .HasColumnType("datetime2"); - b.Property("LastModifiedBy") - .HasColumnType("int"); + b.Property("LastModifiedBy") + .HasColumnType("bigint"); b.Property("Name") .HasColumnType("nvarchar(max)"); diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20220523195643_initial.cs similarity index 53% rename from src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.cs rename to src/Services/Passenger/src/Passenger/Data/Migrations/20220523195643_initial.cs index 9485856..cf5759c 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20220309230648_initial.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/20220523195643_initial.cs @@ -12,24 +12,6 @@ namespace Passenger.Data.Migrations migrationBuilder.EnsureSchema( name: "dbo"); - migrationBuilder.CreateTable( - name: "OutboxMessages", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - OccurredOn = table.Column(type: "datetime2", nullable: false), - Type = table.Column(type: "nvarchar(max)", nullable: false), - Data = table.Column(type: "nvarchar(max)", nullable: false), - ProcessedOn = table.Column(type: "datetime2", nullable: true), - EventType = table.Column(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false), - CorrelationId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_OutboxMessages", x => x.Id); - }); - migrationBuilder.CreateTable( name: "Passenger", schema: "dbo", @@ -40,9 +22,12 @@ namespace Passenger.Data.Migrations Name = table.Column(type: "nvarchar(max)", nullable: true), PassengerType = table.Column(type: "int", nullable: false), Age = table.Column(type: "int", nullable: false), - LastModified = table.Column(type: "datetime2", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: true), + CreatedBy = table.Column(type: "bigint", nullable: true), + LastModified = table.Column(type: "datetime2", nullable: true), + LastModifiedBy = table.Column(type: "bigint", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), - ModifiedBy = table.Column(type: "int", nullable: true) + Version = table.Column(type: "bigint", nullable: false) }, constraints: table => { @@ -52,9 +37,6 @@ namespace Passenger.Data.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( - name: "OutboxMessages"); - migrationBuilder.DropTable( name: "Passenger", schema: "dbo"); diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs index fb7dd22..df21933 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs @@ -22,76 +22,6 @@ namespace Passenger.Data.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - modelBuilder.Entity("BuildingBlocks.InternalProcessor.InternalMessage", b => - { - b.Property("EventId") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("CommandType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CorrelationId") - .HasColumnType("uniqueidentifier"); - - b.Property("Data") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OccurredOn") - .HasColumnType("datetime2"); - - b.Property("ProcessedOn") - .HasColumnType("datetime2"); - - b.HasKey("EventId"); - - b.ToTable("InternalMessages", (string)null); - }); - - modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b => - { - b.Property("EventId") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("CorrelationId") - .HasColumnType("uniqueidentifier"); - - b.Property("Data") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EventType") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OccurredOn") - .HasColumnType("datetime2"); - - b.Property("ProcessedOn") - .HasColumnType("datetime2"); - - b.Property("Type") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("EventId"); - - b.ToTable("OutboxMessages", (string)null); - }); - modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => { b.Property("Id") diff --git a/src/Services/Passenger/src/Passenger/Identity/RegisterNewUser/RegisterNewUserConsumerHandler.cs b/src/Services/Passenger/src/Passenger/Identity/RegisterNewUser/RegisterNewUserConsumerHandler.cs index c754c1c..80107f7 100644 --- a/src/Services/Passenger/src/Passenger/Identity/RegisterNewUser/RegisterNewUserConsumerHandler.cs +++ b/src/Services/Passenger/src/Passenger/Identity/RegisterNewUser/RegisterNewUserConsumerHandler.cs @@ -19,7 +19,7 @@ public class RegisterNewUserConsumerHandler : IConsumer { Guard.Against.Null(context.Message, nameof(UserCreated)); - var passenger = Passengers.Models.Passenger.Create(context.Message.Id, context.Message.Name, context.Message.PassportNumber); + var passenger = Passengers.Models.Passenger.Create(SnowFlakIdGenerator.NewId(), context.Message.Name, context.Message.PassportNumber); await _passengerDbContext.AddAsync(passenger); diff --git a/src/Services/Passenger/src/Passenger/Passenger.csproj b/src/Services/Passenger/src/Passenger/Passenger.csproj index e7d7f7e..487d10d 100644 --- a/src/Services/Passenger/src/Passenger/Passenger.csproj +++ b/src/Services/Passenger/src/Passenger/Passenger.csproj @@ -13,12 +13,12 @@ - - + + - + diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommand.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommand.cs index 556f53a..555dc3d 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommand.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommand.cs @@ -1,8 +1,11 @@ +using BuildingBlocks.IdsGenerator; using MediatR; using Passenger.Passengers.Dtos; using Passenger.Passengers.Models; namespace Passenger.Passengers.Features.CompleteRegisterPassenger; -public record CompleteRegisterPassengerCommand - (string PassportNumber, PassengerType PassengerType, int Age) : IRequest; +public record CompleteRegisterPassengerCommand(string PassportNumber, PassengerType PassengerType, int Age) : IRequest +{ + public long Id { get; set; } = SnowFlakIdGenerator.NewId(); +} diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommandHandler.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommandHandler.cs index 0e5284f..55eaabd 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommandHandler.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/CompleteRegisterPassengerCommandHandler.cs @@ -24,8 +24,7 @@ public class CompleteRegisterPassengerCommandHandler : IRequestHandler x.PassportNumber == command.PassportNumber, - cancellationToken); + x => x.PassportNumber == command.PassportNumber, cancellationToken); if (passenger is null) throw new PassengerNotExist(); diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs new file mode 100644 index 0000000..e6035a9 --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs @@ -0,0 +1,18 @@ +using AutoBogus; +using BuildingBlocks.IdsGenerator; +using Passenger.Passengers.Features.CompleteRegisterPassenger; +using Passenger.Passengers.Models; + +namespace Integration.Test.Fakes; + +public sealed class FakeCompleteRegisterPassengerCommand : AutoFaker +{ + public FakeCompleteRegisterPassengerCommand(string passportNumber) + { + RuleFor(r => r.Id, _ => SnowFlakIdGenerator.NewId()); + RuleFor(r => r.PassportNumber, _ => passportNumber); + RuleFor(r => r.PassengerType, _ => PassengerType.Male); + RuleFor(r => r.Age, _ => 30); + } +} + diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs new file mode 100644 index 0000000..925d566 --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs @@ -0,0 +1,12 @@ +using BuildingBlocks.Contracts.EventBus.Messages; +using BuildingBlocks.IdsGenerator; + +namespace Integration.Test.Fakes; + +public static class FakePassengerCreated +{ + public static global::Passenger.Passengers.Models.Passenger Generate(UserCreated userCreated) + { + return global::Passenger.Passengers.Models.Passenger.Create(SnowFlakIdGenerator.NewId(), userCreated.Name, userCreated.PassportNumber); + } +} diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs new file mode 100644 index 0000000..b885954 --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs @@ -0,0 +1,15 @@ +using AutoBogus; +using BuildingBlocks.Contracts.EventBus.Messages; +using BuildingBlocks.IdsGenerator; + +namespace Integration.Test.Fakes; + +public class FakeUserCreated : AutoFaker +{ + public FakeUserCreated() + { + RuleFor(r => r.Id, _ => SnowFlakIdGenerator.NewId()); + RuleFor(r => r.Name, _ => "Meysam"); + RuleFor(r => r.PassportNumber, _ => "1299878"); + } +} diff --git a/src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs b/src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs new file mode 100644 index 0000000..fc065ce --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/Identity/Features/RegisterNewUserConsumerTests.cs @@ -0,0 +1,33 @@ +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(); + } +} diff --git a/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj index ff3abdc..91447ef 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj @@ -8,10 +8,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -26,9 +26,4 @@ - - - - - diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs new file mode 100644 index 0000000..a611663 --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs @@ -0,0 +1,45 @@ +using System.Threading.Tasks; +using BuildingBlocks.Contracts.EventBus.Messages; +using BuildingBlocks.IdsGenerator; +using FluentAssertions; +using Integration.Test.Fakes; +using MassTransit; +using MassTransit.Testing; +using Xunit; + +namespace Integration.Test.Passenger.Features; + +[Collection(nameof(TestFixture))] +public class CompleteRegisterPassengerTests +{ + private readonly TestFixture _fixture; + private readonly ITestHarness _testHarness; + + public CompleteRegisterPassengerTests(TestFixture fixture) + { + _fixture = fixture; + _testHarness = _fixture.TestHarness; + } + + [Fact] + public async Task should_complete_register_passenger_and_update_to_db() + { + // Arrange + var userCreated = new FakeUserCreated().Generate(); + await _testHarness.Bus.Publish(userCreated); + await _testHarness.Consumed.Any(); + await _fixture.InsertAsync(FakePassengerCreated.Generate(userCreated)); + + var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate(); + + // Act + var response = await _fixture.SendAsync(command); + + // Assert + response.Should().NotBeNull(); + response?.Name.Should().Be(userCreated.Name); + response?.PassportNumber.Should().Be(command.PassportNumber); + response?.PassengerType.Should().Be(command.PassengerType); + response?.Age.Should().Be(command.Age); + } +} diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs new file mode 100644 index 0000000..b78a923 --- /dev/null +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs @@ -0,0 +1,42 @@ +using System.Threading.Tasks; +using BuildingBlocks.Contracts.EventBus.Messages; +using FluentAssertions; +using Integration.Test.Fakes; +using MassTransit.Testing; +using Passenger.Passengers.Features.GetPassengerById; +using Xunit; + +namespace Integration.Test.Passenger.Features; + +[Collection(nameof(TestFixture))] +public class GetPassengerByIdTests +{ + private readonly TestFixture _fixture; + private readonly ITestHarness _testHarness; + + public GetPassengerByIdTests(TestFixture fixture) + { + _fixture = fixture; + _testHarness = _fixture.TestHarness; + } + + [Fact] + public async Task should_retrive_a_passenger_by_id_currectly() + { + // Arrange + var userCreated = new FakeUserCreated().Generate(); + await _testHarness.Bus.Publish(userCreated); + await _testHarness.Consumed.Any(); + var passengerEntity = FakePassengerCreated.Generate(userCreated); + await _fixture.InsertAsync(passengerEntity); + + var query = new GetPassengerQueryById(passengerEntity.Id); + + // Act + var response = await _fixture.SendAsync(query); + + // Assert + response.Should().NotBeNull(); + response?.Id.Should().Be(passengerEntity.Id); + } +} diff --git a/src/Services/Passenger/tests/IntegrationTest/UnitTest1.cs b/src/Services/Passenger/tests/IntegrationTest/UnitTest1.cs deleted file mode 100644 index 3b10395..0000000 --- a/src/Services/Passenger/tests/IntegrationTest/UnitTest1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Xunit; - -namespace Integration.Test; - -public class UnitTest1 -{ - [Fact] - public void Test1() - { - - } -} \ No newline at end of file