From f93e92d5af767ea4d258dd14c5b5f37d0596a1d9 Mon Sep 17 00:00:00 2001 From: plockwood Date: Fri, 18 Oct 2024 11:35:51 +0100 Subject: [PATCH] Fixed unit tests --- .../Project/EnrichProjectCommandTests.cs | 7 +++++++ .../LegacyProjectServiceModelMapper.cs | 2 ++ .../EnrichProjectCommandTests.cs | 21 +++++++++++++++++-- .../ProjectAggregate/LegacyProjectGetTests.cs | 1 + .../LegacyProjectUpdateTests.cs | 1 + 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs index 2dc144242..115e0b793 100644 --- a/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs +++ b/Dfe.Academies.Academisation.Service.UnitTest/Commands/Legacy/Project/EnrichProjectCommandTests.cs @@ -5,6 +5,7 @@ using Dfe.Academies.Academisation.IService.Query; using Dfe.Academies.Academisation.Service.Commands.Legacy.Project; using Dfe.Academies.Contracts.V4.Establishments; +using Dfe.Academies.Contracts.V4.Trusts; using Microsoft.Extensions.Logging; using Moq; using Xunit; @@ -59,6 +60,9 @@ public async Task IncompleteProjects__UnknownSchool__LogAndContinue() .ReturnsAsync(_fixture.Create()) .ReturnsAsync(_fixture.Create()); + _establishmentGetDataQuery.Setup(m => m.GetTrustByReferenceNumber(It.IsAny())) + .ReturnsAsync(_fixture.Build().With(x => x.Ukprn, "101010").Create()); + await _subject.Execute(); Assert.Multiple( @@ -78,6 +82,9 @@ public async Task IncompleteProjects__KnownSchool__UpdateDb() _establishmentGetDataQuery.Setup(m => m.GetEstablishment(It.IsAny())) .ReturnsAsync(_fixture.Create()); + _establishmentGetDataQuery.Setup(m => m.GetTrustByReferenceNumber(It.IsAny())) + .ReturnsAsync(_fixture.Build().With(x => x.Ukprn, "101010").Create()); + await _subject.Execute(); _updateCommand.Verify(m => m.Execute(project), Times.Once); diff --git a/Dfe.Academies.Academisation.Service/Mappers/Legacy/ProjectAggregate/LegacyProjectServiceModelMapper.cs b/Dfe.Academies.Academisation.Service/Mappers/Legacy/ProjectAggregate/LegacyProjectServiceModelMapper.cs index e2e6ef216..6284fb510 100644 --- a/Dfe.Academies.Academisation.Service/Mappers/Legacy/ProjectAggregate/LegacyProjectServiceModelMapper.cs +++ b/Dfe.Academies.Academisation.Service/Mappers/Legacy/ProjectAggregate/LegacyProjectServiceModelMapper.cs @@ -151,6 +151,8 @@ internal static ConversionProjectServiceModel MapToServiceModel(this IProject pr ProjectDatesSectionComplete = project.Details.ProjectDatesSectionComplete, // if we have sent the project to complete then the project is readonly IsReadOnly = project.IsReadOnly, + TrustUkprn = project.Details.TrustUkprn + }; return serviceModel; diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs index 833f03a40..9f3d25e6c 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/EnrichProjectCommandTests.cs @@ -8,9 +8,11 @@ using Dfe.Academies.Academisation.Data.UnitTest.Contexts; using Dfe.Academies.Academisation.Domain.Core.ProjectAggregate; using Dfe.Academies.Academisation.Domain.ProjectAggregate; +using Dfe.Academies.Academisation.IService.ServiceModels.Academies; using Dfe.Academies.Academisation.Service.Commands.Legacy.Project; using Dfe.Academies.Academisation.Service.Queries; using Dfe.Academies.Contracts.V4.Establishments; +using Dfe.Academies.Contracts.V4.Trusts; using Dfe.Academisation.CorrelationIdMiddleware; using MediatR; using Microsoft.EntityFrameworkCore; @@ -30,6 +32,7 @@ public class EnrichProjectCommandTests private readonly EnrichProjectCommand _subject; private readonly EstablishmentDto _establishment; + private readonly TrustDto _trust; private readonly Fixture _fixture = new(); public EnrichProjectCommandTests() @@ -38,6 +41,7 @@ public EnrichProjectCommandTests() // mock establishment _establishment = _fixture.Create(); + _trust = _fixture.Build().With(x => x.Ukprn, "101101").Create(); _httpClientFactory = new Mock(); var httpClient = _mockHttpMessageHandler.ToHttpClient(); @@ -63,15 +67,23 @@ public EnrichProjectCommandTests() public async Task SomeProjectsAreIncomplete__ForKnownEstablishment__EnrichIncompleteProjectsWithMissingData() { // Arrange - var (project1, project2, project3) = (CreateProject(), CreateProject(), CreateProject("Bristol", "South West")); + var (project1, project2, project3) = (CreateProject(), CreateProject(), CreateProject("Bristol", "South West", 101101)); _context.Projects.AddRange(project1, project2, project3); await _context.SaveChangesAsync(); _mockHttpMessageHandler.When($"http://localhost/v4/establishment/urn/{project1.Details.Urn}") .Respond("application/json", JsonConvert.SerializeObject(_establishment)); + _mockHttpMessageHandler.When($"http://localhost/v4/establishment/urn/{project2.Details.Urn}") .Respond("application/json", JsonConvert.SerializeObject(_establishment)); + + _mockHttpMessageHandler.When($"http://localhost/v4/trust/trustReferenceNumber/{project1.Details.TrustReferenceNumber}") + .Respond("application/json", JsonConvert.SerializeObject(_trust)); + + _mockHttpMessageHandler.When($"http://localhost/v4/trust/trustReferenceNumber/{project2.Details.TrustReferenceNumber}") + .Respond("application/json", JsonConvert.SerializeObject(_trust)); + var httpClient = _mockHttpMessageHandler.ToHttpClient(); httpClient.BaseAddress = new Uri("http://localhost"); _httpClientFactory.Setup(m => m.CreateClient("AcademiesApi")).Returns(httpClient); @@ -103,6 +115,10 @@ public async Task SomeProjectsAreIncomplete__ForUnknownEstablishment__ProjectsRe await _context.SaveChangesAsync(); _mockHttpMessageHandler.When($"http://localhost/v4/establishment/urn/*").Respond(HttpStatusCode.NotFound); + + _mockHttpMessageHandler.When($"http://localhost/v4/trust/trustReferenceNumber/*").Respond(HttpStatusCode.NotFound); + + var httpClient = _mockHttpMessageHandler.ToHttpClient(); httpClient.BaseAddress = new Uri("http://localhost"); _httpClientFactory.Setup(m => m.CreateClient("AcademiesApi")).Returns(httpClient); @@ -122,7 +138,7 @@ public async Task SomeProjectsAreIncomplete__ForUnknownEstablishment__ProjectsRe ); } - private Project CreateProject(string? la = null, string? region = null) + private Project CreateProject(string? la = null, string? region = null, int? trustUkprn = null) { var project = _fixture.Create(); @@ -130,6 +146,7 @@ private Project CreateProject(string? la = null, string? region = null) .With(p => p.LocalAuthority, la) .With(p => p.Urn, project.Details.Urn) .With(p => p.Region, region) + .With(p => p.TrustUkprn, trustUkprn) .Create(); project.Update(projectDetails); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs index f052f5f05..93c4d92e5 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectGetTests.cs @@ -50,6 +50,7 @@ public async Task ProjectExists___ProjectReturned() .Excluding(x => x.IsFormAMat) .Excluding(x => x.ApplicationSharePointId) .Excluding(x => x.SchoolSharePointId) + .Excluding(x => x.IsReadOnly) ); existingProject.Id.Should().Be(serviceModel.Id); diff --git a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs index b3dd1a963..dea4c0c24 100644 --- a/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs +++ b/Dfe.Academies.Academisation.SubcutaneousTest/ProjectAggregate/LegacyProjectUpdateTests.cs @@ -77,6 +77,7 @@ public async Task ProjectExists___FullProjectIsUpdated() .With(p => p.Id, existingProject.Id) .With(p => p.Urn, existingProject.Details.Urn) .With(p => p.ExternalApplicationFormSaved, existingProject.Details.ExternalApplicationFormSaved) + .With(p => p.IsReadOnly, existingProject.IsReadOnly) // excluded from update so need to be set for equality to assert .With(x => x.KeyStage2PerformanceAdditionalInformation, existingProject.Details.KeyStage2PerformanceAdditionalInformation) .With(x => x.KeyStage4PerformanceAdditionalInformation, existingProject.Details.KeyStage4PerformanceAdditionalInformation)