45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Heimdall.Application.Groups.Commands.RemoveCameraFromGroup;
|
|||
|
|
using Heimdall.Application.Common;
|
||
|
|
using Heimdall.Application.Tests.Common;
|
||
|
|
using Heimdall.Domain.Entities;
|
||
|
|
using NSubstitute;
|
||
|
|
using Shouldly;
|
||
|
|
|
||
|
|
namespace Heimdall.Application.Tests.Handlers.Groups;
|
||
|
|
|
||
|
|
public class RemoveCameraFromGroupHandlerTests
|
||
|
|
{
|
||
|
|
private readonly Guid _groupId = Guid.NewGuid();
|
||
|
|
private readonly Guid _cameraId = Guid.NewGuid();
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Remove_should_return_success()
|
||
|
|
{
|
||
|
|
var access = new GroupCameraAccess(_groupId, _cameraId);
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.GroupCameraAccesses.Returns(MockDbSetHelper.CreateFor([access]));
|
||
|
|
context.AuditLogs.Returns(Substitute.For<Microsoft.EntityFrameworkCore.DbSet<AuditLog>>());
|
||
|
|
|
||
|
|
var handler = new RemoveCameraFromGroupHandler(context);
|
||
|
|
var command = new RemoveCameraFromGroupCommand(_groupId, _cameraId);
|
||
|
|
|
||
|
|
var result = await handler.Handle(command, CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeTrue();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Remove_should_return_not_found_when_access_not_exists()
|
||
|
|
{
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.GroupCameraAccesses.Returns(MockDbSetHelper.CreateFor<GroupCameraAccess>([]));
|
||
|
|
|
||
|
|
var handler = new RemoveCameraFromGroupHandler(context);
|
||
|
|
var command = new RemoveCameraFromGroupCommand(_groupId, _cameraId);
|
||
|
|
|
||
|
|
var result = await handler.Handle(command, CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeFalse();
|
||
|
|
result.StatusCode.ShouldBe(404);
|
||
|
|
}
|
||
|
|
}
|