diff --git a/Dfe.Academies.Academisation.Domain.Core/ProjectAggregate/SponsoredProject.cs b/Dfe.Academies.Academisation.Domain.Core/ProjectAggregate/SponsoredProject.cs index 7100408fd..58bbd76a4 100644 --- a/Dfe.Academies.Academisation.Domain.Core/ProjectAggregate/SponsoredProject.cs +++ b/Dfe.Academies.Academisation.Domain.Core/ProjectAggregate/SponsoredProject.cs @@ -2,5 +2,5 @@ { public record SponsoredProject(SponsoredProjectSchool? School, SponsoredProjectTrust? Trust); public record SponsoredProjectTrust(string Name, string ReferenceNumber); - public record SponsoredProjectSchool(string Name, int Urn, DateTime? OpeningDate, bool? PartOfPfiScheme); + public record SponsoredProjectSchool(string Name, int Urn, DateTime? OpeningDate, bool? PartOfPfiScheme, string? LocalAuthorityName, string? Region); } diff --git a/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs b/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs index 2f5044791..d68fe4a6c 100644 --- a/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs +++ b/Dfe.Academies.Academisation.Domain/ProjectAggregate/Project.cs @@ -116,6 +116,8 @@ public static CreateResult CreateFormAMat(IApplication application) public static CreateResult CreateSponsoredProject(SponsoredProject project) { + ArgumentNullException.ThrowIfNull(project); + if (project.Trust == null) { return new CreateValidationErrorResult(new List @@ -141,7 +143,9 @@ public static CreateResult CreateSponsoredProject(SponsoredProject project) NameOfTrust = project.Trust?.Name, AcademyTypeAndRoute = "Sponsored", ConversionSupportGrantAmount = 25000, - PartOfPfiScheme = ToYesNoString(project.School?.PartOfPfiScheme) ?? "No" + PartOfPfiScheme = ToYesNoString(project.School?.PartOfPfiScheme) ?? "No", + LocalAuthority = project.School?.LocalAuthorityName, + Region = project.School?.Region }; return new CreateSuccessResult(new Project(projectDetails)); diff --git a/Dfe.Academies.Academisation.IService/Commands/AdvisoryBoardDecision/IApplicationCreateCommand.cs b/Dfe.Academies.Academisation.IService/Commands/AdvisoryBoardDecision/IApplicationCreateCommand.cs deleted file mode 100644 index 5dbfde26b..000000000 --- a/Dfe.Academies.Academisation.IService/Commands/AdvisoryBoardDecision/IApplicationCreateCommand.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.IService.RequestModels; - -namespace Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; - -public interface IApplicationCreateCommand -{ - Task Execute(ApplicationCreateRequestModel applicationRequestModel); -} diff --git a/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj b/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj index bd009dda9..c66156d05 100644 --- a/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj +++ b/Dfe.Academies.Academisation.IService/Dfe.Academies.Academisation.IService.csproj @@ -6,12 +6,6 @@ enable - - - - - - diff --git a/Dfe.Academies.Academisation.IService/RequestModels/ApplicationCreateRequestModel.cs b/Dfe.Academies.Academisation.IService/RequestModels/ApplicationCreateRequestModel.cs deleted file mode 100644 index b2eaf2d17..000000000 --- a/Dfe.Academies.Academisation.IService/RequestModels/ApplicationCreateRequestModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; - -namespace Dfe.Academies.Academisation.IService.RequestModels; - -public class ApplicationCreateRequestModel -{ - public ApplicationCreateRequestModel(ApplicationType applicationType, ContributorRequestModel contributor) - { - ApplicationType = applicationType; - Contributor = contributor; - } - - public ApplicationType ApplicationType { get; } - public ContributorRequestModel Contributor { get; } -} diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/SponsoredProjectServiceModel.cs b/Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/SponsoredProjectServiceModel.cs index e9e31886d..eb1840aed 100644 --- a/Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/SponsoredProjectServiceModel.cs +++ b/Dfe.Academies.Academisation.IService/ServiceModels/Legacy/ProjectAggregate/SponsoredProjectServiceModel.cs @@ -18,5 +18,7 @@ public class SponsoredProjectSchoolServiceModel public int Urn { get; init; } public DateTime OpeningDate { get; init; } public bool PartOfPfiScheme { get; init; } + public string? LocalAuthorityName { get; init; } + public string? Region{ get; init; } } } diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationCreateCommandTest.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationCreateCommandTest.cs index abbc92f85..c8d0dfcb9 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationCreateCommandTest.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationCreateCommandTest.cs @@ -42,10 +42,10 @@ public async Task ApplicationReturnedFromFactory___ApplicationPassedToDataLayer_ .Setup(x => x.Create(It.IsAny(), It.IsAny())) .Returns(new CreateSuccessResult(app)); - ApplicationCreateCommand subject = new(_applicationFactoryMock.Object, _repo.Object, _mockMapper.Object); + ApplicationCreateCommandHandler subject = new(_applicationFactoryMock.Object, _repo.Object, _mockMapper.Object); // act - var result = await subject.Execute(applicationCreateRequestModel); + var result = await subject.Handle(applicationCreateRequestModel, default); // assert _repo.Verify(x => x.Insert(It.Is(y => y == app)), Times.Once()); @@ -68,10 +68,10 @@ public async Task ValidationErrorReturnedFromFactory___ApplicationNotPassedToDat .Setup(x => x.Create(It.IsAny(), It.IsAny())) .Returns(new CreateValidationErrorResult(new List())); - ApplicationCreateCommand subject = new(_applicationFactoryMock.Object, _repo.Object, _mockMapper.Object); + ApplicationCreateCommandHandler subject = new(_applicationFactoryMock.Object, _repo.Object, _mockMapper.Object); // act - var result = await subject.Execute(applicationCreateRequestModel); + var result = await subject.Handle(applicationCreateRequestModel, default); // assert _repo diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationSubmitCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationSubmitCommandTests.cs index 089081ae3..01bbe839a 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationSubmitCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/ApplicationSubmitCommandTests.cs @@ -47,7 +47,7 @@ public async Task NotFound___NotPassedToDataLayer_NotFoundReturned() _repo.Setup(x => x.GetByIdAsync(_applicationId)).ReturnsAsync((Application?)null); // act - var result = await _subject.Handle(new SubmitApplicationCommand(_applicationId), default(CancellationToken)); + var result = await _subject.Handle(new ApplicationSubmitCommand(_applicationId), default(CancellationToken)); // assert Assert.IsType(result); @@ -64,7 +64,7 @@ public async Task SubmitApplicationValidationError___NotPassedToUpdateDataComman _applicationSubmissionServiceMock.Setup(x => x.SubmitApplication(_applicationMock.Object)).Returns(commandValidationErrorResult); // act - var result = await _subject.Handle(new SubmitApplicationCommand(_applicationId), default(CancellationToken)); + var result = await _subject.Handle(new ApplicationSubmitCommand(_applicationId), default(CancellationToken)); // assert Assert.IsType(result); @@ -84,7 +84,7 @@ public async Task ProjectNotCreated___PassedToDataLayer_CommandSuccessReturned() .Returns(new CommandSuccessResult()); // act - var result = await _subject.Handle(new SubmitApplicationCommand(_applicationId), default(CancellationToken)); + var result = await _subject.Handle(new ApplicationSubmitCommand(_applicationId), default(CancellationToken)); // assert Assert.IsType(result); @@ -105,7 +105,7 @@ public async Task ProjectCreated___PassedToDataLayer_CreateSuccessReturned() .Returns(new CreateSuccessResult(_projectMock.Object)); // act - var result = await _subject.Handle(new SubmitApplicationCommand(_applicationId), default(CancellationToken)); + var result = await _subject.Handle(new ApplicationSubmitCommand(_applicationId), default(CancellationToken)); // assert Assert.IsType>(result); @@ -126,7 +126,7 @@ public async Task ProjectCreateValidationError___NotPassedToUpdateDataCommand_Va .Returns(createValidationErrorResult); // act - var result = await _subject.Handle(new SubmitApplicationCommand(_applicationId), default(CancellationToken)); + var result = await _subject.Handle(new ApplicationSubmitCommand(_applicationId), default(CancellationToken)); // assert Assert.IsType(result); diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Helpers/ApplicationCreateRequestModelBuilder.cs b/Dfe.Academies.Academisation.Service.UnitTest/Helpers/ApplicationCreateRequestModelBuilder.cs index f8f89d730..e220e6ec2 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Helpers/ApplicationCreateRequestModelBuilder.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Helpers/ApplicationCreateRequestModelBuilder.cs @@ -12,9 +12,9 @@ internal class ApplicationCreateRequestModelBuilder private static readonly Faker _faker = new(); - public ApplicationCreateRequestModel Build() + public ApplicationCreateCommand Build() { - return new ApplicationCreateRequestModel(_applicationType, _contributorRequestModel); + return new ApplicationCreateCommand(_applicationType, _contributorRequestModel); } public ApplicationCreateRequestModelBuilder WithApplicationType(ApplicationType applicationType) diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommand.cs index 5d612f330..2dda4f773 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommand.cs @@ -1,45 +1,17 @@ -using AutoMapper; -using Dfe.Academies.Academisation.Core; -using Dfe.Academies.Academisation.Domain.ApplicationAggregate; +using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; -using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; -using Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; -using Dfe.Academies.Academisation.IService.RequestModels; -using Dfe.Academies.Academisation.Service.Mappers.Application; +using MediatR; -namespace Dfe.Academies.Academisation.Service.Commands.Application; +namespace Dfe.Academies.Academisation.IService.RequestModels; -public class ApplicationCreateCommand : IApplicationCreateCommand +public class ApplicationCreateCommand : IRequest { - private readonly IApplicationFactory _domainFactory; - private readonly IApplicationRepository _applicationRepository; - private readonly IMapper _mapper; - - public ApplicationCreateCommand(IApplicationFactory domainFactory, IApplicationRepository applicationRepository, IMapper mapper) + public ApplicationCreateCommand(ApplicationType applicationType, ContributorRequestModel contributor) { - _domainFactory = domainFactory; - _applicationRepository = applicationRepository; - _mapper = mapper; + ApplicationType = applicationType; + Contributor = contributor; } - public async Task Execute(ApplicationCreateRequestModel applicationCreateRequestModel) - { - (ApplicationType applicationType, ContributorDetails contributorDetails) = applicationCreateRequestModel.AsDomain(); - var result = _domainFactory.Create(applicationType, contributorDetails); - - if (result is CreateValidationErrorResult domainValidationErrorResult) - { - return domainValidationErrorResult.MapToPayloadType(); - } - - if (result is not CreateSuccessResult domainSuccessResult) - { - throw new NotImplementedException("Other CreateResult types not expected"); - } - - await _applicationRepository.Insert(domainSuccessResult.Payload); - await _applicationRepository.UnitOfWork.SaveChangesAsync(); - - return domainSuccessResult.MapToPayloadType(ApplicationServiceModelMapper.MapFromDomain, _mapper); - } + public ApplicationType ApplicationType { get; } + public ContributorRequestModel Contributor { get; } } diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommandHandler.cs new file mode 100644 index 000000000..a9addbbd9 --- /dev/null +++ b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommandHandler.cs @@ -0,0 +1,46 @@ +using AutoMapper; +using Dfe.Academies.Academisation.Core; +using Dfe.Academies.Academisation.Domain.ApplicationAggregate; +using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; +using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; +using Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; +using Dfe.Academies.Academisation.IService.RequestModels; +using Dfe.Academies.Academisation.Service.Mappers.Application; +using MediatR; + +namespace Dfe.Academies.Academisation.Service.Commands.Application; + +public class ApplicationCreateCommandHandler : IRequestHandler +{ + private readonly IApplicationFactory _domainFactory; + private readonly IApplicationRepository _applicationRepository; + private readonly IMapper _mapper; + + public ApplicationCreateCommandHandler(IApplicationFactory domainFactory, IApplicationRepository applicationRepository, IMapper mapper) + { + _domainFactory = domainFactory; + _applicationRepository = applicationRepository; + _mapper = mapper; + } + + public async Task Handle(ApplicationCreateCommand applicationCreateRequestModel, CancellationToken cancellationToken) + { + (ApplicationType applicationType, ContributorDetails contributorDetails) = applicationCreateRequestModel.AsDomain(); + var result = _domainFactory.Create(applicationType, contributorDetails); + + if (result is CreateValidationErrorResult domainValidationErrorResult) + { + return domainValidationErrorResult.MapToPayloadType(); + } + + if (result is not CreateSuccessResult domainSuccessResult) + { + throw new NotImplementedException("Other CreateResult types not expected"); + } + + await _applicationRepository.Insert(domainSuccessResult.Payload); + await _applicationRepository.UnitOfWork.SaveChangesAsync(); + + return domainSuccessResult.MapToPayloadType(ApplicationServiceModelMapper.MapFromDomain, _mapper); + } +} diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/SubmitApplicationCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommand.cs similarity index 88% rename from Dfe.Academies.Academisation.IService/Commands/Application/SubmitApplicationCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommand.cs index fd7f2e998..a7f93a93f 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Application/SubmitApplicationCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommand.cs @@ -8,6 +8,6 @@ namespace Dfe.Academies.Academisation.IService.Commands.Application { - public record SubmitApplicationCommand( + public record ApplicationSubmitCommand( int applicationId) : IRequest; } diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs index e721de62d..1cd0b0b74 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/ApplicationSubmitCommandHandler.cs @@ -11,7 +11,7 @@ namespace Dfe.Academies.Academisation.Service.Commands.Application { - public class ApplicationSubmitCommandHandler : IRequestHandler + public class ApplicationSubmitCommandHandler : IRequestHandler { private readonly IApplicationRepository _applicationRepository; private readonly IProjectCreateDataCommand _projectCreateDataCommand; @@ -27,7 +27,7 @@ public ApplicationSubmitCommandHandler( _applicationSubmissionService = applicationSubmissionService; } - public async Task Handle(SubmitApplicationCommand command, CancellationToken cancellationToken) + public async Task Handle(ApplicationSubmitCommand command, CancellationToken cancellationToken) { var application = await _applicationRepository.GetByIdAsync(command.applicationId); diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/IApplicationUpdateCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/IApplicationUpdateCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/Commands/Application/IApplicationUpdateCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/IApplicationUpdateCommand.cs diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/CreateLeaseCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/CreateLeaseCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/CreateLeaseCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/CreateLeaseCommand.cs diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/CreateLoanCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/CreateLoanCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/CreateLoanCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/CreateLoanCommand.cs diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/DeleteLeaseCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteLeaseCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/DeleteLeaseCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteLeaseCommand.cs diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/DeleteLoanCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteLoanCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/DeleteLoanCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteLoanCommand.cs diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/DeleteSchoolCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteSchoolCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/Commands/Application/DeleteSchoolCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteSchoolCommand.cs diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/DeleteSchoolCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteSchoolCommandHandler.cs similarity index 99% rename from Dfe.Academies.Academisation.Service/Commands/Application/DeleteSchoolCommandHandler.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteSchoolCommandHandler.cs index 3a9d73116..1f27e4afa 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/DeleteSchoolCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/School/DeleteSchoolCommandHandler.cs @@ -3,7 +3,7 @@ using Dfe.Academies.Academisation.IService.Commands.Application; using MediatR; -namespace Dfe.Academies.Academisation.Service.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.School { public class DeleteSchoolCommandHandler : IRequestHandler { @@ -29,7 +29,7 @@ public async Task Handle(DeleteSchoolCommand command, Cancellatio var schoolToDelete = existingApplication.Schools.SingleOrDefault(x => x.Details.Urn == command.Urn); var result = existingApplication.DeleteSchool(command.Urn); - + if (result is CommandValidationErrorResult) { return result; diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/SetAdditionalDetailsCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/SetAdditionalDetailsCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/SetAdditionalDetailsCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/SetAdditionalDetailsCommand.cs diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/UpdateLeaseCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/UpdateLeaseCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/UpdateLeaseCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/UpdateLeaseCommand.cs diff --git a/Dfe.Academies.Academisation.IService/ServiceModels/Application/School/UpdateLoanCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/School/UpdateLoanCommand.cs similarity index 100% rename from Dfe.Academies.Academisation.IService/ServiceModels/Application/School/UpdateLoanCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/School/UpdateLoanCommand.cs diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/CreateTrustKeyPersonCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/CreateTrustKeyPersonCommand.cs similarity index 86% rename from Dfe.Academies.Academisation.IService/Commands/Application/CreateTrustKeyPersonCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/CreateTrustKeyPersonCommand.cs index 0f5ade3cb..b3a66b595 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Application/CreateTrustKeyPersonCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/CreateTrustKeyPersonCommand.cs @@ -4,7 +4,7 @@ using Dfe.Academies.Academisation.IService.ServiceModels.Application; using MediatR; -namespace Dfe.Academies.Academisation.IService.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public record CreateTrustKeyPersonCommand( int ApplicationId, diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/CreateTrustKeyPersonCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/CreateTrustKeyPersonCommandHandler.cs similarity index 96% rename from Dfe.Academies.Academisation.Service/Commands/Application/CreateTrustKeyPersonCommandHandler.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/CreateTrustKeyPersonCommandHandler.cs index 08b54764b..904bc379e 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/CreateTrustKeyPersonCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/CreateTrustKeyPersonCommandHandler.cs @@ -2,10 +2,9 @@ using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.ApplicationAggregate.Trusts; -using Dfe.Academies.Academisation.IService.Commands.Application; using MediatR; -namespace Dfe.Academies.Academisation.Service.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public class CreateTrustKeyPersonCommandHandler : IRequestHandler { @@ -30,7 +29,7 @@ public async Task Handle(CreateTrustKeyPersonCommand command, Can } var result = existingApplication.AddTrustKeyPerson(command.Name, command.DateOfBirth, command.Biography, command.Roles.Select(x => TrustKeyPersonRole.Create(x.Role, x.TimeInRole))); - + if (result is CommandValidationErrorResult) { return result; diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/DeleteTrustKeyPersonCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/DeleteTrustKeyPersonCommand.cs similarity index 76% rename from Dfe.Academies.Academisation.IService/Commands/Application/DeleteTrustKeyPersonCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/DeleteTrustKeyPersonCommand.cs index db0d79dd2..dbb7bb79f 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Application/DeleteTrustKeyPersonCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/DeleteTrustKeyPersonCommand.cs @@ -2,7 +2,7 @@ using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; using MediatR; -namespace Dfe.Academies.Academisation.IService.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public record DeleteTrustKeyPersonCommand( int ApplicationId, diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/DeleteTrustKeyPersonCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/DeleteTrustKeyPersonCommandHandler.cs similarity index 95% rename from Dfe.Academies.Academisation.Service/Commands/Application/DeleteTrustKeyPersonCommandHandler.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/DeleteTrustKeyPersonCommandHandler.cs index 50ff68cbe..6f82bc833 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/DeleteTrustKeyPersonCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/DeleteTrustKeyPersonCommandHandler.cs @@ -1,10 +1,9 @@ using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; -using Dfe.Academies.Academisation.IService.Commands.Application; using MediatR; using TrustKeyPerson = Dfe.Academies.Academisation.Domain.ApplicationAggregate.Trusts.TrustKeyPerson; -namespace Dfe.Academies.Academisation.Service.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public class DeleteTrustKeyPersonCommandHandler : IRequestHandler { @@ -28,7 +27,7 @@ public async Task Handle(DeleteTrustKeyPersonCommand command, Can } var result = existingApplication.DeleteTrustKeyPerson(command.KeyPersonId); - + if (result is CommandValidationErrorResult) { return result; diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/FormTrustCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/FormTrustCommandHandler.cs similarity index 96% rename from Dfe.Academies.Academisation.Service/Commands/Application/FormTrustCommandHandler.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/FormTrustCommandHandler.cs index 0fa79eb92..8eb09aab0 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/FormTrustCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/FormTrustCommandHandler.cs @@ -1,10 +1,9 @@ using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; -using Dfe.Academies.Academisation.IService.Commands.Application; using MediatR; -namespace Dfe.Academies.Academisation.Service.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public class FormTrustCommandHandler : IRequestHandler { diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/JoinTrustCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/JoinTrustCommandHandler.cs similarity index 95% rename from Dfe.Academies.Academisation.Service/Commands/Application/JoinTrustCommandHandler.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/JoinTrustCommandHandler.cs index 87e0d8e99..e76af258b 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/JoinTrustCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/JoinTrustCommandHandler.cs @@ -1,9 +1,8 @@ using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; -using Dfe.Academies.Academisation.IService.Commands.Application; using MediatR; -namespace Dfe.Academies.Academisation.Service.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public class JoinTrustCommandHandler : IRequestHandler { diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/SetFormTrustDetailsCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/SetFormTrustDetailsCommand.cs similarity index 92% rename from Dfe.Academies.Academisation.IService/Commands/Application/SetFormTrustDetailsCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/SetFormTrustDetailsCommand.cs index 297714258..02a044cc0 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Application/SetFormTrustDetailsCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/SetFormTrustDetailsCommand.cs @@ -6,7 +6,7 @@ using Dfe.Academies.Academisation.Core; using MediatR; -namespace Dfe.Academies.Academisation.IService.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public record SetFormTrustDetailsCommand( int applicationId, diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/SetJoinTrustDetailsCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/SetJoinTrustDetailsCommand.cs similarity index 88% rename from Dfe.Academies.Academisation.IService/Commands/Application/SetJoinTrustDetailsCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/SetJoinTrustDetailsCommand.cs index debb0ec85..a26487a31 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Application/SetJoinTrustDetailsCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/SetJoinTrustDetailsCommand.cs @@ -7,7 +7,7 @@ using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; using MediatR; -namespace Dfe.Academies.Academisation.IService.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public record SetJoinTrustDetailsCommand( int applicationId, diff --git a/Dfe.Academies.Academisation.IService/Commands/Application/UpdateTrustKeyPersonCommand.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/UpdateTrustKeyPersonCommand.cs similarity index 85% rename from Dfe.Academies.Academisation.IService/Commands/Application/UpdateTrustKeyPersonCommand.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/UpdateTrustKeyPersonCommand.cs index 0c661ccad..39a8abf49 100644 --- a/Dfe.Academies.Academisation.IService/Commands/Application/UpdateTrustKeyPersonCommand.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/UpdateTrustKeyPersonCommand.cs @@ -3,7 +3,7 @@ using Dfe.Academies.Academisation.IService.ServiceModels.Application; using MediatR; -namespace Dfe.Academies.Academisation.IService.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public record UpdateTrustKeyPersonCommand( int ApplicationId, diff --git a/Dfe.Academies.Academisation.Service/Commands/Application/UpdateTrustKeyPersonCommandHandler.cs b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/UpdateTrustKeyPersonCommandHandler.cs similarity index 95% rename from Dfe.Academies.Academisation.Service/Commands/Application/UpdateTrustKeyPersonCommandHandler.cs rename to Dfe.Academies.Academisation.Service/Commands/Application/Trust/UpdateTrustKeyPersonCommandHandler.cs index c5f83ae1b..62d2b2cae 100644 --- a/Dfe.Academies.Academisation.Service/Commands/Application/UpdateTrustKeyPersonCommandHandler.cs +++ b/Dfe.Academies.Academisation.Service/Commands/Application/Trust/UpdateTrustKeyPersonCommandHandler.cs @@ -1,10 +1,9 @@ using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.ApplicationAggregate.Trusts; -using Dfe.Academies.Academisation.IService.Commands.Application; using MediatR; -namespace Dfe.Academies.Academisation.Service.Commands.Application +namespace Dfe.Academies.Academisation.Service.Commands.Application.Trust { public class UpdateTrustKeyPersonCommandHandler : IRequestHandler { @@ -27,7 +26,7 @@ public async Task Handle(UpdateTrustKeyPersonCommand command, Can } var result = existingApplication.UpdateTrustKeyPerson(command.KeyPersonId, command.Name, command.DateOfBirth, command.Biography, command.Roles.Select(x => TrustKeyPersonRole.Create(x.Id, x.Role, x.TimeInRole))); - + if (result is CommandValidationErrorResult) { return result; diff --git a/Dfe.Academies.Academisation.Service/Mappers/Application/ApplicationCreateRequestModelMapper.cs b/Dfe.Academies.Academisation.Service/Mappers/Application/ApplicationCreateRequestModelMapper.cs index b340e9719..e64097405 100644 --- a/Dfe.Academies.Academisation.Service/Mappers/Application/ApplicationCreateRequestModelMapper.cs +++ b/Dfe.Academies.Academisation.Service/Mappers/Application/ApplicationCreateRequestModelMapper.cs @@ -5,7 +5,7 @@ namespace Dfe.Academies.Academisation.Service.Mappers.Application { internal static class ApplicationCreateRequestModelMapper { - internal static (ApplicationType, ContributorDetails) AsDomain(this ApplicationCreateRequestModel requestModel) + internal static (ApplicationType, ContributorDetails) AsDomain(this ApplicationCreateCommand requestModel) { ContributorDetails contributorDetails = new( requestModel.Contributor.FirstName, diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationCreateTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationCreateTests.cs index ddace726f..aad7153f7 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationCreateTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationCreateTests.cs @@ -1,6 +1,7 @@ using AutoFixture; using AutoMapper; using Bogus; +using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.Core.Test; using Dfe.Academies.Academisation.Data; using Dfe.Academies.Academisation.Data.Repositories; @@ -8,7 +9,6 @@ using Dfe.Academies.Academisation.Domain.ApplicationAggregate; using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; -using Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; using Dfe.Academies.Academisation.IService.Commands.Application; using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.IService.RequestModels; @@ -28,12 +28,11 @@ public class ApplicationCreateTests private readonly Fixture _fixture = new(); private readonly Faker _faker = new(); - private readonly IApplicationCreateCommand _applicationCreateCommand; private readonly IApplicationQueryService _applicationQueryService; private readonly IApplicationUpdateCommand _applicationUpdateCommand; - private readonly ILogger _applicationLogger; - private readonly IMediator _mediator; private readonly IApplicationFactory _applicationFactory = new ApplicationFactory(); + private readonly ILogger _applicationLogger; + private readonly Mock _mediator = new Mock(); private readonly AcademisationContext _context; private readonly IApplicationRepository _repo; @@ -45,13 +44,21 @@ public ApplicationCreateTests() _context = new TestApplicationContext().CreateContext(); _repo = new ApplicationRepository(_context, _mapper.Object); - _applicationCreateCommand = new ApplicationCreateCommand(_applicationFactory, _repo, _mapper.Object); _applicationQueryService = new ApplicationQueryService(_repo, _mapper.Object); _trustQueryService = new TrustQueryService(_context, _mapper.Object); _applicationUpdateCommand = new Mock().Object; _applicationLogger = new Mock>().Object; - _mediator = new Mock().Object; + + + var applicationCreateCommandHandler = new ApplicationCreateCommandHandler(_applicationFactory, _repo, _mapper.Object); + + _mediator.Setup(x => x.Send(It.IsAny(), It.IsAny())) + .Returns, CancellationToken>(async (cmd, ct) => + { + + return await applicationCreateCommandHandler.Handle((ApplicationCreateCommand)cmd, ct); + }); _fixture.Customize(composer => composer.With(c => c.EmailAddress, _faker.Internet.Email())); @@ -62,18 +69,17 @@ public async Task ParametersValid___ApplicationCreated() { // arrange var applicationController = new ApplicationController( - _applicationCreateCommand, _applicationQueryService, _applicationUpdateCommand, _trustQueryService, - _mediator, + _mediator.Object, _applicationLogger); - ApplicationCreateRequestModel applicationCreateRequestModel = _fixture - .Create(); + ApplicationCreateCommand applicationCreateRequestModel = _fixture + .Create(); // act - var result = await applicationController.Post(applicationCreateRequestModel); + var result = await applicationController.Post(applicationCreateRequestModel, default); // assert (CreatedAtRouteResult createdAtRouteResult, _) = DfeAssert.CreatedAtRoute(result, "GetApplication"); @@ -109,21 +115,20 @@ public async Task ParametersInvalid___ApplicationNotCreated() { // arrange var applicationController = new ApplicationController( - _applicationCreateCommand, _applicationQueryService, _applicationUpdateCommand, _trustQueryService, - _mediator, + _mediator.Object, _applicationLogger); _fixture.Customize(composer => composer.With(c => c.EmailAddress, _faker.Name.FullName())); - ApplicationCreateRequestModel applicationCreateRequestModel = _fixture - .Create(); + ApplicationCreateCommand applicationCreateRequestModel = _fixture + .Create(); // act - var result = await applicationController.Post(applicationCreateRequestModel); + var result = await applicationController.Post(applicationCreateRequestModel, default); // assert Assert.IsType(result.Result); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationSubmitTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationSubmitTests.cs index c8671ea1e..bb0cd6df6 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationSubmitTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationSubmitTests.cs @@ -44,7 +44,6 @@ public class ApplicationSubmitTests private readonly IProjectFactory _projectFactory = new ProjectFactory(); private readonly IApplicationSubmissionService _applicationSubmissionService; - private readonly IApplicationCreateCommand _applicationCreateCommand; private readonly IApplicationQueryService _applicationQueryService; private readonly IApplicationUpdateCommand _applicationUpdateCommand; private readonly ITrustQueryService _trustQueryService; @@ -68,16 +67,24 @@ public ApplicationSubmitTests() _applicationsListByUserQuery = new Mock().Object; _applicationLogger = new Mock>().Object; _applicationUpdateCommand = new ApplicationUpdateCommand(_repo); - _applicationCreateCommand = new ApplicationCreateCommand(_applicationFactory, _repo, _mapper.Object); _mediator = new Mock(); var submitApplicationHandler = new ApplicationSubmitCommandHandler(_repo, _projectCreateDataCommand, _applicationSubmissionService); - _mediator.Setup(x => x.Send(It.IsAny(), It.IsAny())) + _mediator.Setup(x => x.Send(It.IsAny(), It.IsAny())) .Returns, CancellationToken>(async (cmd, ct) => { - return await submitApplicationHandler.Handle((SubmitApplicationCommand)cmd, ct); + return await submitApplicationHandler.Handle((ApplicationSubmitCommand)cmd, ct); + }); + + var applicationCreateCommandHandler = new ApplicationCreateCommandHandler(_applicationFactory, _repo, _mapper.Object); + + _mediator.Setup(x => x.Send(It.IsAny(), It.IsAny())) + .Returns, CancellationToken>(async (cmd, ct) => + { + + return await applicationCreateCommandHandler.Handle((ApplicationCreateCommand)cmd, ct); }); _fixture.Customize(composer => @@ -104,17 +111,16 @@ public async Task JoinAMatApplicationExists___ApplicationIsSubmitted_And_Project { // Arrange var applicationController = new ApplicationController( - _applicationCreateCommand, _applicationQueryService, _applicationUpdateCommand, _trustQueryService, _mediator.Object, _applicationLogger); - ApplicationCreateRequestModel applicationCreateRequestModel = _fixture - .Create(); + ApplicationCreateCommand applicationCreateRequestModel = _fixture + .Create(); - var createResult = await applicationController.Post(applicationCreateRequestModel); + var createResult = await applicationController.Post(applicationCreateRequestModel, default); (_, var createdPayload) = DfeAssert.CreatedAtRoute(createResult, "GetApplication"); @@ -137,7 +143,7 @@ public async Task JoinAMatApplicationExists___ApplicationIsSubmitted_And_Project Assert.Equal(ApplicationStatus.Submitted, getPayload.ApplicationStatus); - var projectController = new LegacyProjectController(new LegacyProjectGetQuery(new ProjectGetDataQuery(_context)), Mock.Of(), + var projectController = new ProjectController(new LegacyProjectGetQuery(new ProjectGetDataQuery(_context)), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); var projectResult = await projectController.Get(1); @@ -152,17 +158,16 @@ public async Task FormAMatApplicationExists___ApplicationIsSubmitted_And_Project { // Arrange var applicationController = new ApplicationController( - _applicationCreateCommand, _applicationQueryService, _applicationUpdateCommand, _trustQueryService, _mediator.Object, _applicationLogger); - ApplicationCreateRequestModel applicationCreateRequestModel = new( + ApplicationCreateCommand applicationCreateRequestModel = new( ApplicationType.FormAMat, _fixture.Create()); - var createResult = await applicationController.Post(applicationCreateRequestModel); + var createResult = await applicationController.Post(applicationCreateRequestModel, default); (_, var createdPayload) = DfeAssert.CreatedAtRoute(createResult, "GetApplication"); @@ -192,7 +197,7 @@ public async Task FormAMatApplicationExists___ApplicationIsSubmitted_And_Project Assert.Equal(ApplicationStatus.Submitted, getPayload.ApplicationStatus); - var projectController = new LegacyProjectController(new LegacyProjectGetQuery(new ProjectGetDataQuery(_context)), new LegacyProjectListGetQuery(new ProjectListGetDataQuery(_context)), + var projectController = new ProjectController(new LegacyProjectGetQuery(new ProjectGetDataQuery(_context)), new LegacyProjectListGetQuery(new ProjectListGetDataQuery(_context)), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); var projectResults = await projectController.GetProjects(new GetAcademyConversionSearchModel(1, 3, null, null, null, null, new[] { $"A2B_{createdPayload.ApplicationReference!}" })); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationUpdateTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationUpdateTests.cs index fd6e0594e..e65e85b9c 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationUpdateTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ApplicationAggregate/ApplicationUpdateTests.cs @@ -29,7 +29,6 @@ public class ApplicationUpdateTests private readonly Fixture _fixture = new(); private readonly Faker _faker = new(); - private readonly IApplicationCreateCommand _applicationCreateCommand; private readonly IApplicationQueryService _applicationQueryService; private readonly IApplicationUpdateCommand _applicationUpdateCommand; private readonly IApplicationListByUserQuery _applicationsListByUserQuery; @@ -48,7 +47,6 @@ public ApplicationUpdateTests() _context = new TestApplicationContext().CreateContext(); _repo = new ApplicationRepository(_context, _mapper.Object); _applicationUpdateCommand = new ApplicationUpdateCommand(_repo); - _applicationCreateCommand = new ApplicationCreateCommand(_applicationFactory, _repo, _mapper.Object); _applicationQueryService = new ApplicationQueryService(_repo, _mapper.Object); _applicationsListByUserQuery = new Mock().Object; _trustQueryService = new TrustQueryService(_context, _mapper.Object); @@ -56,7 +54,6 @@ public ApplicationUpdateTests() _mediator = new Mock().Object; _applicationController = new( - _applicationCreateCommand, _applicationQueryService, _applicationUpdateCommand, _trustQueryService, @@ -185,9 +182,9 @@ public async Task StatusChangedToSubmittid___BadRequest_ApplicationNotUpdated() private async Task CreateExistingApplication() { - ApplicationCreateRequestModel applicationForCreate = new(ApplicationType.FormAMat, _fixture.Create());// with { ApplicationType = ApplicationType.FormAMat } ; + ApplicationCreateCommand applicationForCreate = new(ApplicationType.FormAMat, _fixture.Create());// with { ApplicationType = ApplicationType.FormAMat } ; - var createResult = await _applicationCreateCommand.Execute(applicationForCreate); + var createResult = await new ApplicationCreateCommandHandler(_applicationFactory, _repo, _mapper.Object).Handle(applicationForCreate, default); var createSuccessResult = Assert.IsType>(createResult); int id = createSuccessResult.Payload.ApplicationId; var schools = new List(); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectAddNoteTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectAddNoteTests.cs index dbb6fc614..b03b71d58 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectAddNoteTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectAddNoteTests.cs @@ -31,9 +31,9 @@ public LegacyProjectAddNoteTests() _createSponsoredProjectCommand = Mock.Of(); } - private LegacyProjectController System_under_test() + private ProjectController System_under_test() { - return new LegacyProjectController( + return new ProjectController( _projectGetQuery, _projectListGetQuery, _getStatusesQuery, @@ -50,7 +50,7 @@ public async Task Should_return_a_201_result_when_the_note_is_added_successfully .Setup(x => x.Execute(It.IsAny())) .Returns(Task.FromResult(new CommandSuccessResult() as CommandResult)); - LegacyProjectController controller = System_under_test(); + ProjectController controller = System_under_test(); ActionResult result = await controller.AddNote(1234, new AddNoteRequest("Subject", "Note", "Author", DateTime.Today)); @@ -65,7 +65,7 @@ public async Task Should_return_a_404_result_if_the_id_does_not_match_a_known_pr .Setup(x => x.Execute(It.IsAny())) .Returns(Task.FromResult(new NotFoundCommandResult() as CommandResult)); - LegacyProjectController controller = System_under_test(); + ProjectController controller = System_under_test(); ActionResult result = await controller.AddNote(1234, new AddNoteRequest("Subject", "Note", "Author", DateTime.UtcNow)); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetStatusesTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetStatusesTests.cs index 1810213b7..bb0e5afd5 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetStatusesTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetStatusesTests.cs @@ -13,7 +13,7 @@ namespace Dfe.Academies.Academisation.SubcutaneousTest.ProjectAggregate; public class LegacyProjectGetStatusesTests { - private readonly LegacyProjectController _legacyProjectController; + private readonly ProjectController _projectController; private readonly AcademisationContext _context; public LegacyProjectGetStatusesTests() @@ -23,7 +23,7 @@ public LegacyProjectGetStatusesTests() IProjectStatusesDataQuery dataQuery = new ProjectStatusesDataQuery(_context); IProjectGetStatusesQuery query = new ProjectGetStatusesQuery(dataQuery); - _legacyProjectController = new LegacyProjectController(Mock.Of(), Mock.Of(), + _projectController = new ProjectController(Mock.Of(), Mock.Of(), query, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); } @@ -35,7 +35,7 @@ public async Task ProjectExists___ProjectReturned() await _context.SaveChangesAsync(); // act - var result = await _legacyProjectController.GetFilterParameters(); + var result = await _projectController.GetFilterParameters(); // assert var response = DfeAssert.OkObjectResult(result); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs index bf044eb24..342d3661f 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs @@ -16,7 +16,7 @@ namespace Dfe.Academies.Academisation.SubcutaneousTest.ProjectAggregate; public class ProjectGetTests { - private readonly LegacyProjectController _legacyProjectController; + private readonly ProjectController _projectController; private readonly AcademisationContext _context; private readonly Fixture _fixture = new(); @@ -27,7 +27,7 @@ public ProjectGetTests() IProjectGetDataQuery projectGetDataQuery = new ProjectGetDataQuery(_context); ILegacyProjectGetQuery legacyProjectGetQuery = new LegacyProjectGetQuery(projectGetDataQuery); - _legacyProjectController = new LegacyProjectController(legacyProjectGetQuery, Mock.Of(), + _projectController = new ProjectController(legacyProjectGetQuery, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); } @@ -40,7 +40,7 @@ public async Task ProjectExists___ProjectReturned() await _context.SaveChangesAsync(); // act - ActionResult result = await _legacyProjectController.Get(existingProject.Id); + ActionResult result = await _projectController.Get(existingProject.Id); // assert result.Result.Should().BeOfType(); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs index 9fe160ce4..4fd09b374 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectListGetTests.cs @@ -14,7 +14,7 @@ namespace Dfe.Academies.Academisation.SubcutaneousTest.ProjectAggregate; public class LegacyProjectListGetTests { - private readonly LegacyProjectController _subject; + private readonly ProjectController _subject; private readonly AcademisationContext _context; private readonly Fixture _fixture = new(); @@ -25,7 +25,7 @@ public LegacyProjectListGetTests() IProjectListGetDataQuery projectGetDataQuery = new ProjectListGetDataQuery(_context); ILegacyProjectListGetQuery legacyProjectGetQuery = new LegacyProjectListGetQuery(projectGetDataQuery); - _subject = new LegacyProjectController(Mock.Of(), legacyProjectGetQuery, + _subject = new ProjectController(Mock.Of(), legacyProjectGetQuery, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(),Mock.Of()); } diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs index bfc546409..7f535d246 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs @@ -45,7 +45,7 @@ public ProjectUpdateTests() public async Task ProjectExists___FullProjectIsUpdated() { // Arrange - var legacyProjectController = new LegacyProjectController(_legacyProjectGetQuery, Mock.Of(), + var legacyProjectController = new ProjectController(_legacyProjectGetQuery, Mock.Of(), Mock.Of(), _legacyProjectUpdateCommand, Mock.Of(), Mock.Of(), Mock.Of()); var existingProject = _fixture.Create(); @@ -73,7 +73,7 @@ public async Task ProjectExists___FullProjectIsUpdated() public async Task ProjectExists_FullProjectIsReturnedOnGet() { // Arrange - var legacyProjectController = new LegacyProjectController(_legacyProjectGetQuery, Mock.Of(), + var legacyProjectController = new ProjectController(_legacyProjectGetQuery, Mock.Of(), Mock.Of(), _legacyProjectUpdateCommand, Mock.Of(), Mock.Of(), Mock.Of()); var existingProject = _fixture.Create(); @@ -103,7 +103,7 @@ public async Task ProjectExists_FullProjectIsReturnedOnGet() public async Task ProjectExists___PartialProjectIsUpdated() { // Arrange - var legacyProjectController = new LegacyProjectController(_legacyProjectGetQuery, Mock.Of(), + var legacyProjectController = new ProjectController(_legacyProjectGetQuery, Mock.Of(), Mock.Of(), _legacyProjectUpdateCommand, Mock.Of(), Mock.Of(), Mock.Of()); var existingProject = _fixture.Create(); diff --git a/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ConversionApplicationControllerTests.cs b/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ConversionApplicationControllerTests.cs index ea54ee3fe..2b4683d3b 100644 --- a/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ConversionApplicationControllerTests.cs +++ b/Dfe.Academies.Academisation.WebApi.UnitTest/Controller/ConversionApplicationControllerTests.cs @@ -22,7 +22,6 @@ namespace Dfe.Academies.Academisation.WebApi.UnitTest.Controller public class ApplicationControllerTests { private readonly Fixture _fixture = new(); - private readonly Mock _createCommandMock = new(); private readonly Mock _getQueryMock = new(); private readonly Mock _updateCommandMock = new(); private readonly Mock> _applicationLogger = new (); @@ -32,21 +31,22 @@ public class ApplicationControllerTests public ApplicationControllerTests() { - _subject = new ApplicationController(_createCommandMock.Object, _getQueryMock.Object, _updateCommandMock.Object, _trustQueryService.Object, _mockMediator.Object, _applicationLogger.Object); + _subject = new ApplicationController(_getQueryMock.Object, _updateCommandMock.Object, _trustQueryService.Object, _mockMediator.Object, _applicationLogger.Object); } [Fact] public async Task Post___ServiceReturnsSuccess___SuccessResponseReturned() { // arrange - var requestModel = _fixture.Create(); - + var requestModel = _fixture.Create(); var applicationServiceModel = _fixture.Create(); - _createCommandMock.Setup(x => x.Execute(requestModel)) + + var cancelationToken = default(CancellationToken); + _mockMediator.Setup(x => x.Send(requestModel, cancelationToken)) .ReturnsAsync(new CreateSuccessResult(applicationServiceModel)); // act - var result = await _subject.Post(requestModel); + var result = await _subject.Post(requestModel, cancelationToken); // assert var createdResult = Assert.IsType(result.Result); @@ -59,13 +59,15 @@ public async Task Post___ServiceReturnsSuccess___SuccessResponseReturned() public async Task Post___ServiceReturnsValidationError___BadRequestResponseReturned() { // arrange - var requestModel = _fixture.Create(); + var requestModel = _fixture.Create(); var expectedValidationError = new List() { new ValidationError("PropertyName", "Error message") }; - _createCommandMock.Setup(x => x.Execute(requestModel)) + + var cancelationToken = default(CancellationToken); + _mockMediator.Setup(x => x.Send(requestModel, cancelationToken)) .ReturnsAsync(new CreateValidationErrorResult(expectedValidationError)); // act - var result = await _subject.Post(requestModel); + var result = await _subject.Post(requestModel, cancelationToken); // assert var badRequestResult = Assert.IsType(result.Result); @@ -79,7 +81,7 @@ public async Task Submit___ServiceReturnsNotFound___NotFoundReturned() // arrange int applicationId = _fixture.Create(); - _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) + _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) .ReturnsAsync(new NotFoundCommandResult()); // act @@ -97,7 +99,7 @@ public async Task Submit___ServiceReturnsCommandValidationError___BadRequestRetu List expectedValidationError = new(); - _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) + _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) .ReturnsAsync(new CommandValidationErrorResult(expectedValidationError)); // act @@ -115,7 +117,7 @@ public async Task Submit___ServiceReturnsCommandSuccess___SuccessResponseReturne // arrange int applicationId = _fixture.Create(); - _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) + _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) .ReturnsAsync(new CommandSuccessResult()); // act @@ -132,7 +134,7 @@ public async Task Submit___ServiceReturnsCreateValidationError___BadRequestRetur int applicationId = _fixture.Create(); List expectedValidationError = new(); - _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) + _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) .ReturnsAsync(new CreateValidationErrorResult(expectedValidationError)); // act @@ -151,7 +153,7 @@ public async Task Submit___ServiceReturnsCreateSuccess___BadRequestReturned() int applicationId = _fixture.Create(); LegacyProjectServiceModel projectServiceModel = new LegacyProjectServiceModel(1, 1); - _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) + _mockMediator.Setup(x => x.Send(It.Is(cmd => cmd.applicationId == applicationId), It.IsAny())) .ReturnsAsync(new CreateSuccessResult(projectServiceModel)); // act diff --git a/Dfe.Academies.Academisation.WebApi/Controllers/ApplicationController.cs b/Dfe.Academies.Academisation.WebApi/Controllers/ApplicationController.cs index 85b3ac7e6..31353bad6 100644 --- a/Dfe.Academies.Academisation.WebApi/Controllers/ApplicationController.cs +++ b/Dfe.Academies.Academisation.WebApi/Controllers/ApplicationController.cs @@ -1,12 +1,16 @@ -using Dfe.Academies.Academisation.Core; +using System.Threading; +using System; +using Dfe.Academies.Academisation.Core; using Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; using Dfe.Academies.Academisation.IService.Commands.Application; using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.IService.RequestModels; using Dfe.Academies.Academisation.IService.ServiceModels.Application; using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate; +using Dfe.Academies.Academisation.Service.Commands.Application.Trust; using MediatR; using Microsoft.AspNetCore.Mvc; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace Dfe.Academies.Academisation.WebApi.Controllers { @@ -16,14 +20,13 @@ namespace Dfe.Academies.Academisation.WebApi.Controllers public class ApplicationController : ControllerBase { private const string GetRouteName = "GetApplication"; - private readonly IApplicationCreateCommand _applicationCreateCommand; private readonly IApplicationQueryService _applicationQueryService; private readonly IApplicationUpdateCommand _applicationUpdateCommand; private readonly ITrustQueryService _trustQueryService; private readonly IMediator _mediator; private readonly ILogger _logger; - public ApplicationController(IApplicationCreateCommand applicationCreateCommand, + public ApplicationController( IApplicationQueryService applicationQueryService, IApplicationUpdateCommand applicationUpdateCommand, ITrustQueryService trustQueryService, @@ -32,7 +35,6 @@ ILogger logger ) { // need guard clauses on these check for null - _applicationCreateCommand = applicationCreateCommand; _applicationQueryService = applicationQueryService; _applicationUpdateCommand = applicationUpdateCommand; _trustQueryService = trustQueryService; @@ -43,10 +45,10 @@ ILogger logger [ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [HttpPost] - public async Task> Post([FromBody] ApplicationCreateRequestModel request) + public async Task> Post([FromBody] ApplicationCreateCommand command, CancellationToken cancellationToken) { - _logger.LogInformation($"Creating application using post endpoint with contributor: {request?.Contributor?.EmailAddress}"); - var result = await _applicationCreateCommand.Execute(request); + _logger.LogInformation($"Creating application using post endpoint with contributor: {command?.Contributor?.EmailAddress}"); + var result = await _mediator.Send(command, cancellationToken).ConfigureAwait(false); return result switch { @@ -203,7 +205,7 @@ public async Task> GetKeyPerson(int applicationId, int keyP public async Task Submit(int applicationId) { _logger.LogInformation($"Submitting application: {applicationId}"); - var result = await _mediator.Send(new SubmitApplicationCommand(applicationId)).ConfigureAwait(false); + var result = await _mediator.Send(new ApplicationSubmitCommand(applicationId)).ConfigureAwait(false); return result switch { diff --git a/Dfe.Academies.Academisation.WebApi/Controllers/LegacyProjectController.cs b/Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs similarity index 98% rename from Dfe.Academies.Academisation.WebApi/Controllers/LegacyProjectController.cs rename to Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs index 3592cfd23..b688fe90e 100644 --- a/Dfe.Academies.Academisation.WebApi/Controllers/LegacyProjectController.cs +++ b/Dfe.Academies.Academisation.WebApi/Controllers/ProjectController.cs @@ -13,7 +13,7 @@ namespace Dfe.Academies.Academisation.WebApi.Controllers [Route("legacy/")] [ApiController] [ProducesResponseType(StatusCodes.Status401Unauthorized)] - public class LegacyProjectController : ControllerBase + public class ProjectController : ControllerBase { private readonly ILegacyProjectAddNoteCommand _legacyProjectAddNoteCommand; private readonly ILegacyProjectDeleteNoteCommand _legacyProjectDeleteNoteCommand; @@ -23,7 +23,7 @@ public class LegacyProjectController : ControllerBase private readonly IProjectGetStatusesQuery _projectGetStatusesQuery; private readonly ICreateSponsoredProjectCommand _createSponsoredProjectCommand; - public LegacyProjectController(ILegacyProjectGetQuery legacyProjectGetQuery, + public ProjectController(ILegacyProjectGetQuery legacyProjectGetQuery, ILegacyProjectListGetQuery legacyProjectListGetQuery, IProjectGetStatusesQuery projectGetStatusesQuery, ILegacyProjectUpdateCommand legacyProjectUpdateCommand, @@ -167,7 +167,7 @@ public async Task AddSponsoredConversion(SponsoredProjectServiceMo CommandSuccessResult => Created(new Uri("/legacy/project/", UriKind.Relative), null), NotFoundCommandResult => NotFound(), _ => throw new NotImplementedException() - }; + }; } /// diff --git a/Dfe.Academies.Academisation.WebApi/Program.cs b/Dfe.Academies.Academisation.WebApi/Program.cs index 103d059ba..8eaa9833e 100644 --- a/Dfe.Academies.Academisation.WebApi/Program.cs +++ b/Dfe.Academies.Academisation.WebApi/Program.cs @@ -27,6 +27,7 @@ using Dfe.Academies.Academisation.Service.Commands.AdvisoryBoardDecision; using Dfe.Academies.Academisation.Service.Commands.Application; using Dfe.Academies.Academisation.Service.Commands.Application.School; +using Dfe.Academies.Academisation.Service.Commands.Application.Trust; using Dfe.Academies.Academisation.Service.Commands.Legacy.Project; using Dfe.Academies.Academisation.Service.CommandValidations; using Dfe.Academies.Academisation.Service.Queries; @@ -95,7 +96,6 @@ builder.Services.Configure(apiKeysConfiguration); // Commands -builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/release-notes.md b/release-notes.md index 751b56eab..5c467fb06 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,4 +1,8 @@ +## 9.0.0 +* Refactoring the command/command handlers to be consistent + ## 8.0.0 * The term 'Involuntary Conversion' has been replaced with 'Sponsored Conversion'. This includes all Api endpoints. Note this release is required for the corresponding changes in the prepare-conversions application to work. - +* User Story 129594 : The Local Authority and Region for a school is now passed up to the Academisation Api during involuntary project creation. This avoids the delay in populating the two values within the Academisation Api as they're already known during the conversion process. +* LA Dates can be set back to null --- \ No newline at end of file