-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeletePositionByIdCommandHandlerTests.cs
More file actions
43 lines (36 loc) · 1.8 KB
/
Copy pathDeletePositionByIdCommandHandlerTests.cs
File metadata and controls
43 lines (36 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace TalentManagementAPI.Application.Tests.Positions
{
public class DeletePositionByIdCommandHandlerTests
{
private readonly Mock<IPositionRepositoryAsync> _repositoryMock = new();
private readonly Mock<IEventDispatcher> _eventDispatcherMock = new();
[Fact]
public async Task Handle_ShouldDeletePosition()
{
var command = new DeletePositionByIdCommand { Id = Guid.NewGuid() };
var entity = new Position { Id = command.Id };
_repositoryMock.Setup(r => r.GetByIdAsync(command.Id)).ReturnsAsync(entity);
var handler = new DeletePositionByIdCommand.DeletePositionByIdCommandHandler(
_repositoryMock.Object,
_eventDispatcherMock.Object);
var result = await handler.Handle(command, CancellationToken.None);
result.IsSuccess.Should().BeTrue();
_repositoryMock.Verify(r => r.DeleteAsync(entity), Times.Once);
_eventDispatcherMock.Verify(s => s.PublishAsync(
It.Is<PositionChangedEvent>(e => e.PositionId == entity.Id),
It.IsAny<CancellationToken>()), Times.Once);
}
[Fact]
public async Task Handle_ShouldThrowWhenMissing()
{
var command = new DeletePositionByIdCommand { Id = Guid.NewGuid() };
_repositoryMock.Setup(r => r.GetByIdAsync(command.Id)).ReturnsAsync((Position)null!);
var handler = new DeletePositionByIdCommand.DeletePositionByIdCommandHandler(
_repositoryMock.Object,
_eventDispatcherMock.Object);
await FluentActions.Awaiting(() => handler.Handle(command, CancellationToken.None))
.Should().ThrowAsync<ApiException>()
.WithMessage("Position Not Found.");
}
}
}