In progress
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteTask;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Application.Tests.Commands.DeleteTask;
|
||||
|
||||
public class DeleteTaskCommandHandlerTests
|
||||
{
|
||||
private readonly Mock<IProjectRepository> _projectRepositoryMock;
|
||||
private readonly Mock<IUnitOfWork> _unitOfWorkMock;
|
||||
private readonly DeleteTaskCommandHandler _handler;
|
||||
|
||||
public DeleteTaskCommandHandlerTests()
|
||||
{
|
||||
_projectRepositoryMock = new Mock<IProjectRepository>();
|
||||
_unitOfWorkMock = new Mock<IUnitOfWork>();
|
||||
_handler = new DeleteTaskCommandHandler(_projectRepositoryMock.Object, _unitOfWorkMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Delete_Task_Successfully()
|
||||
{
|
||||
// Arrange
|
||||
var userId = UserId.Create();
|
||||
var project = Project.Create("Test Project", "Description", "TST", userId);
|
||||
var epic = project.CreateEpic("Test Epic", "Epic Description", userId);
|
||||
var story = epic.CreateStory("Test Story", "Story Description", TaskPriority.Medium, userId);
|
||||
var task = story.CreateTask("Task to Delete", "Description", TaskPriority.Medium, userId);
|
||||
var taskId = task.Id;
|
||||
|
||||
_projectRepositoryMock
|
||||
.Setup(x => x.GetProjectWithTaskAsync(taskId, It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(project);
|
||||
|
||||
var command = new DeleteTaskCommand { TaskId = taskId.Value };
|
||||
|
||||
// Act
|
||||
await _handler.Handle(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
story.Tasks.Should().BeEmpty();
|
||||
_projectRepositoryMock.Verify(x => x.Update(project), Times.Once);
|
||||
_unitOfWorkMock.Verify(x => x.SaveChangesAsync(It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Fail_When_Task_Not_Found()
|
||||
{
|
||||
// Arrange
|
||||
var taskId = TaskId.Create();
|
||||
_projectRepositoryMock
|
||||
.Setup(x => x.GetProjectWithTaskAsync(taskId, It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync((Project?)null);
|
||||
|
||||
var command = new DeleteTaskCommand { TaskId = taskId.Value };
|
||||
|
||||
// Act
|
||||
Func<Task> act = async () => await _handler.Handle(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await act.Should().ThrowAsync<NotFoundException>()
|
||||
.WithMessage("*Task*");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user