From 936f886e547e395778890231346f14a8742b86f6 Mon Sep 17 00:00:00 2001 From: plockwood Date: Thu, 2 May 2024 14:34:30 +0100 Subject: [PATCH] Remove add note data command --- .../IncompleteProjectsGetDataQueryTests.cs | 8 +- .../ProjectNoteAddCommandTests.cs | 90 ------------------- .../IncompleteProjectsGetDataQuery.cs | 25 ------ .../ProjectAggregate/ProjectNoteAddCommand.cs | 30 ------- .../ConversionProjectRepository.cs | 8 ++ .../IConversionProjectRepository.cs | 2 + .../ProjectAggregate/Project.cs | 5 ++ .../IIncompleteProjectsGetDataQuery.cs | 9 -- .../IProjectNoteAddCommand.cs | 10 --- .../ProjectAggregate/IProject.cs | 1 + .../IConversionProjectExportService.cs | 3 +- .../Project/ITransferProjectExportService.cs | 2 +- .../ServiceModels}/GetProjectSearchModel.cs | 2 +- .../ConversionProjectSearchModel.cs | 2 +- .../TransferProjectSearchModel.cs | 2 +- .../Project/EnrichProjectCommandTests.cs | 11 +-- .../LegacyProjectAddNoteCommandTests.cs | 25 ++---- .../TransferProjectExportServiceTests.cs | 3 +- .../ConversionProjectAddNoteCommandHandler.cs | 21 ++--- .../Legacy/Project/EnrichProjectCommand.cs | 11 +-- .../Queries/ConversionProjectExportService.cs | 10 +-- .../Queries/TransferProjectExportService.cs | 1 - .../ApplicationSubmitTests.cs | 4 +- .../EnrichProjectCommandTests.cs | 4 +- .../LegacyProjectListGetTests.cs | 2 +- .../Controller/ExportControllerTests.cs | 3 +- .../ConversionProjectController.cs | 2 +- .../Controllers/ExportController.cs | 5 +- .../Controllers/ProjectController.cs | 2 +- .../Controllers/TransferProjectController.cs | 2 +- Dfe.Academies.Academisation.WebApi/Program.cs | 2 - 31 files changed, 74 insertions(+), 233 deletions(-) delete mode 100644 Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteAddCommandTests.cs delete mode 100644 Dfe.Academies.Academisation.Data/ProjectAggregate/IncompleteProjectsGetDataQuery.cs delete mode 100644 Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteAddCommand.cs delete mode 100644 Dfe.Academies.Academisation.IData/ProjectAggregate/IIncompleteProjectsGetDataQuery.cs delete mode 100644 Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteAddCommand.cs rename {Dfe.Academies.Academisation.Data/ProjectAggregate => Dfe.Academies.Academisation.IService/ServiceModels}/GetProjectSearchModel.cs (93%) rename {Dfe.Academies.Academisation.Data => Dfe.Academies.Academisation.IService/ServiceModels/Legacy}/ProjectAggregate/ConversionProjectSearchModel.cs (93%) rename {Dfe.Academies.Academisation.Data/ProjectAggregate => Dfe.Academies.Academisation.IService/ServiceModels/TransferProject}/TransferProjectSearchModel.cs (70%) diff --git a/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/IncompleteProjectsGetDataQueryTests.cs b/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/IncompleteProjectsGetDataQueryTests.cs index 8a92c0537..43f745f64 100644 --- a/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/IncompleteProjectsGetDataQueryTests.cs +++ b/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/IncompleteProjectsGetDataQueryTests.cs @@ -1,10 +1,13 @@ using System.Linq; using System.Threading.Tasks; using AutoFixture; +using AutoMapper; using Dfe.Academies.Academisation.Data.ProjectAggregate; +using Dfe.Academies.Academisation.Data.Repositories; using Dfe.Academies.Academisation.Data.UnitTest.Contexts; using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; +using Moq; using Xunit; namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate @@ -13,13 +16,14 @@ public class IncompleteProjectsGetDataQueryTests { private readonly Fixture _fixture = new(); - private readonly IncompleteProjectsGetDataQuery _subject; + private readonly ConversionProjectRepository _subject; private readonly AcademisationContext _context; + private Mock _mockMapper = new Mock(); public IncompleteProjectsGetDataQueryTests() { _context = new TestProjectContext().CreateContext(); - _subject = new IncompleteProjectsGetDataQuery(_context); + _subject = new ConversionProjectRepository(_context, _mockMapper.Object); } [Fact] diff --git a/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteAddCommandTests.cs b/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteAddCommandTests.cs deleted file mode 100644 index bedca7e9a..000000000 --- a/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteAddCommandTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using AutoFixture; -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Data.ProjectAggregate; -using Dfe.Academies.Academisation.Data.UnitTest.Contexts; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; -using FluentAssertions; -using System.Threading.Tasks; -using System; -using Xunit; -using Dfe.Academies.Academisation.Domain.ProjectAggregate; - -namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate -{ - public class ProjectNoteAddCommandTests - { - private readonly ProjectNote _newNote; - private readonly AcademisationContext _context; - private readonly Fixture _fixture; - - public ProjectNoteAddCommandTests() - { - _fixture = new Fixture(); - Project project = _fixture.Create(); - - var testProjectContext = new TestProjectContext(); - _context = testProjectContext.CreateContext(); - - _context.Projects.Add(project); - _context.SaveChanges(); - - _newNote = new ProjectNote( - "Subject", - "Note", - "Author", - DateTime.Today, - project.Id) - ; - } - - private ProjectNoteAddCommand System_under_test() - { - return new ProjectNoteAddCommand(_context); - } - - [Fact] - public async Task Should_return_not_found_result_if_the_specified_project_does_not_exist() - { - ProjectNote unknownNote = _fixture.Create(); - - ProjectNoteAddCommand command = System_under_test(); - - CommandResult result = await command.Execute( - unknownNote.ProjectId, - new ProjectNote(unknownNote.Subject, unknownNote.Note, unknownNote.Author, unknownNote.Date, unknownNote.ProjectId) - ); - - result.Should().BeOfType(); - - _context.ProjectNotes.Should().NotContainEquivalentOf(_newNote - , x => x.Excluding(q => q.Id)); - } - - [Fact] - public async Task Should_add_the_new_note_to_the_project() - { - ProjectNoteAddCommand command = System_under_test(); - - await command.Execute( - _newNote.ProjectId, - new ProjectNote(_newNote.Subject, _newNote.Note, _newNote.Author, _newNote.Date, _newNote.ProjectId) - ); - - _context.ProjectNotes.Should().ContainEquivalentOf( - _newNote, x => x.Excluding(q => q.Id)); - } - - [Fact] - public async Task Should_save_the_amended_project() - { - ProjectNoteAddCommand command = System_under_test(); - - CommandResult result = await command.Execute( - _newNote.ProjectId, - new ProjectNote(_newNote.Subject, _newNote.Note, _newNote.Author, _newNote.Date, _newNote.ProjectId) - ); - - result.Should().BeOfType(); - } - } -} diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/IncompleteProjectsGetDataQuery.cs b/Dfe.Academies.Academisation.Data/ProjectAggregate/IncompleteProjectsGetDataQuery.cs deleted file mode 100644 index 316512759..000000000 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/IncompleteProjectsGetDataQuery.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Dfe.Academies.Academisation.IData.ProjectAggregate; -using Dfe.Academies.Academisation.IDomain.ProjectAggregate; -using Microsoft.EntityFrameworkCore; - -namespace Dfe.Academies.Academisation.Data.ProjectAggregate -{ - public class IncompleteProjectsGetDataQuery : IIncompleteProjectsGetDataQuery - { - private readonly AcademisationContext _context; - - public IncompleteProjectsGetDataQuery(AcademisationContext context) - { - _context = context; - } - - public async Task?> GetIncompleteProjects() - { - var createdProjectState = await _context.Projects - .Where(p => string.IsNullOrEmpty(p.Details.LocalAuthority) || string.IsNullOrEmpty(p.Details.Region) || string.IsNullOrEmpty(p.Details.SchoolPhase) || string.IsNullOrEmpty(p.Details.SchoolType)) - .ToListAsync(); - - return createdProjectState; - } - } -} diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteAddCommand.cs b/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteAddCommand.cs deleted file mode 100644 index ebe5948e3..000000000 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteAddCommand.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; - -namespace Dfe.Academies.Academisation.Data.ProjectAggregate -{ - public class ProjectNoteAddCommand : IProjectNoteAddCommand - { - private readonly AcademisationContext _context; - - public ProjectNoteAddCommand(AcademisationContext context) - { - _context = context; - } - - public async Task Execute(int projectId, ProjectNote note) - { - if (_context.Projects.Any(x => x.Id == projectId) is false) - { - return new NotFoundCommandResult(); - } - - _context.ProjectNotes.Add(new ProjectNote (note.Subject, note.Note, note.Author,note.Date, projectId)); - - await _context.SaveChangesAsync(); - - return new CommandSuccessResult(); - } - } -} diff --git a/Dfe.Academies.Academisation.Data/Repositories/ConversionProjectRepository.cs b/Dfe.Academies.Academisation.Data/Repositories/ConversionProjectRepository.cs index 09f99bc6c..18729a6a4 100644 --- a/Dfe.Academies.Academisation.Data/Repositories/ConversionProjectRepository.cs +++ b/Dfe.Academies.Academisation.Data/Repositories/ConversionProjectRepository.cs @@ -89,6 +89,14 @@ private static IQueryable FilterFormAMAT(IQueryable queryable) return queryable; } + public async Task?> GetIncompleteProjects() + { + var createdProjectState = await _context.Projects + .Where(p => string.IsNullOrEmpty(p.Details.LocalAuthority) || string.IsNullOrEmpty(p.Details.Region) || string.IsNullOrEmpty(p.Details.SchoolPhase) || string.IsNullOrEmpty(p.Details.SchoolType)) + .ToListAsync(); + + return createdProjectState; + } private static IQueryable FilterByRegion(IEnumerable? regions, IQueryable queryable) { diff --git a/Dfe.Academies.Academisation.Domain/ProjectAggregate/IConversionProjectRepository.cs b/Dfe.Academies.Academisation.Domain/ProjectAggregate/IConversionProjectRepository.cs index 2d76605d5..d160615bd 100644 --- a/Dfe.Academies.Academisation.Domain/ProjectAggregate/IConversionProjectRepository.cs +++ b/Dfe.Academies.Academisation.Domain/ProjectAggregate/IConversionProjectRepository.cs @@ -19,4 +19,6 @@ public interface IConversionProjectRepository : IRepository, IGenericRe Task> GetConversionProjectsByFormAMatIds(IEnumerable ids, CancellationToken cancellationToken); Task<(IEnumerable projects, int totalCount)> SearchFormAMatProjects( IEnumerable? states, string? title, IEnumerable? deliveryOfficers, IEnumerable? regions, IEnumerable? localAuthorities, IEnumerable? advisoryBoardDates); + + Task?> GetIncompleteProjects(); } diff --git a/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs b/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs index 8f908e871..e799cab50 100644 --- a/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs +++ b/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs @@ -548,4 +548,9 @@ public void SetDeletedAt() { DeletedAt = DateTime.UtcNow; } + + public void AddNote(string subject, string note, string author, DateTime date) + { + _notes.Add(new ProjectNote(subject, note, author, date, Id)); + } } diff --git a/Dfe.Academies.Academisation.IData/ProjectAggregate/IIncompleteProjectsGetDataQuery.cs b/Dfe.Academies.Academisation.IData/ProjectAggregate/IIncompleteProjectsGetDataQuery.cs deleted file mode 100644 index 7d1be33c1..000000000 --- a/Dfe.Academies.Academisation.IData/ProjectAggregate/IIncompleteProjectsGetDataQuery.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Dfe.Academies.Academisation.IDomain.ProjectAggregate; - -namespace Dfe.Academies.Academisation.IData.ProjectAggregate -{ - public interface IIncompleteProjectsGetDataQuery - { - Task?> GetIncompleteProjects(); - } -} diff --git a/Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteAddCommand.cs b/Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteAddCommand.cs deleted file mode 100644 index 768d5129c..000000000 --- a/Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteAddCommand.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; - -namespace Dfe.Academies.Academisation.IData.ProjectAggregate -{ - public interface IProjectNoteAddCommand - { - Task Execute(int projectId, ProjectNote note); - } -} diff --git a/Dfe.Academies.Academisation.IDomain/ProjectAggregate/IProject.cs b/Dfe.Academies.Academisation.IDomain/ProjectAggregate/IProject.cs index 8db4cfbfe..47902779b 100644 --- a/Dfe.Academies.Academisation.IDomain/ProjectAggregate/IProject.cs +++ b/Dfe.Academies.Academisation.IDomain/ProjectAggregate/IProject.cs @@ -43,4 +43,5 @@ public void SetSchoolOverview( public void SetPerformanceData(string? keyStage2PerformanceAdditionalInformation, string? keyStage4PerformanceAdditionalInformation, string? keyStage5PerformanceAdditionalInformation, string? educationalAttendanceAdditionalInformation); void SetFormAMatProjectId(int id); void SetRoute(string route); + void AddNote(string subject, string note, string author, DateTime date); } diff --git a/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/IConversionProjectExportService.cs b/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/IConversionProjectExportService.cs index b22f4a234..ca627bb53 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/IConversionProjectExportService.cs +++ b/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/IConversionProjectExportService.cs @@ -1,5 +1,4 @@ -using Dfe.Academies.Academisation.Data.ProjectAggregate; -using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; +using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; namespace Dfe.Academies.Academisation.IService.Commands.Legacy.Project { diff --git a/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/ITransferProjectExportService.cs b/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/ITransferProjectExportService.cs index a5abd26ce..ef10dd280 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/ITransferProjectExportService.cs +++ b/Dfe.Academies.Academisation.IService/Commands/Legacy/Project/ITransferProjectExportService.cs @@ -1,4 +1,4 @@ -using Dfe.Academies.Academisation.Data.ProjectAggregate; +using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject; namespace Dfe.Academies.Academisation.IService.Commands.Legacy.Project { diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/GetProjectSearchModel.cs b/Dfe.Academies.Academisation.IService/ServiceModels/GetProjectSearchModel.cs similarity index 93% rename from Dfe.Academies.Academisation.Data/ProjectAggregate/GetProjectSearchModel.cs rename to Dfe.Academies.Academisation.IService/ServiceModels/GetProjectSearchModel.cs index 10fa17f2b..b9bd47233 100644 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/GetProjectSearchModel.cs +++ b/Dfe.Academies.Academisation.IService/ServiceModels/GetProjectSearchModel.cs @@ -1,4 +1,4 @@ -namespace Dfe.Academies.Academisation.Data.ProjectAggregate +namespace Dfe.Academies.Academisation.IService.ServiceModels { public class GetProjectSearchModel { diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/ConversionProjectSearchModel.cs b/Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/ConversionProjectSearchModel.cs similarity index 93% rename from Dfe.Academies.Academisation.Data/ProjectAggregate/ConversionProjectSearchModel.cs rename to Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/ConversionProjectSearchModel.cs index ad21a8a5d..099ba83a5 100644 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/ConversionProjectSearchModel.cs +++ b/Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/ConversionProjectSearchModel.cs @@ -1,4 +1,4 @@ -namespace Dfe.Academies.Academisation.Data.ProjectAggregate +namespace Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate { public class ConversionProjectSearchModel { diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/TransferProjectSearchModel.cs b/Dfe.Academies.Academisation.IService/ServiceModels/TransferProject/TransferProjectSearchModel.cs similarity index 70% rename from Dfe.Academies.Academisation.Data/ProjectAggregate/TransferProjectSearchModel.cs rename to Dfe.Academies.Academisation.IService/ServiceModels/TransferProject/TransferProjectSearchModel.cs index 6543aee3c..8a2eb50fc 100644 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/TransferProjectSearchModel.cs +++ b/Dfe.Academies.Academisation.IService/ServiceModels/TransferProject/TransferProjectSearchModel.cs @@ -1,4 +1,4 @@ -namespace Dfe.Academies.Academisation.Data.ProjectAggregate +namespace Dfe.Academies.Academisation.IService.ServiceModels.TransferProject { public class TransferProjectSearchModel { diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs index 8462d6229..81e95db8c 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs @@ -1,4 +1,5 @@ using AutoFixture; +using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Dfe.Academies.Academisation.IService.Query; @@ -13,7 +14,7 @@ namespace Dfe.Academies.Academisation.Service.UnitTest.Commands.Legacy.Project public class EnrichProjectCommandTests { private readonly EnrichProjectCommand _subject; - private readonly Mock _incompleteProjectGetDataQuery; + private readonly Mock _conversionProjectRepository; private readonly Mock _establishmentGetDataQuery; private readonly Mock _updateCommand; private readonly Mock> _logger; @@ -22,14 +23,14 @@ public class EnrichProjectCommandTests public EnrichProjectCommandTests() { - _incompleteProjectGetDataQuery = new Mock(); + _conversionProjectRepository = new Mock(); _establishmentGetDataQuery = new Mock(); _updateCommand = new Mock(); _logger = new Mock>(); _subject = new EnrichProjectCommand( _logger.Object, - _incompleteProjectGetDataQuery.Object, + _conversionProjectRepository.Object, _establishmentGetDataQuery.Object, _updateCommand.Object); } @@ -50,7 +51,7 @@ public async Task NoIncompleteProjects__LogAndReturn() public async Task IncompleteProjects__UnknownSchool__LogAndContinue() { var projects = _fixture.CreateMany(); - _incompleteProjectGetDataQuery.Setup(m => m.GetIncompleteProjects()) + _conversionProjectRepository.Setup(m => m.GetIncompleteProjects()) .ReturnsAsync(projects); _establishmentGetDataQuery.SetupSequence(m => m.GetEstablishment(It.IsAny())) @@ -71,7 +72,7 @@ public async Task IncompleteProjects__UnknownSchool__LogAndContinue() public async Task IncompleteProjects__KnownSchool__UpdateDb() { var project = _fixture.Create(); - _incompleteProjectGetDataQuery.Setup(m => m.GetIncompleteProjects()) + _conversionProjectRepository.Setup(m => m.GetIncompleteProjects()) .ReturnsAsync(new List { project }); _establishmentGetDataQuery.Setup(m => m.GetEstablishment(It.IsAny())) diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectAddNoteCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectAddNoteCommandTests.cs index 95ba69809..191d27df8 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectAddNoteCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectAddNoteCommandTests.cs @@ -1,11 +1,9 @@ using AutoFixture; using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; +using Dfe.Academies.Academisation.Domain.SeedWork; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Dfe.Academies.Academisation.Service.Commands.ConversionProject; -using Dfe.Academies.Academisation.Service.Commands.Legacy.Project; using FluentAssertions; using Moq; using Xunit; @@ -15,25 +13,24 @@ namespace Dfe.Academies.Academisation.Service.UnitTest.Commands.Legacy.Project public class LegacyProjectAddNoteCommandTests { private readonly Fixture _fixture; - private readonly Mock _projectGetDataQuery; - private readonly Mock _projectNoteAddCommand; + private readonly Mock _repo; public LegacyProjectAddNoteCommandTests() { _fixture = new Fixture(); - _projectGetDataQuery = new Mock(); - _projectNoteAddCommand = new Mock(); + _repo = new Mock(); + _repo.Setup(x => x.UnitOfWork).Returns(Mock.Of()); } private ConversionProjectAddNoteCommandHandler System_under_test() { - return new ConversionProjectAddNoteCommandHandler(_projectGetDataQuery.Object, _projectNoteAddCommand.Object); + return new ConversionProjectAddNoteCommandHandler(_repo.Object); } [Fact] public async Task Should_return_not_found_command_result_if_the_project_is_unknown() { - _projectGetDataQuery + _repo .Setup(x => x.GetConversionProject(It.IsAny())) .ReturnsAsync((IProject?)null); @@ -49,22 +46,16 @@ public async Task Should_pass_on_the_result_from_the_data_layer_command_if_the_p { IProject project = _fixture.Create(); - _projectGetDataQuery - .Setup(x => x.GetConversionProject(It.IsAny())) + _repo.Setup(x => x.GetConversionProject(It.IsAny())) .ReturnsAsync(project); - var addCommandResult = new CommandSuccessResult(); - _projectNoteAddCommand - .Setup(x => x.Execute(It.IsAny(), It.IsAny())) - .ReturnsAsync(addCommandResult); - var command = System_under_test(); CommandResult result = await command.Handle( _fixture.Create() with { ProjectId = project.Id }, default ); - result.Should().Be(addCommandResult); + result.Should().BeOfType(typeof(CommandSuccessResult)); } } } diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Queries/TransferProjectExportServiceTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Queries/TransferProjectExportServiceTests.cs index 235ca6461..930305276 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Queries/TransferProjectExportServiceTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Queries/TransferProjectExportServiceTests.cs @@ -1,5 +1,4 @@ -using Dfe.Academies.Academisation.Data.ProjectAggregate; -using Dfe.Academies.Academisation.IService.Query; +using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject; using Dfe.Academies.Academisation.Service.Queries; using Moq; diff --git a/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectAddNoteCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectAddNoteCommandHandler.cs index e04feb6fe..593d4a6bf 100644 --- a/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectAddNoteCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectAddNoteCommandHandler.cs @@ -1,24 +1,18 @@ using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; -using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; using MediatR; namespace Dfe.Academies.Academisation.Service.Commands.ConversionProject { public class ConversionProjectAddNoteCommandHandler : IRequestHandler { - private readonly IProjectNoteAddCommand _addNoteCommand; private readonly IConversionProjectRepository _conversionProjectRepository; - public ConversionProjectAddNoteCommandHandler(IConversionProjectRepository conversionProjectRepository, - IProjectNoteAddCommand addNoteCommand) + public ConversionProjectAddNoteCommandHandler(IConversionProjectRepository conversionProjectRepository) { _conversionProjectRepository = conversionProjectRepository; - _addNoteCommand = addNoteCommand; } public async Task Handle(ConversionProjectAddNoteCommand model, CancellationToken cancellationToken) @@ -30,14 +24,15 @@ public async Task Handle(ConversionProjectAddNoteCommand model, C return new NotFoundCommandResult(); } - return await _addNoteCommand.Execute( - model.ProjectId, - new ProjectNote( - model.Subject, + project.AddNote(model.Subject, model.Note, model.Author, - model.Date, model.ProjectId) - ); + model.Date); + + await _conversionProjectRepository.UnitOfWork.SaveChangesAsync(); + + return new CommandSuccessResult(); + } } } diff --git a/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs index 928b6ca16..b53982846 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs @@ -1,4 +1,5 @@ -using Dfe.Academies.Academisation.IData.ProjectAggregate; +using Dfe.Academies.Academisation.Domain.ApplicationAggregate; +using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; @@ -11,25 +12,25 @@ namespace Dfe.Academies.Academisation.Service.Commands.Legacy.Project public class EnrichProjectCommand : IEnrichProjectCommand { private readonly ILogger _logger; - private readonly IIncompleteProjectsGetDataQuery _incompleteProjectsGetDataQuery; + private readonly IConversionProjectRepository _conversionProjectRepository; private readonly IAcademiesQueryService _establishmentRepository; private readonly IProjectUpdateDataCommand _projectUpdateDataCommand; public EnrichProjectCommand( ILogger logger, - IIncompleteProjectsGetDataQuery incompleteProjectsGetDataQuery, + IConversionProjectRepository conversionProjectRepository, IAcademiesQueryService establishmentRepository, IProjectUpdateDataCommand projectUpdateDataCommand) { _logger = logger; - _incompleteProjectsGetDataQuery = incompleteProjectsGetDataQuery; + _conversionProjectRepository = conversionProjectRepository; _establishmentRepository = establishmentRepository; _projectUpdateDataCommand = projectUpdateDataCommand; } public async Task Execute() { - var incompleteProjects = await _incompleteProjectsGetDataQuery.GetIncompleteProjects(); + var incompleteProjects = await _conversionProjectRepository.GetIncompleteProjects(); if (incompleteProjects == null || !incompleteProjects.Any()) { diff --git a/Dfe.Academies.Academisation.Service/Queries/ConversionProjectExportService.cs b/Dfe.Academies.Academisation.Service/Queries/ConversionProjectExportService.cs index c66eae80c..43c7bd99e 100644 --- a/Dfe.Academies.Academisation.Service/Queries/ConversionProjectExportService.cs +++ b/Dfe.Academies.Academisation.Service/Queries/ConversionProjectExportService.cs @@ -1,5 +1,4 @@ using ClosedXML.Excel; -using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; @@ -75,9 +74,10 @@ private async Task GenerateSpreadsheet(IEnumerable GenerateSpreadsheet(IEnumerable>(), - new IncompleteProjectsGetDataQuery(_context), + new ConversionProjectRepository(_context, Mock.Of()), new AcademiesQueryService(Mock.Of>(), _academiesApiClientFactory.Object, correlationContext), new ProjectUpdateDataCommand(_context)); } diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs index 8db8c6303..7fd46f775 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs @@ -1,11 +1,11 @@ using AutoFixture; using Dfe.Academies.Academisation.Core.Test; using Dfe.Academies.Academisation.Data; -using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.Data.Repositories; using Dfe.Academies.Academisation.Data.UnitTest.Contexts; using Dfe.Academies.Academisation.Domain.ProjectAggregate; using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; +using Dfe.Academies.Academisation.IService.ServiceModels; using Dfe.Academies.Academisation.Service.Queries; using Dfe.Academies.Academisation.WebApi.Controllers; using MediatR; diff --git a/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ExportControllerTests.cs b/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ExportControllerTests.cs index 677890f4f..408f9a4fe 100644 --- a/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ExportControllerTests.cs +++ b/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ExportControllerTests.cs @@ -1,7 +1,8 @@ using System.IO; using System.Threading.Tasks; -using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; +using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; +using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject; using Dfe.Academies.Academisation.WebApi.Controllers; using MediatR; using Microsoft.AspNetCore.Mvc; diff --git a/Dfe.Academies.Academisation.WebApi/Controllers/ConversionProjectController.cs b/Dfe.Academies.Academisation.WebApi/Controllers/ConversionProjectController.cs index 0bbd83229..4e0c71f8e 100644 --- a/Dfe.Academies.Academisation.WebApi/Controllers/ConversionProjectController.cs +++ b/Dfe.Academies.Academisation.WebApi/Controllers/ConversionProjectController.cs @@ -1,6 +1,6 @@ using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.IService.Query; +using Dfe.Academies.Academisation.IService.ServiceModels; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; using Dfe.Academies.Academisation.Service.Commands.ConversionProject; using Dfe.Academies.Academisation.Service.Commands.ConversionProject.SetCommands; diff --git a/Dfe.Academies.Academisation.WebApi/Controllers/ExportController.cs b/Dfe.Academies.Academisation.WebApi/Controllers/ExportController.cs index 15ad2542f..8b40ac92f 100644 --- a/Dfe.Academies.Academisation.WebApi/Controllers/ExportController.cs +++ b/Dfe.Academies.Academisation.WebApi/Controllers/ExportController.cs @@ -1,5 +1,6 @@ -using Dfe.Academies.Academisation.Data.ProjectAggregate; -using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; +using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; +using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; +using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject; using Microsoft.AspNetCore.Mvc; namespace Dfe.Academies.Academisation.WebApi.Controllers diff --git a/Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs b/Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs index 991d316f6..2455470b2 100644 --- a/Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs +++ b/Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs @@ -1,9 +1,9 @@ using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; using Dfe.Academies.Academisation.IService.Query; +using Dfe.Academies.Academisation.IService.ServiceModels; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; using Dfe.Academies.Academisation.Service.Commands.ConversionProject; using Dfe.Academies.Academisation.WebApi.Extensions; diff --git a/Dfe.Academies.Academisation.WebApi/Controllers/TransferProjectController.cs b/Dfe.Academies.Academisation.WebApi/Controllers/TransferProjectController.cs index 7510f977e..6c88095f6 100644 --- a/Dfe.Academies.Academisation.WebApi/Controllers/TransferProjectController.cs +++ b/Dfe.Academies.Academisation.WebApi/Controllers/TransferProjectController.cs @@ -1,6 +1,6 @@ using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.IService.Query; +using Dfe.Academies.Academisation.IService.ServiceModels; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; using Dfe.Academies.Academisation.IService.ServiceModels.TransferProject; using Dfe.Academies.Academisation.Service.Commands.Application; diff --git a/Dfe.Academies.Academisation.WebApi/Program.cs b/Dfe.Academies.Academisation.WebApi/Program.cs index ee853d038..402425b0f 100644 --- a/Dfe.Academies.Academisation.WebApi/Program.cs +++ b/Dfe.Academies.Academisation.WebApi/Program.cs @@ -97,7 +97,6 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); //Repositories @@ -117,7 +116,6 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped();