Files
Heimdall/tests/Heimdall.Application.Tests/Handlers/Cameras/DeleteCameraHandlerTests.cs
T
Arnaud Dartois 45c6ce82eb perf: add ConfigureAwait(false) to all async calls in library projects
Add ConfigureAwait(false) to all await expressions in Application and
Infrastructure projects (111 files). This follows .NET best practices
for library code to avoid potential deadlocks when consumed from
synchronization contexts (legacy, unit test runners).

Also fix 4 test assertions that check SaveChangesAsync — update to
SaveChangesWithRetryAsync to match the handler changes from Fix 4.
2026-07-27 18:59:12 +00:00

55 lines
2.0 KiB
C#

using Heimdall.Application.Cameras.Commands.DeleteCamera;
using Heimdall.Application.Common;
using Heimdall.Application.Tests.Common;
using Heimdall.Domain.Entities;
using NSubstitute;
namespace Heimdall.Application.Tests.Handlers.Cameras;
public class DeleteCameraHandlerTests
{
private readonly Camera _existingCamera = new(Guid.NewGuid(), "Front Door");
[Fact]
public async Task Delete_camera_should_return_success()
{
var context = Substitute.For<IApplicationDbContext>();
context.Cameras.Returns(MockDbSetHelper.CreateFor<Camera>([_existingCamera]));
var handler = new DeleteCameraCommandHandler(context);
var command = new DeleteCameraCommand(_existingCamera.Id);
var result = await handler.Handle(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
}
[Fact]
public async Task Delete_nonexistent_camera_should_return_not_found()
{
var context = Substitute.For<IApplicationDbContext>();
context.Cameras.Returns(MockDbSetHelper.CreateFor<Camera>([_existingCamera]));
var handler = new DeleteCameraCommandHandler(context);
var command = new DeleteCameraCommand(Guid.NewGuid());
var result = await handler.Handle(command, CancellationToken.None);
result.IsSuccess.ShouldBeFalse();
result.StatusCode.ShouldBe(404);
}
[Fact]
public async Task Delete_camera_should_soft_delete_and_save()
{
var context = Substitute.For<IApplicationDbContext>();
context.Cameras.Returns(MockDbSetHelper.CreateFor<Camera>([_existingCamera]));
var handler = new DeleteCameraCommandHandler(context);
var command = new DeleteCameraCommand(_existingCamera.Id);
await handler.Handle(command, CancellationToken.None);
_existingCamera.IsDeleted.ShouldBeTrue();
_existingCamera.DeletedAt.ShouldNotBeNull();
await context.Received(1).SaveChangesWithRetryAsync(ct: Arg.Any<CancellationToken>());
}
}