using Heimdall.Application.Common; using Heimdall.Application.Vehicles.Commands.CreateVehicle; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Vehicles; public class CreateVehicleHandlerTests { [Fact] public async Task Create_vehicle_should_return_success() { var context = Substitute.For(); context.Vehicles.Returns(MockDbSetHelper.CreateFor()); var handler = new CreateVehicleCommandHandler(context); var result = await handler.Handle( new CreateVehicleCommand("AB-123-CD", null, "Renault", "Clio", "Gris"), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.LicensePlate.ShouldBe("AB-123-CD"); result.Data.Make.ShouldBe("Renault"); result.Data.Model.ShouldBe("Clio"); result.Data.Color.ShouldBe("Gris"); await context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); } [Fact] public async Task Create_vehicle_with_person_should_store_person_id() { var personId = Guid.NewGuid(); var context = Substitute.For(); context.Vehicles.Returns(MockDbSetHelper.CreateFor()); var handler = new CreateVehicleCommandHandler(context); var result = await handler.Handle( new CreateVehicleCommand("XY-999-ZZ", personId, null, null, null), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data!.PersonId.ShouldBe(personId); } [Fact] public async Task Create_vehicle_minimal_should_succeed() { var context = Substitute.For(); context.Vehicles.Returns(MockDbSetHelper.CreateFor()); var handler = new CreateVehicleCommandHandler(context); var result = await handler.Handle( new CreateVehicleCommand(null, null, null, null, null), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.LicensePlate.ShouldBeNull(); } }