Skip to content

Commit

Permalink
Merge pull request #263 from DFE-Digital/feature/130614-change-Involu…
Browse files Browse the repository at this point in the history
…ntary-to-Sponsored

Feature/130614 change involuntary to sponsored
  • Loading branch information
chrisdexnimble authored Jun 5, 2023
2 parents 8c60714 + e2bda5e commit ef714d8
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
using System.Threading.Tasks;
using AutoFixture;
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Data.ProjectAggregate;
using Dfe.Academies.Academisation.Data.UnitTest.Contexts;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using FluentAssertions;
using Xunit;

namespace Dfe.Academies.Academisation.Data.UnitTest.ProjectAggregate
{
public class CreateInvoluntaryProjectCommandTests
public class CreateSponsoredProjectCommandTests
{
private readonly InvoluntaryProject _newProject;
private readonly SponsoredProject _newProject;
private readonly AcademisationContext _context;
private readonly IProjectCreateDataCommand _projectCreateDataCommand;
private readonly Fixture _fixture;

public CreateInvoluntaryProjectCommandTests()
public CreateSponsoredProjectCommandTests()
{
_fixture = new Fixture();
ProjectState projectState = _fixture.Create<ProjectState>();
Expand All @@ -29,18 +29,18 @@ public CreateInvoluntaryProjectCommandTests()
_context.Projects.Add(projectState);
_context.SaveChanges();

_newProject = _fixture.Create<InvoluntaryProject>();
_newProject = _fixture.Create<SponsoredProject>();
}

private CreateInvoluntaryProjectDataCommand System_under_test()
private CreateSponsoredProjectDataCommand System_under_test()
{
return new CreateInvoluntaryProjectDataCommand(_projectCreateDataCommand);
return new CreateSponsoredProjectDataCommand(_projectCreateDataCommand);
}

[Fact]
public async Task Should_add_the_new_involuntary_project()
public async Task Should_add_the_new_sponsored_project()
{
CreateInvoluntaryProjectDataCommand command = System_under_test();
CreateSponsoredProjectDataCommand command = System_under_test();

await command.Execute(_newProject);

Expand All @@ -50,18 +50,18 @@ public async Task Should_add_the_new_involuntary_project()
[Fact]
public async Task Should_return_error_if_school_is_null()
{
CreateInvoluntaryProjectDataCommand command = System_under_test();
CreateSponsoredProjectDataCommand command = System_under_test();

var result = await command.Execute(new InvoluntaryProject(null, _fixture.Create<InvoluntaryProjectTrust>()));
var result = await command.Execute(new SponsoredProject(null, _fixture.Create<SponsoredProjectTrust>()));

result.Should().BeOfType<CommandValidationErrorResult>();
}
[Fact]
public async Task Should_return_error_if_join_trust_is_null()
{
CreateInvoluntaryProjectDataCommand command = System_under_test();
CreateSponsoredProjectDataCommand command = System_under_test();

var result = await command.Execute(new InvoluntaryProject(_fixture.Create<InvoluntaryProjectSchool>(), null));
var result = await command.Execute(new SponsoredProject(_fixture.Create<SponsoredProjectSchool>(), null));

result.Should().BeOfType<CommandValidationErrorResult>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.ProjectAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ProjectAggregate;

namespace Dfe.Academies.Academisation.Data.ProjectAggregate
{
public class CreateInvoluntaryProjectDataCommand : ICreateInvoluntaryProjectDataCommand
public class CreateSponsoredProjectDataCommand : ICreateSponsoredProjectDataCommand
{
private readonly IProjectCreateDataCommand _projectCreateDataCommand;
public CreateInvoluntaryProjectDataCommand(IProjectCreateDataCommand projectCreateDataCommand)
public CreateSponsoredProjectDataCommand(IProjectCreateDataCommand projectCreateDataCommand)
{
_projectCreateDataCommand = projectCreateDataCommand;
}

public async Task<CommandResult> Execute(Core.ProjectAggregate.InvoluntaryProject project)
public async Task<CommandResult> Execute(SponsoredProject project)
{
var domainServiceResult = Project.CreateInvoluntaryProject(project);
var domainServiceResult = Project.CreateSponsoredProject(project);

switch (domainServiceResult)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Dfe.Academies.Academisation.Domain.Core.ProjectAggregate
{
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);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ApplicationAggregate;
Expand Down Expand Up @@ -115,7 +114,7 @@ public static CreateResult CreateFormAMat(IApplication application)
return new CreateSuccessResult<IEnumerable<IProject>>(projectList);
}

public static CreateResult CreateInvoluntaryProject(InvoluntaryProject project)
public static CreateResult CreateSponsoredProject(SponsoredProject project)
{
if (project.Trust == null)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;

namespace Dfe.Academies.Academisation.IData.ProjectAggregate
{
public interface ICreateSponsoredProjectDataCommand
{
Task<CommandResult> Execute(SponsoredProject project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Dfe.Academies.Academisation.IService.Commands.Legacy.Project
{
public interface ICreateInvoluntaryProjectCommand
public interface ICreateSponsoredProjectCommand
{
Task<CommandResult> Execute(InvoluntaryProjectServiceModel model);
Task<CommandResult> Execute(SponsoredProjectServiceModel model);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate
{
public class InvoluntaryProjectServiceModel
public class SponsoredProjectServiceModel
{
public InvoluntaryProjectSchoolServiceModel? School { get; init; }
public InvoluntaryProjectTrustServiceModel? Trust { get; init; }
public SponsoredProjectSchoolServiceModel? School { get; init; }
public SponsoredProjectTrustServiceModel? Trust { get; init; }
}

public class InvoluntaryProjectTrustServiceModel
public class SponsoredProjectTrustServiceModel
{
public string? Name { get; init; }
public string? ReferenceNumber { get; init; }
}

public class InvoluntaryProjectSchoolServiceModel
public class SponsoredProjectSchoolServiceModel
{
public string? Name { get; init; }
public int Urn { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
using AutoMapper;
using Dfe.Academies.Academisation.Core;
using Dfe.Academies.Academisation.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.IData.ProjectAggregate;
using Dfe.Academies.Academisation.IService.Commands.Legacy.Project;
using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate;

namespace Dfe.Academies.Academisation.Service.Commands.Legacy.Project
{
public class CreateInvoluntaryProjectCommand : ICreateInvoluntaryProjectCommand
public class CreateSponsoredProjectCommand : ICreateSponsoredProjectCommand
{
private readonly IMapper _mapper;
private readonly ICreateInvoluntaryProjectDataCommand _createInvoluntaryProjectDataCommand;
private readonly ICreateSponsoredProjectDataCommand _createSponsoredProjectDataCommand;

public CreateInvoluntaryProjectCommand(
public CreateSponsoredProjectCommand(
IMapper mapper,
ICreateInvoluntaryProjectDataCommand createInvoluntaryProjectDataCommand)
ICreateSponsoredProjectDataCommand createSponsoredProjectDataCommand)
{
_mapper = mapper;
_createInvoluntaryProjectDataCommand = createInvoluntaryProjectDataCommand;
_createSponsoredProjectDataCommand = createSponsoredProjectDataCommand;
}

public async Task<CommandResult> Execute(InvoluntaryProjectServiceModel model)
public async Task<CommandResult> Execute(SponsoredProjectServiceModel model)
{
var result = await _createInvoluntaryProjectDataCommand.Execute(_mapper.Map<InvoluntaryProject>(model));
var result = await _createSponsoredProjectDataCommand.Execute(_mapper.Map<SponsoredProject>(model));

if (result is CommandValidationErrorResult)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task JoinAMatApplicationExists___ApplicationIsSubmitted_And_Project

var projectController = new LegacyProjectController(new LegacyProjectGetQuery(new ProjectGetDataQuery(_context)), Mock.Of<ILegacyProjectListGetQuery>(),
Mock.Of<IProjectGetStatusesQuery>(), Mock.Of<ILegacyProjectUpdateCommand>(), Mock.Of<ILegacyProjectAddNoteCommand>(), Mock.Of<ILegacyProjectDeleteNoteCommand>(),
Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ICreateSponsoredProjectCommand>());
var projectResult = await projectController.Get(1);

(_, LegacyProjectServiceModel project) = DfeAssert.OkObjectResult(projectResult);
Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task FormAMatApplicationExists___ApplicationIsSubmitted_And_Project

var projectController = new LegacyProjectController(new LegacyProjectGetQuery(new ProjectGetDataQuery(_context)), new LegacyProjectListGetQuery(new ProjectListGetDataQuery(_context)),
Mock.Of<IProjectGetStatusesQuery>(), Mock.Of<ILegacyProjectUpdateCommand>(), Mock.Of<ILegacyProjectAddNoteCommand>(), Mock.Of<ILegacyProjectDeleteNoteCommand>(),
Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ICreateSponsoredProjectCommand>());
var projectResults = await projectController.GetProjects(new GetAcademyConversionSearchModel(1, 3, null, null, null, null, new[] { $"A2B_{createdPayload.ApplicationReference!}" }));

(_, LegacyApiResponse<LegacyProjectServiceModel> projects) = DfeAssert.OkObjectResult(projectResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LegacyProjectAddNoteTests
private readonly ILegacyProjectGetQuery _projectGetQuery;
private readonly ILegacyProjectListGetQuery _projectListGetQuery;
private readonly ILegacyProjectUpdateCommand _projectUpdateCommand;
private readonly ICreateInvoluntaryProjectCommand _createInvoluntaryProjectCommand;
private readonly ICreateSponsoredProjectCommand _createSponsoredProjectCommand;
private ILegacyProjectDeleteNoteCommand _projectDeleteNoteCommand;

public LegacyProjectAddNoteTests()
Expand All @@ -28,7 +28,7 @@ public LegacyProjectAddNoteTests()
_projectUpdateCommand = Mock.Of<ILegacyProjectUpdateCommand>();
_projectAddNoteCommand = new Mock<ILegacyProjectAddNoteCommand>();
_projectDeleteNoteCommand = Mock.Of<ILegacyProjectDeleteNoteCommand>();
_createInvoluntaryProjectCommand = Mock.Of<ICreateInvoluntaryProjectCommand>();
_createSponsoredProjectCommand = Mock.Of<ICreateSponsoredProjectCommand>();
}

private LegacyProjectController System_under_test()
Expand All @@ -40,7 +40,7 @@ private LegacyProjectController System_under_test()
_projectUpdateCommand,
_projectAddNoteCommand.Object,
_projectDeleteNoteCommand,
_createInvoluntaryProjectCommand);
_createSponsoredProjectCommand);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LegacyProjectGetStatusesTests()
IProjectGetStatusesQuery query = new ProjectGetStatusesQuery(dataQuery);

_legacyProjectController = new LegacyProjectController(Mock.Of<ILegacyProjectGetQuery>(), Mock.Of<ILegacyProjectListGetQuery>(),
query, Mock.Of<ILegacyProjectUpdateCommand>(), Mock.Of<ILegacyProjectAddNoteCommand>(), Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateInvoluntaryProjectCommand>());
query, Mock.Of<ILegacyProjectUpdateCommand>(), Mock.Of<ILegacyProjectAddNoteCommand>(), Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateSponsoredProjectCommand>());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProjectGetTests()

_legacyProjectController = new LegacyProjectController(legacyProjectGetQuery, Mock.Of<ILegacyProjectListGetQuery>(),
Mock.Of<IProjectGetStatusesQuery>(), Mock.Of<ILegacyProjectUpdateCommand>(), Mock.Of<ILegacyProjectAddNoteCommand>(),
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateSponsoredProjectCommand>());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public LegacyProjectListGetTests()

_subject = new LegacyProjectController(Mock.Of<ILegacyProjectGetQuery>(), legacyProjectGetQuery,
Mock.Of<IProjectGetStatusesQuery>(), Mock.Of<ILegacyProjectUpdateCommand>(), Mock.Of<ILegacyProjectAddNoteCommand>(),
Mock.Of<ILegacyProjectDeleteNoteCommand>(),Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ILegacyProjectDeleteNoteCommand>(),Mock.Of<ICreateSponsoredProjectCommand>());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task ProjectExists___FullProjectIsUpdated()
// Arrange
var legacyProjectController = new LegacyProjectController(_legacyProjectGetQuery, Mock.Of<ILegacyProjectListGetQuery>(),
Mock.Of<IProjectGetStatusesQuery>(), _legacyProjectUpdateCommand, Mock.Of<ILegacyProjectAddNoteCommand>(),
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateSponsoredProjectCommand>());
var existingProject = _fixture.Create<ProjectState>();
await _context.Projects.AddAsync(existingProject);
await _context.SaveChangesAsync();
Expand Down Expand Up @@ -75,7 +75,7 @@ public async Task ProjectExists_FullProjectIsReturnedOnGet()
// Arrange
var legacyProjectController = new LegacyProjectController(_legacyProjectGetQuery, Mock.Of<ILegacyProjectListGetQuery>(),
Mock.Of<IProjectGetStatusesQuery>(), _legacyProjectUpdateCommand, Mock.Of<ILegacyProjectAddNoteCommand>(),
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateSponsoredProjectCommand>());
var existingProject = _fixture.Create<ProjectState>();
await _context.Projects.AddAsync(existingProject);
await _context.SaveChangesAsync();
Expand Down Expand Up @@ -105,7 +105,7 @@ public async Task ProjectExists___PartialProjectIsUpdated()
// Arrange
var legacyProjectController = new LegacyProjectController(_legacyProjectGetQuery, Mock.Of<ILegacyProjectListGetQuery>(),
Mock.Of<IProjectGetStatusesQuery>(), _legacyProjectUpdateCommand, Mock.Of<ILegacyProjectAddNoteCommand>(),
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateInvoluntaryProjectCommand>());
Mock.Of<ILegacyProjectDeleteNoteCommand>(), Mock.Of<ICreateSponsoredProjectCommand>());
var existingProject = _fixture.Create<ProjectState>();

await _context.Projects.AddAsync(existingProject);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Ardalis.GuardClauses;
using AutoMapper;
using Dfe.Academies.Academisation.Core.ProjectAggregate;
using Dfe.Academies.Academisation.Domain.ApplicationAggregate.Trusts;
using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate;
using Dfe.Academies.Academisation.IDomain.ApplicationAggregate;
using Dfe.Academies.Academisation.IService.ServiceModels.Application;
using Dfe.Academies.Academisation.IService.ServiceModels.Application.School;
Expand All @@ -22,9 +22,9 @@ public static void AddMappings(Profile profile)
// .ForMember(x => x.DynamicsApplicationId, opt => opt.Ignore());
//profile.CreateMap<JoinTrustState, JoinTrust>();
profile.CreateMap<IJoinTrust, ApplicationJoinTrustServiceModel>();
profile.CreateMap<InvoluntaryProjectServiceModel, InvoluntaryProject>();
profile.CreateMap<InvoluntaryProjectTrustServiceModel, InvoluntaryProjectTrust>();
profile.CreateMap<InvoluntaryProjectSchoolServiceModel, InvoluntaryProjectSchool>();
profile.CreateMap<SponsoredProjectServiceModel, SponsoredProject>();
profile.CreateMap<SponsoredProjectTrustServiceModel, SponsoredProjectTrust>();
profile.CreateMap<SponsoredProjectSchoolServiceModel, SponsoredProjectSchool>();

// the mapping for this object is awkward because of the use of records, may have to re-think someof this but this is the best for now
//profile.CreateMap<FormTrustState, FormTrustDetails>().ReverseMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public class LegacyProjectController : ControllerBase
private readonly ILegacyProjectListGetQuery _legacyProjectListGetQuery;
private readonly ILegacyProjectUpdateCommand _legacyProjectUpdateCommand;
private readonly IProjectGetStatusesQuery _projectGetStatusesQuery;
private readonly ICreateInvoluntaryProjectCommand _createInvoluntaryProjectCommand;
private readonly ICreateSponsoredProjectCommand _createSponsoredProjectCommand;

public LegacyProjectController(ILegacyProjectGetQuery legacyProjectGetQuery,
ILegacyProjectListGetQuery legacyProjectListGetQuery,
IProjectGetStatusesQuery projectGetStatusesQuery,
ILegacyProjectUpdateCommand legacyProjectUpdateCommand,
ILegacyProjectAddNoteCommand legacyProjectAddNoteCommand,
ILegacyProjectDeleteNoteCommand legacyProjectDeleteNoteCommand,
ICreateInvoluntaryProjectCommand createInvoluntaryProjectCommand)
ICreateSponsoredProjectCommand createSponsoredProjectCommand)
{
_legacyProjectGetQuery = legacyProjectGetQuery;
_legacyProjectListGetQuery = legacyProjectListGetQuery;
_projectGetStatusesQuery = projectGetStatusesQuery;
_legacyProjectUpdateCommand = legacyProjectUpdateCommand;
_legacyProjectAddNoteCommand = legacyProjectAddNoteCommand;
_legacyProjectDeleteNoteCommand = legacyProjectDeleteNoteCommand;
_createInvoluntaryProjectCommand = createInvoluntaryProjectCommand;
_createSponsoredProjectCommand = createSponsoredProjectCommand;
}

/// <summary>
Expand Down Expand Up @@ -150,17 +150,17 @@ public async Task<ActionResult> AddNote(int id, AddNoteRequest note)
}

/// <summary>
/// Adds a involuntary conversion project
/// Adds a sponsored conversion project
/// </summary>
/// <param name="project">The model holding the data required to create an Involuntary conversion</param>
/// <param name="project">The model holding the data required to create a sponsored conversion</param>
/// <response code="201">The project has been added</response>
[HttpPost("project/involuntary-conversion-project")]
[HttpPost("project/sponsored-conversion-project")]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<ActionResult> AddInvoluntaryConversion(InvoluntaryProjectServiceModel project)
public async Task<ActionResult> AddSponsoredConversion(SponsoredProjectServiceModel project)
{
CommandResult result = await _createInvoluntaryProjectCommand.Execute(project);
CommandResult result = await _createSponsoredProjectCommand.Execute(project);

return result switch
{
Expand Down
Loading

0 comments on commit ef714d8

Please sign in to comment.