From 81460910def97a47a69ddfe812b6a41752ab4515 Mon Sep 17 00:00:00 2001 From: plockwood Date: Thu, 2 May 2024 17:01:15 +0100 Subject: [PATCH] Remove delete note data command --- ...ademies.Academisation.Data.UnitTest.csproj | 1 - .../AcademiesApiClientFactoryFactoryTests.cs | 1 - .../ProjectNoteDeleteCommandTests.cs | 118 +++++++++--------- .../Dfe.Academies.Academisation.Data.csproj | 1 - .../Http/AcademiesApiClientFactoryFactory.cs | 3 +- .../Http/IAcademiesApiClientFactory.cs | 2 +- .../IProjectUpdateDataCommand.cs | 8 ++ .../ProjectNoteDeleteCommand.cs | 64 +++++----- .../ProjectUpdateDataCommand.cs | 1 - .../ProjectAggregate/Project.cs | 8 ++ .../IProjectNoteDeleteCommand.cs | 10 -- .../ProjectAggregate/IProject.cs | 1 + ...fe.Academies.Academisation.IService.csproj | 1 - ...emies.Academisation.IntegrationTest.csproj | 1 - .../Commands/ApplicationDeleteCommandTests.cs | 4 - .../Project/EnrichProjectCommandTests.cs | 2 +- .../LegacyProjectDeleteNoteCommandTests.cs | 73 ++++++----- .../LegacyProjectUpdateCommandTests.cs | 2 +- .../ApplicationSubmitCommandHandler.cs | 6 +- ...nversionProjectDeleteNoteCommandHandler.cs | 46 +++++-- .../ConversionProjectUpdateCommandHandler.cs | 3 +- .../Legacy/Project/EnrichProjectCommand.cs | 4 +- ...Dfe.Academies.Academisation.Service.csproj | 1 - .../Queries/AcademiesQueryService.cs | 9 +- .../ApplicationDeleteTests.cs | 3 - ...mies.Academisation.SubcutaneousTest.csproj | 1 - .../EnrichProjectCommandTests.cs | 3 +- .../LegacyProjectUpdateTests.cs | 2 - Dfe.Academies.Academisation.WebApi/Program.cs | 21 ++-- Dfe.Academies.Academisation.sln | 7 -- 30 files changed, 203 insertions(+), 204 deletions(-) rename {Dfe.Academies.Academisation.IData => Dfe.Academies.Academisation.Data}/Http/IAcademiesApiClientFactory.cs (77%) create mode 100644 Dfe.Academies.Academisation.Data/ProjectAggregate/IProjectUpdateDataCommand.cs delete mode 100644 Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteDeleteCommand.cs diff --git a/Dfe.Academies.Academisation.Data.UnitTest/Dfe.Academies.Academisation.Data.UnitTest.csproj b/Dfe.Academies.Academisation.Data.UnitTest/Dfe.Academies.Academisation.Data.UnitTest.csproj index 946aa1e32..66931f285 100644 --- a/Dfe.Academies.Academisation.Data.UnitTest/Dfe.Academies.Academisation.Data.UnitTest.csproj +++ b/Dfe.Academies.Academisation.Data.UnitTest/Dfe.Academies.Academisation.Data.UnitTest.csproj @@ -30,7 +30,6 @@ - diff --git a/Dfe.Academies.Academisation.Data.UnitTest/Http/AcademiesApiClientFactoryFactoryTests.cs b/Dfe.Academies.Academisation.Data.UnitTest/Http/AcademiesApiClientFactoryFactoryTests.cs index c4fe5a166..1faac6ac2 100644 --- a/Dfe.Academies.Academisation.Data.UnitTest/Http/AcademiesApiClientFactoryFactoryTests.cs +++ b/Dfe.Academies.Academisation.Data.UnitTest/Http/AcademiesApiClientFactoryFactoryTests.cs @@ -1,7 +1,6 @@ using System; using System.Net.Http; using Dfe.Academies.Academisation.Data.Http; -using Dfe.Academies.Academisation.IData.Http; using Dfe.Academisation.CorrelationIdMiddleware; using FluentAssertions; using Moq; diff --git a/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteDeleteCommandTests.cs b/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteDeleteCommandTests.cs index d3c2cc202..d4b7ca8f9 100644 --- a/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteDeleteCommandTests.cs +++ b/Dfe.Academies.Academisation.Data.UnitTest/ProjectAggregate/ProjectNoteDeleteCommandTests.cs @@ -1,79 +1,79 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -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 Dfe.Academies.Academisation.Domain.ProjectAggregate; -using Dfe.Academies.Academisation.IDomain.ProjectAggregate; -using FluentAssertions; -using Xunit; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Threading.Tasks; +//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 Dfe.Academies.Academisation.Domain.ProjectAggregate; +//using Dfe.Academies.Academisation.IDomain.ProjectAggregate; +//using FluentAssertions; +//using Xunit; -namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate -{ - public class ProjectNoteDeleteCommandTests - { - private readonly AcademisationContext _context; - private readonly Fixture _fixture; - private readonly IList _notes; +//namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate +//{ +// public class ProjectNoteDeleteCommandTests +// { +// private readonly AcademisationContext _context; +// private readonly Fixture _fixture; +// private readonly IList _notes; - public ProjectNoteDeleteCommandTests() - { - var testProjectContext = new TestProjectContext(); - _context = testProjectContext.CreateContext(); +// public ProjectNoteDeleteCommandTests() +// { +// var testProjectContext = new TestProjectContext(); +// _context = testProjectContext.CreateContext(); - _fixture = new Fixture(); +// _fixture = new Fixture(); - IList projects = _fixture.CreateMany(3).ToList(); +// IList projects = _fixture.CreateMany(3).ToList(); - _notes = _fixture.CreateMany().ToList(); +// _notes = _fixture.CreateMany().ToList(); - _notes = _notes.Select(x => new ProjectNote(x.Subject, x.Note, x.Author, x.Date, projects[Random.Shared.Next(projects.Count)].Id)) - .ToList(); +// _notes = _notes.Select(x => new ProjectNote(x.Subject, x.Note, x.Author, x.Date, projects[Random.Shared.Next(projects.Count)].Id)) +// .ToList(); - _context.Projects.AddRangeAsync(projects); - _context.ProjectNotes.AddRangeAsync(_notes); - _context.SaveChanges(); - } +// _context.Projects.AddRangeAsync(projects); +// _context.ProjectNotes.AddRangeAsync(_notes); +// _context.SaveChanges(); +// } - private ProjectNote RandomNote => _notes[Random.Shared.Next(_notes.Count)]; +// private ProjectNote RandomNote => _notes[Random.Shared.Next(_notes.Count)]; - private ProjectNoteDeleteCommand System_under_test() - { - return new ProjectNoteDeleteCommand(_context); - } +// private ProjectNoteDeleteCommand System_under_test() +// { +// return new ProjectNoteDeleteCommand(_context); +// } - [Fact] - public async Task Should_return_not_found_result_if_the_note_does_not_exist() - { - ProjectNote noteToDelete = _fixture.Create(); +// [Fact] +// public async Task Should_return_not_found_result_if_the_note_does_not_exist() +// { +// ProjectNote noteToDelete = _fixture.Create(); - ProjectNoteDeleteCommand command = System_under_test(); +// ProjectNoteDeleteCommand command = System_under_test(); - _context.ProjectNotes.Should().NotContain(noteToDelete); +// _context.ProjectNotes.Should().NotContain(noteToDelete); - CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete); +// CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete); - result.Should().BeOfType(); - } +// result.Should().BeOfType(); +// } - [Fact] - public async Task Should_remove_the_note() - { - ProjectNote noteToDelete = RandomNote; +// [Fact] +// public async Task Should_remove_the_note() +// { +// ProjectNote noteToDelete = RandomNote; - ProjectNoteDeleteCommand command = System_under_test(); +// ProjectNoteDeleteCommand command = System_under_test(); - _context.ProjectNotes.Should().Contain(noteToDelete); +// _context.ProjectNotes.Should().Contain(noteToDelete); - CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete); +// CommandResult result = await command.Execute(noteToDelete.ProjectId, noteToDelete); - result.Should().BeOfType(); +// result.Should().BeOfType(); - _context.ProjectNotes.Should().NotContain(noteToDelete); - } - } -} +// _context.ProjectNotes.Should().NotContain(noteToDelete); +// } +// } +//} diff --git a/Dfe.Academies.Academisation.Data/Dfe.Academies.Academisation.Data.csproj b/Dfe.Academies.Academisation.Data/Dfe.Academies.Academisation.Data.csproj index aaba0236b..36d1c4044 100644 --- a/Dfe.Academies.Academisation.Data/Dfe.Academies.Academisation.Data.csproj +++ b/Dfe.Academies.Academisation.Data/Dfe.Academies.Academisation.Data.csproj @@ -18,7 +18,6 @@ - diff --git a/Dfe.Academies.Academisation.Data/Http/AcademiesApiClientFactoryFactory.cs b/Dfe.Academies.Academisation.Data/Http/AcademiesApiClientFactoryFactory.cs index 325b819eb..284546fdc 100644 --- a/Dfe.Academies.Academisation.Data/Http/AcademiesApiClientFactoryFactory.cs +++ b/Dfe.Academies.Academisation.Data/Http/AcademiesApiClientFactoryFactory.cs @@ -1,5 +1,4 @@ -using Dfe.Academies.Academisation.IData.Http; -using Dfe.Academisation.CorrelationIdMiddleware; +using Dfe.Academisation.CorrelationIdMiddleware; namespace Dfe.Academies.Academisation.Data.Http { diff --git a/Dfe.Academies.Academisation.IData/Http/IAcademiesApiClientFactory.cs b/Dfe.Academies.Academisation.Data/Http/IAcademiesApiClientFactory.cs similarity index 77% rename from Dfe.Academies.Academisation.IData/Http/IAcademiesApiClientFactory.cs rename to Dfe.Academies.Academisation.Data/Http/IAcademiesApiClientFactory.cs index ebedf7857..205858836 100644 --- a/Dfe.Academies.Academisation.IData/Http/IAcademiesApiClientFactory.cs +++ b/Dfe.Academies.Academisation.Data/Http/IAcademiesApiClientFactory.cs @@ -1,6 +1,6 @@ using Dfe.Academisation.CorrelationIdMiddleware; -namespace Dfe.Academies.Academisation.IData.Http +namespace Dfe.Academies.Academisation.Data.Http { public interface IAcademiesApiClientFactory { diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/IProjectUpdateDataCommand.cs b/Dfe.Academies.Academisation.Data/ProjectAggregate/IProjectUpdateDataCommand.cs new file mode 100644 index 000000000..e671a8304 --- /dev/null +++ b/Dfe.Academies.Academisation.Data/ProjectAggregate/IProjectUpdateDataCommand.cs @@ -0,0 +1,8 @@ +using Dfe.Academies.Academisation.IDomain.ProjectAggregate; + +namespace Dfe.Academies.Academisation.Data.ProjectAggregate; + +public interface IProjectUpdateDataCommand +{ + Task Execute(IProject project); +} diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteDeleteCommand.cs b/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteDeleteCommand.cs index eaceb2737..32a5d396f 100644 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteDeleteCommand.cs +++ b/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectNoteDeleteCommand.cs @@ -1,38 +1,38 @@ -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; -using Microsoft.EntityFrameworkCore; +//using Dfe.Academies.Academisation.Core; +//using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; +//using Dfe.Academies.Academisation.IData.ProjectAggregate; +//using Microsoft.EntityFrameworkCore; -namespace Dfe.Academies.Academisation.Data.ProjectAggregate -{ - public class ProjectNoteDeleteCommand : IProjectNoteDeleteCommand - { - private readonly AcademisationContext _context; +//namespace Dfe.Academies.Academisation.Data.ProjectAggregate +//{ +// public class ProjectNoteDeleteCommand : IProjectNoteDeleteCommand +// { +// private readonly AcademisationContext _context; - public ProjectNoteDeleteCommand(AcademisationContext context) - { - _context = context; - } +// public ProjectNoteDeleteCommand(AcademisationContext context) +// { +// _context = context; +// } - public async Task Execute(int projectId, ProjectNote note) - { - ProjectNote? matchedNote = - await _context.ProjectNotes - .FirstOrDefaultAsync(x => x.ProjectId == projectId && - x.Subject == note.Subject && - x.Note == note.Note && - x.Author == note.Author && - x.Date == note.Date); +// public async Task Execute(int projectId, ProjectNote note) +// { +// ProjectNote? matchedNote = +// await _context.ProjectNotes +// .FirstOrDefaultAsync(x => x.ProjectId == projectId && +// x.Subject == note.Subject && +// x.Note == note.Note && +// x.Author == note.Author && +// x.Date == note.Date); - if (matchedNote is null) - { - return new NotFoundCommandResult(); - } +// if (matchedNote is null) +// { +// return new NotFoundCommandResult(); +// } - _context.ProjectNotes.Remove(matchedNote); - await _context.SaveChangesAsync(); +// _context.ProjectNotes.Remove(matchedNote); +// await _context.SaveChangesAsync(); - return new CommandSuccessResult(); - } - } -} +// return new CommandSuccessResult(); +// } +// } +//} diff --git a/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectUpdateDataCommand.cs b/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectUpdateDataCommand.cs index 2739298b5..79652e08b 100644 --- a/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectUpdateDataCommand.cs +++ b/Dfe.Academies.Academisation.Data/ProjectAggregate/ProjectUpdateDataCommand.cs @@ -1,5 +1,4 @@ using Dfe.Academies.Academisation.Domain.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Microsoft.EntityFrameworkCore; diff --git a/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs b/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs index e799cab50..55707a722 100644 --- a/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs +++ b/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs @@ -4,6 +4,7 @@ using Dfe.Academies.Academisation.Domain.SeedWork; using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace Dfe.Academies.Academisation.Domain.ProjectAggregate; @@ -553,4 +554,11 @@ public void AddNote(string subject, string note, string author, DateTime date) { _notes.Add(new ProjectNote(subject, note, author, date, Id)); } + + public void RemoveNote(int id) + { + var note = _notes.SingleOrDefault(x => x.Id == id); + if (note != null) { _notes.Remove(note); } + + } } diff --git a/Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteDeleteCommand.cs b/Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteDeleteCommand.cs deleted file mode 100644 index ac481c7b9..000000000 --- a/Dfe.Academies.Academisation.IData/ProjectAggregate/IProjectNoteDeleteCommand.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 IProjectNoteDeleteCommand - { - 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 47902779b..72f55975e 100644 --- a/Dfe.Academies.Academisation.IDomain/ProjectAggregate/IProject.cs +++ b/Dfe.Academies.Academisation.IDomain/ProjectAggregate/IProject.cs @@ -44,4 +44,5 @@ public void SetSchoolOverview( void SetFormAMatProjectId(int id); void SetRoute(string route); void AddNote(string subject, string note, string author, DateTime date); + void RemoveNote(int id); } diff --git a/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj b/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj index db8118c22..e341826b7 100644 --- a/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj +++ b/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj @@ -16,7 +16,6 @@ - diff --git a/Dfe.Academies.Academisation.IntegrationTest/Dfe.Academies.Academisation.IntegrationTest.csproj b/Dfe.Academies.Academisation.IntegrationTest/Dfe.Academies.Academisation.IntegrationTest.csproj index d497c0d37..7872bb33e 100644 --- a/Dfe.Academies.Academisation.IntegrationTest/Dfe.Academies.Academisation.IntegrationTest.csproj +++ b/Dfe.Academies.Academisation.IntegrationTest/Dfe.Academies.Academisation.IntegrationTest.csproj @@ -25,7 +25,6 @@ - diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationDeleteCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationDeleteCommandTests.cs index 9c15f81f1..7a99c48a0 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationDeleteCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationDeleteCommandTests.cs @@ -3,12 +3,8 @@ using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.SeedWork; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; -using Dfe.Academies.Academisation.IDomain.ProjectAggregate; -using Dfe.Academies.Academisation.IDomain.Services; using Dfe.Academies.Academisation.IService.RequestModels; -using Dfe.Academies.Academisation.Service.Commands.Application; using Moq; using Xunit; 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 81e95db8c..76495d7c1 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs @@ -1,6 +1,6 @@ using AutoFixture; +using Dfe.Academies.Academisation.Data.ProjectAggregate; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.Service.Commands.Legacy.Project; diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectDeleteNoteCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectDeleteNoteCommandTests.cs index ed16391a9..0e1aecff3 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectDeleteNoteCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectDeleteNoteCommandTests.cs @@ -1,8 +1,10 @@ using AutoFixture; +using AutoFixture.AutoMoq; 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.IService.ServiceModels.Legacy.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; @@ -13,57 +15,68 @@ namespace Dfe.Academies.Academisation.Service.UnitTest.Commands.Legacy.Project { public class LegacyProjectDeleteNoteCommandTests { - private readonly Mock _deleteNoteCommand; + private readonly Mock _repo; private readonly Fixture _fixture; public LegacyProjectDeleteNoteCommandTests() { _fixture = new Fixture(); - _deleteNoteCommand = new Mock(); + _fixture.Customize(new AutoMoqCustomization()); + + _repo = new Mock(); + + _repo.Setup(x => x.UnitOfWork).Returns(Mock.Of()); } private ConversionProjectDeleteNoteCommandHandler System_under_test() { - return new ConversionProjectDeleteNoteCommandHandler(_deleteNoteCommand.Object); + return new ConversionProjectDeleteNoteCommandHandler(_repo.Object); } - [Fact] - public async Task Should_pass_the_request_to_the_data_layer_command() - { - int projectId = Random.Shared.Next(); - var note = _fixture.Create(); + //[Fact] + //public async Task Should_pass_the_request_to_the_data_layer_command() + //{ + // int projectId = Random.Shared.Next(); + // var note = _fixture.Create(); - note.ProjectId = projectId; + // note.ProjectId = projectId; - var command = System_under_test(); + // var command = System_under_test(); - await command.Handle(note, default); - - _deleteNoteCommand.Verify( - x => x.Execute( - It.Is(projectId, EqualityComparer.Default), - It.Is(n => n.Subject == note.Subject && - n.Note == note.Note && - n.Author == note.Author && - n.Date == note.Date) - ) - ); - } + // await command.Handle(note, default); + + // _repo.Verify( + // x => x.Update( + // It.Is(n => n.Subject == note.Subject && + // n.Note == note.Note && + // n.Author == note.Author && + // n.Date == note.Date) + // ) + // ); + //} [Fact] public async Task Should_return_the_result_produced_by_the_data_layer_command() { - var dataCommandResult = new CommandSuccessResult(); + var note = _fixture.Create(); + var project = _fixture.Create(); + + Mock.Get(project).Setup(x => x.Notes).Returns(new List { note }); - _deleteNoteCommand - .Setup(x => x.Execute(It.IsAny(), It.IsAny())) - .ReturnsAsync(dataCommandResult); + _repo.Setup(x => x.GetConversionProject(It.IsAny())).ReturnsAsync(project); var command = System_under_test(); - CommandResult result = await command.Handle(_fixture.Create(), default); + CommandResult result = await command.Handle(new ConversionProjectDeleteNoteCommand() + { + Author = note.Author, + Date = note.Date, + Note = note.Note, + ProjectId = note.ProjectId, + Subject = note.Subject + }, default); - result.Should().Be(dataCommandResult); + result.Should().BeOfType(typeof(CommandSuccessResult)); } } } diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectUpdateCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectUpdateCommandTests.cs index 7dde39944..979218038 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectUpdateCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/LegacyProjectUpdateCommandTests.cs @@ -1,8 +1,8 @@ using AutoFixture; using Dfe.Academies.Academisation.Core; +using Dfe.Academies.Academisation.Data.ProjectAggregate; 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.ServiceModels.Legacy.ProjectAggregate; using Dfe.Academies.Academisation.Service.Commands.ConversionProject; diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs index c0c438fbc..c7b95f302 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs @@ -1,14 +1,10 @@ -using System.Collections; -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Data.Repositories; +using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.Services; using Dfe.Academies.Academisation.IService.Commands.Application; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; -using Dfe.Academies.Academisation.Service.Commands.ConversionProject; using Dfe.Academies.Academisation.Service.Mappers.Legacy.ProjectAggregate; using MediatR; diff --git a/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectDeleteNoteCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectDeleteNoteCommandHandler.cs index 6a146ac4b..4716a2a6a 100644 --- a/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectDeleteNoteCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectDeleteNoteCommandHandler.cs @@ -1,29 +1,49 @@ using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; +using Dfe.Academies.Academisation.Domain.ApplicationAggregate; +using Dfe.Academies.Academisation.Domain.ProjectAggregate; +using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using MediatR; namespace Dfe.Academies.Academisation.Service.Commands.ConversionProject { public class ConversionProjectDeleteNoteCommandHandler : IRequestHandler { - private readonly IProjectNoteDeleteCommand _deleteNoteCommand; + private readonly IConversionProjectRepository _conversionProjectRepository; - public ConversionProjectDeleteNoteCommandHandler(IProjectNoteDeleteCommand deleteNoteCommand) + public ConversionProjectDeleteNoteCommandHandler(IConversionProjectRepository conversionProjectRepository) { - _deleteNoteCommand = deleteNoteCommand; + _conversionProjectRepository = conversionProjectRepository; } public async Task Handle(ConversionProjectDeleteNoteCommand note, CancellationToken cancellationToken) { - return await _deleteNoteCommand.Execute( - note.ProjectId, - new ProjectNote( - note.Subject, - note.Note, - note.Author, - note.Date, note.ProjectId) - ); + IProject? project = await _conversionProjectRepository.GetConversionProject(note.ProjectId); + + if (project is null) + { + return new NotFoundCommandResult(); + } + + // we are doing this because the note id doesn't come from the client + var matchedNote = project.Notes + .FirstOrDefault(x => x.ProjectId == note.ProjectId && + x.Subject == note.Subject && + x.Note == note.Note && + x.Author == note.Author && + x.Date == note.Date); + + if (matchedNote is null) + { + return new NotFoundCommandResult(); + } + + project.RemoveNote(matchedNote.Id); + + _conversionProjectRepository.Update(project as Project); + + await _conversionProjectRepository.UnitOfWork.SaveChangesAsync(); + + return new CommandSuccessResult(); } } } diff --git a/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectUpdateCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectUpdateCommandHandler.cs index 3da2a39fe..626abad62 100644 --- a/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectUpdateCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/ConversionProject/ConversionProjectUpdateCommandHandler.cs @@ -1,7 +1,6 @@ using Dfe.Academies.Academisation.Core; +using Dfe.Academies.Academisation.Data.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.Service.Mappers.Legacy.ProjectAggregate; using MediatR; diff --git a/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs index b53982846..db06fad84 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Legacy/Project/EnrichProjectCommand.cs @@ -1,5 +1,5 @@ -using Dfe.Academies.Academisation.Domain.ApplicationAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; +using Dfe.Academies.Academisation.Data.ProjectAggregate; +using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.IService.Commands.Legacy.Project; using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; diff --git a/Dfe.Academies.Academisation.Service/Dfe.Academies.Academisation.Service.csproj b/Dfe.Academies.Academisation.Service/Dfe.Academies.Academisation.Service.csproj index 221176d19..8224093fc 100644 --- a/Dfe.Academies.Academisation.Service/Dfe.Academies.Academisation.Service.csproj +++ b/Dfe.Academies.Academisation.Service/Dfe.Academies.Academisation.Service.csproj @@ -10,7 +10,6 @@ - diff --git a/Dfe.Academies.Academisation.Service/Queries/AcademiesQueryService.cs b/Dfe.Academies.Academisation.Service/Queries/AcademiesQueryService.cs index c807c97a5..145331354 100644 --- a/Dfe.Academies.Academisation.Service/Queries/AcademiesQueryService.cs +++ b/Dfe.Academies.Academisation.Service/Queries/AcademiesQueryService.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Linq; -using System.Net.Http.Json; -using Dfe.Academies.Academisation.IData.Http; +using System.Net.Http.Json; using Dfe.Academies.Academisation.IService.Query; -using Dfe.Academies.Academisation.IService.ServiceModels.Academies; using Dfe.Academies.Contracts.V4.Trusts; using Dfe.Academies.Contracts.V4.Establishments; using Dfe.Academisation.CorrelationIdMiddleware; using Microsoft.Extensions.Logging; +using Dfe.Academies.Academisation.Data.Http; namespace Dfe.Academies.Academisation.Service.Queries { diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationDeleteTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationDeleteTests.cs index d6945682b..ba28044db 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationDeleteTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationDeleteTests.cs @@ -5,14 +5,12 @@ using Dfe.Academies.Academisation.Core.Test; using Dfe.Academies.Academisation.Core.Utils; 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; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.Services; @@ -36,7 +34,6 @@ public class ApplicationDeleteTests private readonly Fixture _fixture = new(); private readonly Faker _faker = new(); private readonly AcademisationContext _context; - private const string Converter = "Converter"; private readonly IProjectFactory _projectFactory = new ProjectFactory(); private readonly IApplicationSubmissionService _applicationSubmissionService; diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/Dfe.Academies.Academisation.SubcutaneousTest.csproj b/Dfe.Academies.Academisation.SubcutaneousTest/Dfe.Academies.Academisation.SubcutaneousTest.csproj index ea6ffca3a..7e2c86555 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/Dfe.Academies.Academisation.SubcutaneousTest.csproj +++ b/Dfe.Academies.Academisation.SubcutaneousTest/Dfe.Academies.Academisation.SubcutaneousTest.csproj @@ -31,7 +31,6 @@ - diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs index 04b9465d0..a2f2b7e97 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs @@ -2,13 +2,12 @@ using AutoFixture; using AutoMapper; using Dfe.Academies.Academisation.Data; +using Dfe.Academies.Academisation.Data.Http; 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 Dfe.Academies.Academisation.IData.Http; -using Dfe.Academies.Academisation.IService.ServiceModels.Academies; using Dfe.Academies.Academisation.Service.Commands.Legacy.Project; using Dfe.Academies.Academisation.Service.Queries; using Dfe.Academies.Contracts.V4.Establishments; diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs index c00e38d00..c86bbfff7 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs @@ -9,8 +9,6 @@ using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; using Dfe.Academies.Academisation.Domain.FormAMatProjectAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; -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; using Dfe.Academies.Academisation.Service.Commands.ConversionProject; diff --git a/Dfe.Academies.Academisation.WebApi/Program.cs b/Dfe.Academies.Academisation.WebApi/Program.cs index 402425b0f..085e906a6 100644 --- a/Dfe.Academies.Academisation.WebApi/Program.cs +++ b/Dfe.Academies.Academisation.WebApi/Program.cs @@ -11,8 +11,6 @@ using Dfe.Academies.Academisation.Domain.FormAMatProjectAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; using Dfe.Academies.Academisation.Domain.TransferProjectAggregate; -using Dfe.Academies.Academisation.IData.Http; -using Dfe.Academies.Academisation.IData.ProjectAggregate; using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; using Dfe.Academies.Academisation.IDomain.ConversionAdvisoryBoardDecisionAggregate; using Dfe.Academies.Academisation.IDomain.ProjectAggregate; @@ -94,23 +92,18 @@ builder.Services.Configure(apiKeysConfiguration); // Commands -builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); -//Repositories +// Repositories builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); - -builder.Services.AddScoped(); - -// Queries +// Queries and services +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -120,13 +113,15 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); -//utils +// utils builder.Services.AddSingleton(); builder.Services.AddScoped(); -builder.Services.AddScoped(); // Factories builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); //Validators builder.Services.AddSingleton(); diff --git a/Dfe.Academies.Academisation.sln b/Dfe.Academies.Academisation.sln index d404c9073..49c325571 100644 --- a/Dfe.Academies.Academisation.sln +++ b/Dfe.Academies.Academisation.sln @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Academies.Academisation EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Academies.Academisation.Data", "Dfe.Academies.Academisation.Data\Dfe.Academies.Academisation.Data.csproj", "{F3DF5081-0CB4-4E8C-AD99-54CAF1851D4F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Academies.Academisation.IData", "Dfe.Academies.Academisation.IData\Dfe.Academies.Academisation.IData.csproj", "{C4106FE4-3F23-4F04-8DEE-88D29D6B8DD2}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Academies.Academisation.Data.UnitTest", "Dfe.Academies.Academisation.Data.UnitTest\Dfe.Academies.Academisation.Data.UnitTest.csproj", "{81E513D6-87D8-40C5-BF83-B4CAC0FBF775}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dfe.Academies.Academisation.Service", "Dfe.Academies.Academisation.Service\Dfe.Academies.Academisation.Service.csproj", "{EAA3B7AE-4E52-4774-9B23-D79F6E80E9BA}" @@ -76,10 +74,6 @@ Global {F3DF5081-0CB4-4E8C-AD99-54CAF1851D4F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F3DF5081-0CB4-4E8C-AD99-54CAF1851D4F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F3DF5081-0CB4-4E8C-AD99-54CAF1851D4F}.Release|Any CPU.Build.0 = Release|Any CPU - {C4106FE4-3F23-4F04-8DEE-88D29D6B8DD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C4106FE4-3F23-4F04-8DEE-88D29D6B8DD2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C4106FE4-3F23-4F04-8DEE-88D29D6B8DD2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C4106FE4-3F23-4F04-8DEE-88D29D6B8DD2}.Release|Any CPU.Build.0 = Release|Any CPU {81E513D6-87D8-40C5-BF83-B4CAC0FBF775}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {81E513D6-87D8-40C5-BF83-B4CAC0FBF775}.Debug|Any CPU.Build.0 = Debug|Any CPU {81E513D6-87D8-40C5-BF83-B4CAC0FBF775}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -137,7 +131,6 @@ Global {1916E8AB-3167-457D-AD1B-1EC4C1A92373} = {C0D697CE-92C3-400E-A5AA-025352A1BD2F} {4AD797FA-0D14-45D8-86BF-B965056764D2} = {C0D697CE-92C3-400E-A5AA-025352A1BD2F} {F3DF5081-0CB4-4E8C-AD99-54CAF1851D4F} = {5D372A37-BC9B-4476-A5E2-BC4DB7375768} - {C4106FE4-3F23-4F04-8DEE-88D29D6B8DD2} = {5D372A37-BC9B-4476-A5E2-BC4DB7375768} {81E513D6-87D8-40C5-BF83-B4CAC0FBF775} = {5D372A37-BC9B-4476-A5E2-BC4DB7375768} {EAA3B7AE-4E52-4774-9B23-D79F6E80E9BA} = {72E118D3-331E-4A8B-8F07-E13B0732344C} {106EB485-0E64-418A-A9E9-FD3AC4773D51} = {72E118D3-331E-4A8B-8F07-E13B0732344C}