using Microsoft.AspNetCore.Mvc; using Nexus.Api.Controllers; using Nexus.Api.Data; using Nexus.Api.DTOs; using Nexus.Api.Models; using Nexus.Api.Services; using Xunit; namespace Nexus.Api.Tests; public sealed class ProjectRelationsTests { [Fact] public async Task GetTasks_ProjectsExistingAgentCorrelationFields() { var project = new Project { Id = Guid.NewGuid(), Name = "Release readiness" }; var task = new WorkTask { Id = Guid.NewGuid(), Title = "Verify release", State = "In progress", Priority = "High", ProjectId = project.Id, AssignedTo = "iris", ExpectedFrom = "iris", IsAgentTask = true }; var controller = new ProjectsController( new ProjectRelationsService(project, task)); var response = await controller.GetTasks(project.Id, CancellationToken.None); var ok = Assert.IsType(response.Result); var items = Assert.IsAssignableFrom>(ok.Value); var projected = Assert.Single(items); Assert.Equal(project.Id, projected.ProjectId); Assert.Equal("iris", projected.AssignedTo); Assert.Equal("iris", projected.ExpectedFrom); Assert.True(projected.IsAgentTask); } private sealed class ProjectRelationsService(Project project, WorkTask task) : IProjectService { public Task> GetAllAsync(CancellationToken ct = default) => Task.FromResult>([project]); public Task GetByIdAsync(Guid id, CancellationToken ct = default) => Task.FromResult(id == project.Id ? project : null); public Task> GetTasksAsync( Guid id, CancellationToken ct = default) => Task.FromResult>( id == project.Id ? [task] : []); public Task CreateAsync( CreateProjectRequest request, CancellationToken ct = default) => throw new NotSupportedException(); public Task UpdateAsync( Guid id, UpdateProjectRequest request, CancellationToken ct = default) => throw new NotSupportedException(); public Task DeleteAsync( Guid id, CancellationToken ct = default) => throw new NotSupportedException(); } }