Files
Heimdall/tests/Heimdall.Application.Tests/Handlers/Vehicles/DeleteVehicleHandlerTests.cs
T

37 lines
1.3 KiB
C#
Raw Normal View History

using Heimdall.Application.Common;
using Heimdall.Application.Vehicles.Commands.DeleteVehicle;
using Heimdall.Application.Tests.Common;
using Heimdall.Domain.Entities;
using NSubstitute;
namespace Heimdall.Application.Tests.Handlers.Vehicles;
public class DeleteVehicleHandlerTests
{
[Fact]
public async Task Delete_vehicle_should_return_success()
{
var vehicle = new Vehicle("PLATE-1");
var context = Substitute.For<IApplicationDbContext>();
context.Vehicles.Returns(MockDbSetHelper.CreateFor<Vehicle>(new[] { vehicle }));
var handler = new DeleteVehicleCommandHandler(context);
var result = await handler.Handle(new DeleteVehicleCommand(vehicle.Id), CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
await context.Received(1).SaveChangesWithRetryAsync(Arg.Any<int>(), Arg.Any<CancellationToken>());
}
[Fact]
public async Task Delete_vehicle_not_found_should_return_not_found()
{
var context = Substitute.For<IApplicationDbContext>();
context.Vehicles.Returns(MockDbSetHelper.CreateFor<Vehicle>());
var handler = new DeleteVehicleCommandHandler(context);
var result = await handler.Handle(new DeleteVehicleCommand(Guid.NewGuid()), CancellationToken.None);
result.IsSuccess.ShouldBeFalse();
result.StatusCode.ShouldBe(404);
}
}