Files
ColaFlow/colaflow-api/tests/ColaFlow.Application.Tests/Queries/GetStoryById/GetStoryByIdQueryHandlerTests.cs
Yaojia Wang 3232b70ecc fix(backend): Fix unit test compilation errors
Updated all unit tests to match updated method signatures after ProjectManagement Module refactoring.

Changes:
- Added TenantId parameter to Project.Create() calls in all test files
- Added TenantId parameter to ProjectCreatedEvent constructor calls
- Added IHostEnvironment and ILogger mock parameters to IdentityDbContext in Identity tests
- Fixed all test files in ColaFlow.Domain.Tests, ColaFlow.Application.Tests, and ColaFlow.Modules.Identity.Infrastructure.Tests

All tests now compile successfully with 0 errors (10 analyzer warnings only).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 10:28:01 +01:00

72 lines
2.7 KiB
C#

using FluentAssertions;
using Moq;
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoryById;
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.Queries.GetStoryById;
public class GetStoryByIdQueryHandlerTests
{
private readonly Mock<IProjectRepository> _projectRepositoryMock;
private readonly GetStoryByIdQueryHandler _handler;
public GetStoryByIdQueryHandlerTests()
{
_projectRepositoryMock = new Mock<IProjectRepository>();
_handler = new GetStoryByIdQueryHandler(_projectRepositoryMock.Object);
}
[Fact]
public async Task Should_Return_Story_With_Tasks()
{
// Arrange
var userId = UserId.Create();
var project = Project.Create(TenantId.Create(Guid.NewGuid()), "Test Project", "Description", "TST", userId);
var epic = project.CreateEpic("Test Epic", "Epic Description", userId);
var story = epic.CreateStory("Test Story", "Story Description", TaskPriority.High, userId);
var task1 = story.CreateTask("Task 1", "Description 1", TaskPriority.Medium, userId);
var task2 = story.CreateTask("Task 2", "Description 2", TaskPriority.Low, userId);
_projectRepositoryMock
.Setup(x => x.GetProjectWithStoryAsync(story.Id, It.IsAny<CancellationToken>()))
.ReturnsAsync(project);
var query = new GetStoryByIdQuery(story.Id.Value);
// Act
var result = await _handler.Handle(query, CancellationToken.None);
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(story.Id.Value);
result.Title.Should().Be("Test Story");
result.Description.Should().Be("Story Description");
result.Priority.Should().Be("High");
result.Tasks.Should().HaveCount(2);
result.Tasks.Should().Contain(t => t.Id == task1.Id.Value);
result.Tasks.Should().Contain(t => t.Id == task2.Id.Value);
}
[Fact]
public async Task Should_Fail_When_Story_Not_Found()
{
// Arrange
var storyId = StoryId.Create();
_projectRepositoryMock
.Setup(x => x.GetProjectWithStoryAsync(storyId, It.IsAny<CancellationToken>()))
.ReturnsAsync((Project?)null);
var query = new GetStoryByIdQuery(storyId.Value);
// Act
Func<Task> act = async () => await _handler.Handle(query, CancellationToken.None);
// Assert
await act.Should().ThrowAsync<NotFoundException>()
.WithMessage("*Story*");
}
}