Skip to content

Commit

Permalink
Merge pull request #448 from DFE-Digital/feature/162020-preferred-trust
Browse files Browse the repository at this point in the history
Feature/162020 preferred trust
  • Loading branch information
elielijah321 authored Apr 16, 2024
2 parents 11b6499 + 5f2696a commit d187f5d
Show file tree
Hide file tree
Showing 20 changed files with 2,097 additions and 44 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Dfe.Academies.Academisation.Data.Migrations
{
/// <inheritdoc />
public partial class nullableIncomingTrustName : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "IncomingTrustName",
schema: "academisation",
table: "TransferringAcademy",
type: "nvarchar(max)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "IncomingTrustName",
schema: "academisation",
table: "TransferringAcademy",
type: "nvarchar(max)",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<string>("IncomingTrustName")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("IncomingTrustUkprn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TransferProjectTests
private readonly string _incomingTrustUkprn = "23456789";
private readonly string _incomingTrustName = "_incomingTrustName";
private readonly List<string> _academyUkprns = new() { "academy1", "academy2" };
private readonly bool _isFormAMat = true;
private readonly DateTime _createdOn = DateTime.Now;
public TransferProjectTests()
{
Expand All @@ -32,6 +33,7 @@ public void GenerateUrn_WithMultipleAcademies_GivesAMATBasedReference()
string incomingTrustUkprn = "11110000";
string incomingTrustName = "incomingTrustName";
List<string> academyUkprns = new List<string>() { "22221111", "33331111" };
bool isFormAMat = true;
DateTime createdOn = DateTime.Now;

// Act
Expand All @@ -41,6 +43,7 @@ public void GenerateUrn_WithMultipleAcademies_GivesAMATBasedReference()
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn);

// Act
Expand All @@ -59,6 +62,7 @@ public void GenerateUrn_WithOneAcademy_GivesASATBasedReference()
string incomingTrustUkprn = "11110000";
string incomingTrustName = "incomingTrustName";
List<string> academyUkprns = new List<string>() { "22221111" };
bool isFormAMat = true;
DateTime createdOn = DateTime.Now;

// Act
Expand All @@ -68,6 +72,7 @@ public void GenerateUrn_WithOneAcademy_GivesASATBasedReference()
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn);

// Act
Expand All @@ -86,6 +91,7 @@ public void CreateTransferProject_WithValidParameters_CreatesTransferProject()
string incomingTrustUkprn = "11110000";
string incomingTrustName = "incomingTrustName";
List<string> academyUkprns = new List<string>() { "22221111", "33331111" };
bool isFormAMat = false;
DateTime createdOn = DateTime.Now;

// Act
Expand All @@ -95,6 +101,7 @@ public void CreateTransferProject_WithValidParameters_CreatesTransferProject()
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn);

// Assert
Expand All @@ -114,6 +121,7 @@ public void CreateTransferProject_WithNullOutgoingTrustUkprn_ThrowsArgumentNullE
string incomingTrustUkprn = "11110000";
string incomingTrustName = "incomingTrustName";
List<string> academyUkprns = new List<string>() { "22221111", "33331111" };
bool isFormAMat = true;
DateTime createdOn = DateTime.Now;

// Act
Expand All @@ -123,6 +131,7 @@ public void CreateTransferProject_WithNullOutgoingTrustUkprn_ThrowsArgumentNullE
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn));
}

Expand Down Expand Up @@ -242,6 +251,7 @@ private static TransferProject CreateValidTransferProject()
string incomingTrustUkprn = "11110000";
string incomingTrustName = "incomingTrustName";
List<string> academyUkprns = new List<string>() { "22221111", "33331111" };
bool isFormAMat = true;
DateTime createdOn = DateTime.Now;

// Act
Expand All @@ -251,13 +261,14 @@ private static TransferProject CreateValidTransferProject()
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn);
return result;
}

[Theory]
[ClassData(typeof(CreationArgumentExceptionTestData))]
public void CreateTransferProject_WithTestData_ThrowsArgumentExceptions(string outgoingTrustUkprn, string outgoingTrustName, string incomingTrustUkprn, string incomingTrustName, List<string> academyUkprns, DateTime createdOn, Type exType)
public void CreateTransferProject_WithTestData_ThrowsArgumentExceptions(string outgoingTrustUkprn, string outgoingTrustName, string? incomingTrustUkprn, string? incomingTrustName, List<string> academyUkprns, bool? isFormAMat, DateTime createdOn, Type exType)
{
// Arrange
dynamic exception;
Expand All @@ -270,6 +281,7 @@ public void CreateTransferProject_WithTestData_ThrowsArgumentExceptions(string o
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn));
}

Expand All @@ -281,6 +293,7 @@ public void CreateTransferProject_WithTestData_ThrowsArgumentExceptions(string o
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn));
}

Expand All @@ -292,6 +305,7 @@ public void CreateTransferProject_WithTestData_ThrowsArgumentExceptions(string o
incomingTrustUkprn,
incomingTrustName,
academyUkprns,
isFormAMat,
createdOn));
}
}
Expand All @@ -302,7 +316,7 @@ public void CreateTransferProject_WithTestData_ThrowsArgumentExceptions(string o
public void SetFeatures_WithValidParameters_SetsPropertiesCorrectly(string whoInitiated, string specficReasons, string transferType, bool isCompleted)
{
// Arrange
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _createdOn);
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _isFormAMat, _createdOn);
var reasons = new List<string>() { specficReasons };
// Act
transferProject.SetFeatures(whoInitiated, reasons, transferType, isCompleted);
Expand All @@ -318,7 +332,7 @@ public void SetFeatures_WithValidParameters_SetsPropertiesCorrectly(string whoIn
public void SetLegalRequirements_WithValidParameters_SetsPropertiesCorrectly(string outgoingTrustResolution, string incomingTrustAgreement, string diocesanConsent, bool isCompleted)
{
// Arrange
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _createdOn);
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _isFormAMat, _createdOn);

// Act
transferProject.SetLegalRequirements(outgoingTrustResolution, incomingTrustAgreement, diocesanConsent, isCompleted);
Expand All @@ -333,7 +347,7 @@ public void SetLegalRequirements_WithValidParameters_SetsPropertiesCorrectly(str
public void SetTransferDates_WithValidParameters_SetsPropertiesCorrectly()
{
// Arrange
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _createdOn);
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _isFormAMat, _createdOn);
var advisoryBoardDate = DateTime.UtcNow;
var expectedDateForTransfer = DateTime.UtcNow.AddMonths(1);
// Act
Expand All @@ -350,7 +364,7 @@ public void SetTransferDates_WithValidParameters_SetsPropertiesCorrectly()
public void SetStatus_WithValidParameters_SetsPropertiesCorrectly(string status)
{
// Arrange
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _createdOn);
var transferProject = TransferProject.Create(_outgoingTrustUkprn, _outgoingTrusName, _incomingTrustUkprn, _incomingTrustName, _academyUkprns, _isFormAMat, _createdOn);

// Act
transferProject.SetStatus(status);
Expand All @@ -363,18 +377,15 @@ public class CreationArgumentExceptionTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { null, "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, DateTime.Now, typeof(ArgumentNullException) };
yield return new object[] { string.Empty, "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, DateTime.Now, typeof(ArgumentException) };
yield return new object[] { null, "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, false, DateTime.Now, typeof(ArgumentNullException) };
yield return new object[] { string.Empty, "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, false, DateTime.Now, typeof(ArgumentException) };

yield return new object[] { "11112222", "out trust", "11110000", null, new List<string>() { "22221111", "33331111" }, DateTime.Now, typeof(ArgumentNullException) };
yield return new object[] { "11112222", "out trust", "11110000", string.Empty, new List<string>() { "22221111", "33331111" }, DateTime.Now, typeof(ArgumentException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", null, false, DateTime.Now, typeof(ArgumentNullException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>(), false, DateTime.Now, typeof(ArgumentException) };

yield return new object[] { "11112222", "out trust", "11110000", "in trust", null, DateTime.Now, typeof(ArgumentNullException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>(), DateTime.Now, typeof(ArgumentException) };

yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, DateTime.MinValue, typeof(ArgumentOutOfRangeException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, DateTime.MaxValue, typeof(ArgumentOutOfRangeException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, null, typeof(ArgumentOutOfRangeException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, false, DateTime.MinValue, typeof(ArgumentOutOfRangeException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, false, DateTime.MaxValue, typeof(ArgumentOutOfRangeException) };
yield return new object[] { "11112222", "out trust", "11110000", "in trust", new List<string>() { "22221111", "33331111" }, false, null, typeof(ArgumentOutOfRangeException) };
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dfe.Academies.Academisation.Domain.TransferProjectAggregate
{
public class TransferProject : ITransferProject, IAggregateRoot
{
private TransferProject(string outgoingTrustUkprn, string outgoingTrustName, string? incomingTrustUkprn, string incomingTrustName, List<string> academyUkprns)
private TransferProject(string outgoingTrustUkprn, string outgoingTrustName, string? incomingTrustUkprn, string? incomingTrustName, List<string> academyUkprns, bool? isFormAMat)
{
_intendedTransferBenefits =
new List<IntendedTransferBenefit>();
Expand All @@ -19,7 +19,7 @@ private TransferProject(string outgoingTrustUkprn, string outgoingTrustName, str
OutgoingTrustUkprn = outgoingTrustUkprn;
OutgoingTrustName = outgoingTrustName;
//Is form a mat if we have a trust name but no ukprn
IsFormAMat = incomingTrustUkprn == null && !string.IsNullOrEmpty(incomingTrustName);
IsFormAMat = isFormAMat.HasValue && isFormAMat.Value;

foreach (var academyUkprn in academyUkprns)
{
Expand Down Expand Up @@ -196,15 +196,14 @@ public void SetStatus(string status)
Status = status;
}

public static TransferProject Create(string outgoingTrustUkprn, string outgoingTrustName, string? incomingTrustUkprn, string incomingTrustName, List<string> academyUkprns, DateTime createdOn)
public static TransferProject Create(string outgoingTrustUkprn, string outgoingTrustName, string? incomingTrustUkprn, string? incomingTrustName, List<string> academyUkprns, bool? isFormAMat, DateTime createdOn)
{
Guard.Against.NullOrEmpty(outgoingTrustUkprn);
Guard.Against.NullOrEmpty(outgoingTrustName);
Guard.Against.NullOrEmpty(incomingTrustName);
Guard.Against.NullOrEmpty(academyUkprns);
Guard.Against.OutOfSQLDateRange(createdOn);

return new TransferProject(outgoingTrustUkprn, outgoingTrustName, incomingTrustUkprn, incomingTrustName, academyUkprns)
return new TransferProject(outgoingTrustUkprn, outgoingTrustName, incomingTrustUkprn, incomingTrustName, academyUkprns, isFormAMat)
{
CreatedOn = createdOn
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Dfe.Academies.Academisation.Domain.TransferProjectAggregate
{
public class TransferringAcademy : ITransferringAcademy
{
public TransferringAcademy(string? incomingTrustUkprn, string incomingTrustName, string outgoingAcademyUkprn)
public TransferringAcademy(string? incomingTrustUkprn, string? incomingTrustName, string outgoingAcademyUkprn)
{
IncomingTrustUkprn = incomingTrustUkprn;
IncomingTrustName = incomingTrustName;
Expand All @@ -21,7 +21,7 @@ public TransferringAcademy(string? incomingTrustUkprn, string incomingTrustName,
public int TransferProjectId { get; private set; }
public string OutgoingAcademyUkprn { get; private set; }
public string? IncomingTrustUkprn { get; private set; }
public string IncomingTrustName { get; private set; }
public string? IncomingTrustName { get; private set; }

public string? PupilNumbersAdditionalInformation { get; private set; }
public string? LatestOfstedReportAdditionalInformation { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Handle_TransferProjectFound_ReturnsCommandSuccessResult()
UserFullName = "UserFullName"
};
// Create a transfer project to 'SetFeatures' to
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, DateTime.Now);
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, false, DateTime.Now);
// Mock Unit of work and Repository
var unitOfWorkMock = new Mock<IUnitOfWork>();
unitOfWorkMock.Setup(u => u.SaveChangesAsync(It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ private static CreateTransferProjectCommand CreateValidTransferProjectCommand()
string incomingTrustUkprn = "11110000";
string incomingTrusName = "incomingTrusName";
List<string> academyUkprns = new List<string>() { "22221111", "33331111" };
bool isFormAMat = true;

return new CreateTransferProjectCommand(outgoingTrustUkprn, outgoingTrustName, incomingTrustUkprn, incomingTrusName, academyUkprns);

return new CreateTransferProjectCommand(outgoingTrustUkprn, outgoingTrustName, incomingTrustUkprn, incomingTrusName, academyUkprns, isFormAMat);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task Handle_ValidCommand_PersistsExpectedTransferProject()
{
this._mockTransferProjectRepository.Setup(x => x.Update(It.IsAny<Domain.TransferProjectAggregate.TransferProject>()));

var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, DateTime.Now);
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, false, DateTime.Now);
// Mock GetById to use our Transfer Project from above
_mockTransferProjectRepository.Setup(x => x.GetByUrn(It.IsAny<int>())).ReturnsAsync(transferProject);

Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task Handle_ValidCommand_PersistsExpectedTransferProject()
public async Task Handle_ValidCommand_ReturnsCommandSuccessResponse()
{
this._mockTransferProjectRepository.Setup(x => x.Update(It.IsAny<Domain.TransferProjectAggregate.TransferProject>()));
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, DateTime.Now);
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, false, DateTime.Now);
// Mock GetById to use our Transfer Project from above
_mockTransferProjectRepository.Setup(x => x.GetByUrn(It.IsAny<int>())).ReturnsAsync(transferProject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Handle_TransferProjectFound_ReturnsCommandSuccessResult()
IsCompleted = true
};
// Create a transfer project to 'SetFeatures' to
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, DateTime.Now);
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, false, DateTime.Now);
// Mock Unit of work and Repository
var unitOfWorkMock = new Mock<IUnitOfWork>();
unitOfWorkMock.Setup(u => u.SaveChangesAsync(It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task Handle_TransferProjectFound_ReturnsCommandSuccessResult()
IsCompleted = true
};
// Create a transfer project to 'SetLegalRequirements' to
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, DateTime.Now);
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, false, DateTime.Now);
// Mock Unit of work and Repository
var unitOfWorkMock = new Mock<IUnitOfWork>();
unitOfWorkMock.Setup(u => u.SaveChangesAsync(It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task Handle_TransferProjectFound_ReturnsCommandSuccessResult()
};

// Create a transfer project to 'SetName' to
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, DateTime.Now);
var transferProject = Domain.TransferProjectAggregate.TransferProject.Create("12345678", "out trust", "23456789", "in trust", new List<string> { "34567890" }, false, DateTime.Now);
// Mock Unit of work and Repository
var unitOfWorkMock = new Mock<IUnitOfWork>();
unitOfWorkMock.Setup(u => u.SaveChangesAsync(It.IsAny<CancellationToken>()))
Expand Down
Loading

0 comments on commit d187f5d

Please sign in to comment.