diff --git a/SAPPub.Core/Entities/Establishment.cs b/SAPPub.Core/Entities/Establishment.cs index 41738478c..cf412fb89 100644 --- a/SAPPub.Core/Entities/Establishment.cs +++ b/SAPPub.Core/Entities/Establishment.cs @@ -88,7 +88,6 @@ public class Establishment public string UrbanRuralId { get; set; } = string.Empty; public string UrbanRuralName { get; set; } = string.Empty; - public string Website { get; set; } = string.Empty; public string Easting { get; set; } = string.Empty; diff --git a/SAPPub.Core/Entities/EstablishmentMinimum.cs b/SAPPub.Core/Entities/EstablishmentMinimum.cs new file mode 100644 index 000000000..9bab24599 --- /dev/null +++ b/SAPPub.Core/Entities/EstablishmentMinimum.cs @@ -0,0 +1,47 @@ +using SAPPub.Core.Attributes; +using SAPPub.Core.Enums; +using SAPPub.Core.ServiceModels; +using System.Diagnostics.CodeAnalysis; +using System.Net.WebSockets; +using System.Runtime.Serialization; + +namespace SAPPub.Core.Entities; + +[ExcludeFromCodeCoverage] +public class EstablishmentMinimum +{ + public string URN { get; set; } = string.Empty; + + public string EstablishmentName { get; set; } = string.Empty; + + public string LAId { get; set; } = string.Empty; + + public string LAName { get; set; } = string.Empty; + + [DbColumnName("ISKS2")] + public bool IsKS2 { get; set; } + + [DbColumnName("ISKS4")] + public bool IsKS4 { get; set; } + + [DbColumnName("ISKS5")] + public bool IsKS5 { get; set; } + + public string Website { get; set; } = string.Empty; + + + public static EstablishmentMinimumServiceModel MapToServiceModel(Establishment e) + { + return new() + { + URN = e.URN, + EstablishmentName = e.EstablishmentName, + LAId = e.LAId, + LAName = e.LAName, + IsKS2 = e.IsKS2, + IsKS4 = e.IsKS4, + IsKS5 = e.IsKS5, + Website = e.Website, + }; + } +} diff --git a/SAPPub.Core/Interfaces/Services/IEstablishmentService.cs b/SAPPub.Core/Interfaces/Services/IEstablishmentService.cs index 2b1a614d9..e4f34b88a 100644 --- a/SAPPub.Core/Interfaces/Services/IEstablishmentService.cs +++ b/SAPPub.Core/Interfaces/Services/IEstablishmentService.cs @@ -10,4 +10,6 @@ public interface IEstablishmentService Task GetEstablishmentAsync(string urn, CancellationToken ct = default); Task> GetEstablishmentsAsync(IEnumerable urns, CancellationToken ct = default); + Task GetEstablishmentMinimumAsync(string urn, CancellationToken ct = default); + } diff --git a/SAPPub.Core/ServiceModels/EstablishmentMinimumServiceModel.cs b/SAPPub.Core/ServiceModels/EstablishmentMinimumServiceModel.cs new file mode 100644 index 000000000..3e3abb624 --- /dev/null +++ b/SAPPub.Core/ServiceModels/EstablishmentMinimumServiceModel.cs @@ -0,0 +1,28 @@ +using SAPPub.Core.Entities.Destinations; +using SAPPub.Core.Entities.KS4.Absence; +using SAPPub.Core.Entities.KS4.Performance; +using SAPPub.Core.Enums; +using SAPPub.Core.Helpers; + +namespace SAPPub.Core.ServiceModels; + +public class EstablishmentMinimumServiceModel +{ + public string URN { get; set; } = string.Empty; + + public string EstablishmentName { get; set; } = string.Empty; + + public string EstablishmentNameClean => TextHelpers.CleanForUrl(EstablishmentName); + + public string LAId { get; set; } = string.Empty; + + public string LAName { get; set; } = string.Empty; + + public bool IsKS2 { get; set; } + + public bool IsKS4 { get; set; } + + public bool IsKS5 { get; set; } + + public string Website { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/SAPPub.Core/Services/DestinationsService.cs b/SAPPub.Core/Services/DestinationsService.cs index 216921367..1382e9f9b 100644 --- a/SAPPub.Core/Services/DestinationsService.cs +++ b/SAPPub.Core/Services/DestinationsService.cs @@ -13,7 +13,7 @@ public class DestinationsService( { public async Task GetKS4DestinationsDetailsAsync(string urn, CancellationToken ct = default) { - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var laCode = establishment?.LAId ?? string.Empty; if (string.IsNullOrWhiteSpace(establishment?.URN)) @@ -109,7 +109,7 @@ public async Task GetKS5DestinationsDetailsAsync(string { ct.ThrowIfCancellationRequested(); - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var laCode = establishment.LAId ?? string.Empty; if (string.IsNullOrWhiteSpace(establishment.URN)) diff --git a/SAPPub.Core/Services/EstablishmentService.cs b/SAPPub.Core/Services/EstablishmentService.cs index 1a5b94a5a..199f63388 100644 --- a/SAPPub.Core/Services/EstablishmentService.cs +++ b/SAPPub.Core/Services/EstablishmentService.cs @@ -1,4 +1,5 @@ -using SAPPub.Core.Entities; +using Microsoft.Extensions.Caching.Memory; +using SAPPub.Core.Entities; using SAPPub.Core.Exceptions; using SAPPub.Core.Interfaces.Repositories; using SAPPub.Core.Interfaces.Services; @@ -7,9 +8,12 @@ namespace SAPPub.Core.Services; public sealed class EstablishmentService( - IEstablishmentRepository establishmentRepository) : IEstablishmentService + IEstablishmentRepository establishmentRepository, + IMemoryCache memoryCache + ) : IEstablishmentService { private readonly IEstablishmentRepository _establishmentRepository = establishmentRepository ?? throw new ArgumentNullException(nameof(establishmentRepository)); + private readonly IMemoryCache _memoryCache = memoryCache ?? throw new ArgumentNullException(nameof(establishmentRepository)); public async Task> GetEstablishmentsAsync(int page, int take, CancellationToken ct = default) { @@ -36,4 +40,23 @@ public async Task> GetEstablishmentsAsync return establishments.Select(e => Establishment.MapToServiceModel(e)); } + + public async Task GetEstablishmentMinimumAsync(string urn, CancellationToken ct = default) + { + if (_memoryCache.TryGetValue(urn, out EstablishmentMinimumServiceModel? cacheValue) && cacheValue != null) + { + return cacheValue; + } + + var establishment = await _establishmentRepository.GetEstablishmentAsync(urn, ct) + ?? throw new NotFoundException($"Establishment not found with URN: {urn}"); + + var cacheEntryOptions = new MemoryCacheEntryOptions(); + + var establishmentModel = EstablishmentMinimum.MapToServiceModel(establishment); + + _memoryCache.Set(urn, establishmentModel, cacheEntryOptions); + + return establishmentModel; + } } \ No newline at end of file diff --git a/SAPPub.Core/Services/KS4/Attendance/AttendanceService.cs b/SAPPub.Core/Services/KS4/Attendance/AttendanceService.cs index 76f364be2..641b8e273 100644 --- a/SAPPub.Core/Services/KS4/Attendance/AttendanceService.cs +++ b/SAPPub.Core/Services/KS4/Attendance/AttendanceService.cs @@ -15,7 +15,7 @@ public async Task GetAttendenceDetailsAsync( string urn, CancellationToken ct = default) { - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); if (string.IsNullOrWhiteSpace(establishment.URN)) return new AttendanceModel { Urn = urn, IsKS2 = false, IsKS4 = false, IsKS5 = false }; diff --git a/SAPPub.Core/Services/KS4/Performance/AttainmentAndProgressService.cs b/SAPPub.Core/Services/KS4/Performance/AttainmentAndProgressService.cs index 3f33a7c25..9fd520412 100644 --- a/SAPPub.Core/Services/KS4/Performance/AttainmentAndProgressService.cs +++ b/SAPPub.Core/Services/KS4/Performance/AttainmentAndProgressService.cs @@ -17,7 +17,7 @@ public async Task GetAttainmentAndProgressAsync( CancellationToken ct = default) { // Need establishment first to get LAId/LAName (and to check if URN is valid) - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); if (string.IsNullOrWhiteSpace(establishment.URN)) return new AttainmentAndProgressModel { Urn = urn, IsKS2 = false, IsKS4 = false, IsKS5 = false }; diff --git a/SAPPub.Core/Services/KS4/Performance/EnglishAndMathsResultsService.cs b/SAPPub.Core/Services/KS4/Performance/EnglishAndMathsResultsService.cs index b453198e3..a38e6c019 100644 --- a/SAPPub.Core/Services/KS4/Performance/EnglishAndMathsResultsService.cs +++ b/SAPPub.Core/Services/KS4/Performance/EnglishAndMathsResultsService.cs @@ -24,7 +24,7 @@ public async Task GetEnglishAndMathsResultsAsync( CancellationToken ct = default) { // Need establishment first to get LAId/LAName (and to check if URN is valid) - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); if (string.IsNullOrWhiteSpace(establishment.URN)) return CreateEmpty(urn); diff --git a/SAPPub.Core/Services/Performance/EnglishAndMathsQualificationsService.cs b/SAPPub.Core/Services/Performance/EnglishAndMathsQualificationsService.cs index f8bbd161c..acb80a6c4 100644 --- a/SAPPub.Core/Services/Performance/EnglishAndMathsQualificationsService.cs +++ b/SAPPub.Core/Services/Performance/EnglishAndMathsQualificationsService.cs @@ -15,7 +15,7 @@ public async Task GetEnglishAndMathsQualificatio { ct.ThrowIfCancellationRequested(); - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var establishmentPerformanceTask = ks5PerformanceRepository.GetEstablishmentPerformanceAsync(urn, ct); var englandPerformanceTask = ks5PerformanceRepository.GetEnglandPerformanceAsync(ct); diff --git a/SAPPub.Core/Services/Performance/KS2AdditionalMeasuresService.cs b/SAPPub.Core/Services/Performance/KS2AdditionalMeasuresService.cs index 28a88aa6d..99d0ea75d 100644 --- a/SAPPub.Core/Services/Performance/KS2AdditionalMeasuresService.cs +++ b/SAPPub.Core/Services/Performance/KS2AdditionalMeasuresService.cs @@ -15,7 +15,7 @@ public async Task GetAdditionalMeasures(string urn, ArgumentException.ThrowIfNullOrWhiteSpace(urn); ct.ThrowIfCancellationRequested(); - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var establishmentPerformanceTask = ks2PerformanceRepository.GetEstablishmentPerformanceAsync(urn, ct); var localAuthorityPerformanceTask = ks2PerformanceRepository.GetLaPerformanceAsync(establishment.LAId, ct); var englandPerformanceTask = ks2PerformanceRepository.GetEnglandPerformanceAsync(ct); diff --git a/SAPPub.Core/Services/Performance/KS2MeetingOrExceedingStandardsService.cs b/SAPPub.Core/Services/Performance/KS2MeetingOrExceedingStandardsService.cs index 4ed65bc1e..96ec6b341 100644 --- a/SAPPub.Core/Services/Performance/KS2MeetingOrExceedingStandardsService.cs +++ b/SAPPub.Core/Services/Performance/KS2MeetingOrExceedingStandardsService.cs @@ -17,7 +17,7 @@ public async Task GetMeetingOrExceedingStan ArgumentException.ThrowIfNullOrWhiteSpace(urn); ct.ThrowIfCancellationRequested(); - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var establishmentPerformanceTask = ks2PerformanceRepository.GetEstablishmentPerformanceAsync(urn, ct); var localAuthorityPerformanceTask = ks2PerformanceRepository.GetLaPerformanceAsync(establishment.LAId, ct); var englandPerformanceTask = ks2PerformanceRepository.GetEnglandPerformanceAsync(ct); diff --git a/SAPPub.Core/Services/Performance/KS2ScaledScoresService.cs b/SAPPub.Core/Services/Performance/KS2ScaledScoresService.cs index ce2deff83..9f94040a5 100644 --- a/SAPPub.Core/Services/Performance/KS2ScaledScoresService.cs +++ b/SAPPub.Core/Services/Performance/KS2ScaledScoresService.cs @@ -18,7 +18,7 @@ public async Task GetScaledScoreModel(string urn, Cancellat ArgumentException.ThrowIfNullOrWhiteSpace(urn); ct.ThrowIfCancellationRequested(); - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var establishmentPerformanceTask = ks2PerformanceRepository.GetEstablishmentPerformanceAsync(urn, ct); var localAuthorityPerformanceTask = ks2PerformanceRepository.GetLaPerformanceAsync(establishment.LAId, ct); var englandPerformanceTask = ks2PerformanceRepository.GetEnglandPerformanceAsync(ct); diff --git a/SAPPub.Core/Services/Performance/Level3QualificationsService.cs b/SAPPub.Core/Services/Performance/Level3QualificationsService.cs index 794025f75..c404036be 100644 --- a/SAPPub.Core/Services/Performance/Level3QualificationsService.cs +++ b/SAPPub.Core/Services/Performance/Level3QualificationsService.cs @@ -18,7 +18,7 @@ public async Task GetLevel3QualificationDetailsAsync( Level3 level3Qualification, CancellationToken ct = default) { - var establishment = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var establishmentPerformanceTask = ks5PerformanceRepository.GetEstablishmentPerformanceAsync(urn, ct); var englandPerformanceTask = ks5PerformanceRepository.GetEnglandPerformanceAsync(ct); var laPerformanceTask = ks5PerformanceRepository.GetLaPerformanceAsync(establishment.LAId, ct); diff --git a/SAPPub.Infrastructure/Repositories/EstablishmentRepository.cs b/SAPPub.Infrastructure/Repositories/EstablishmentRepository.cs index 8c29c14b8..5b73c7389 100644 --- a/SAPPub.Infrastructure/Repositories/EstablishmentRepository.cs +++ b/SAPPub.Infrastructure/Repositories/EstablishmentRepository.cs @@ -1,4 +1,5 @@ using Dapper; +using Microsoft.FeatureManagement; using Npgsql; using SAPPub.Core.Entities; using SAPPub.Core.Helpers; @@ -7,6 +8,8 @@ using SAPPub.Core.Interfaces.Services.Search; using SAPPub.Core.ServiceModels.Search.InputModels; using SAPPub.Core.Specifications; +using StackExchange.Profiling; +using StackExchange.Profiling.Data; namespace SAPPub.Infrastructure.Repositories { @@ -106,6 +109,7 @@ internal static SearchSqlParts BuildSearchSqlParts(SearchQuery query, int maxRes public async Task<(IEnumerable Results, int TotalCount)> SearchAsync(SearchQuery query, int maxResults = 10, CancellationToken ct = default) { + var visibilitySpec = await _searchVisibilityPolicy.GetVisibilitySpecificationAsync(ct); var parts = BuildSearchSqlParts(query, maxResults, visibilitySpec); @@ -121,7 +125,8 @@ SELECT COUNT(*) FROM v_establishment {parts.WhereClause};"; - await using var conn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + await using var npgsqlConn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + using var conn = new ProfiledDbConnection(npgsqlConn, MiniProfiler.Current); var results = await conn.QueryAsync(sql, parts.Parameters); var totalCount = await conn.ExecuteScalarAsync(countSql, parts.Parameters); diff --git a/SAPPub.Infrastructure/Repositories/Generic/DapperRepository.cs b/SAPPub.Infrastructure/Repositories/Generic/DapperRepository.cs index 22e0b0c47..b2b4ad651 100644 --- a/SAPPub.Infrastructure/Repositories/Generic/DapperRepository.cs +++ b/SAPPub.Infrastructure/Repositories/Generic/DapperRepository.cs @@ -4,6 +4,8 @@ using SAPPub.Core.Interfaces.Repositories.Generic; using SAPPub.Infrastructure.Mapping.ValueCodes; using SAPPub.Infrastructure.Repositories.Helpers; +using StackExchange.Profiling; +using StackExchange.Profiling.Data; namespace SAPPub.Infrastructure.Repositories.Generic { @@ -46,7 +48,9 @@ public async Task> ReadPageAsync(int page, int take, Cancellation if (string.IsNullOrWhiteSpace(sql)) throw new NotSupportedException($"No ReadMultiple query for {typeof(T).Name}"); - await using var conn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + + await using var npgsqlConn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + using var conn = new ProfiledDbConnection(npgsqlConn, MiniProfiler.Current); var cmd = new DapperCommandBuilder() .WithCommandText(sql) @@ -68,7 +72,8 @@ public async Task> ReadAllAsync(CancellationToken ct = default) if (string.IsNullOrWhiteSpace(sql)) throw new NotSupportedException($"No ReadMultiple query for {typeof(T).Name}"); - await using var conn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + await using var npgsqlConn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + using var conn = new ProfiledDbConnection(npgsqlConn, MiniProfiler.Current); var cmd = new DapperCommandBuilder() .WithCommandText(sql) @@ -104,7 +109,8 @@ public async Task> ReadAllAsync(CancellationToken ct = default) if (string.IsNullOrWhiteSpace(sql)) throw new NotSupportedException($"No ReadSingle query for {typeof(T).Name}"); - await using var conn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + await using var npgsqlConn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + using var conn = new ProfiledDbConnection(npgsqlConn, MiniProfiler.Current); var cmd = new DapperCommandBuilder() .WithCommandText(sql) @@ -211,7 +217,8 @@ public async Task> ReadManyAsync(object? parameters, Cancellation if (string.IsNullOrWhiteSpace(sql)) throw new NotSupportedException($"No ReadMany query for {typeof(T).Name}"); - await using var conn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + await using var npgsqlConn = await _dataSource.OpenConnectionAsync(ct).ConfigureAwait(false); + using var conn = new ProfiledDbConnection(npgsqlConn, MiniProfiler.Current); var cmd = new DapperCommandBuilder() .WithCommandText(sql) diff --git a/SAPPub.Infrastructure/SAPPub.Infrastructure.csproj b/SAPPub.Infrastructure/SAPPub.Infrastructure.csproj index 13bd0dbe2..b98b01183 100644 --- a/SAPPub.Infrastructure/SAPPub.Infrastructure.csproj +++ b/SAPPub.Infrastructure/SAPPub.Infrastructure.csproj @@ -12,6 +12,7 @@ + diff --git a/SAPPub.Web/Areas/Profiles/Controllers/CurriculumController.cs b/SAPPub.Web/Areas/Profiles/Controllers/CurriculumController.cs index 0a98b02c4..a3c896b21 100644 --- a/SAPPub.Web/Areas/Profiles/Controllers/CurriculumController.cs +++ b/SAPPub.Web/Areas/Profiles/Controllers/CurriculumController.cs @@ -12,13 +12,13 @@ namespace SAPPub.Web.Areas.Profiles.Controllers; public class CurriculumController(ILogger logger, IFeatureManager featureManager) : Controller { [Route("school/{urn}/{schoolName}/curriculum", Name = RouteConstants.CurriculumRoot)] - public async Task Index([FromServices] IAboutSchoolService aboutSchoolService, + public async Task Index([FromServices] IEstablishmentService establishmentService, string urn, string schoolName, CancellationToken ct) { - var schoolDetails = await aboutSchoolService.GetAboutSchoolDetailsAsync(urn, ct); + var schoolDetails = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); - if (string.IsNullOrWhiteSpace(schoolDetails.Urn)) + if (string.IsNullOrWhiteSpace(schoolDetails.URN)) { logger.LogWarning("No establishment details found for URN: {URN}", urn); return View("Error"); @@ -43,7 +43,7 @@ public async Task KS2( [FromServices] IEstablishmentService establishmentService, string urn, string schoolName, CancellationToken ct) { - var establishmentDetails = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishmentDetails = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var model = ViewModels.KS2.CurriculumAndExtraCurricularActivitiesViewModel.Map(establishmentDetails); return View(model); } @@ -54,7 +54,7 @@ public async Task KS4( [FromServices] IEstablishmentService establishmentService, string urn, string schoolName, CancellationToken ct) { - var establishmentDetails = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishmentDetails = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var model = ViewModels.KS4.CurriculumAndExtraCurricularActivitiesViewModel.Map(establishmentDetails); return View(model); } diff --git a/SAPPub.Web/Areas/Profiles/Controllers/KS2Controller.cs b/SAPPub.Web/Areas/Profiles/Controllers/KS2Controller.cs index 6390f9d5b..f95fe1f91 100644 --- a/SAPPub.Web/Areas/Profiles/Controllers/KS2Controller.cs +++ b/SAPPub.Web/Areas/Profiles/Controllers/KS2Controller.cs @@ -17,7 +17,7 @@ namespace SAPPub.Web.Areas.Profiles.Controllers; [ServiceFilter(typeof(PrimaryQueryValidationFilter))] public class KS2Controller(IOptions urlLinksOptions) : Controller, IEstablishment { - public EstablishmentServiceModel Establishment { get; set; } = null!; // set by the PrimaryQueryValidationFilter + public EstablishmentMinimumServiceModel Establishment { get; set; } = null!; // set by the PrimaryQueryValidationFilter [HttpGet] [Route("school/{urn}/{schoolName}/primary-performance/pupil-progress", Name = RouteConstants.PrimaryAcademicPerformancePupilProgress)] diff --git a/SAPPub.Web/Areas/Profiles/Controllers/KS4Controller.cs b/SAPPub.Web/Areas/Profiles/Controllers/KS4Controller.cs index 650f38371..9fda09334 100644 --- a/SAPPub.Web/Areas/Profiles/Controllers/KS4Controller.cs +++ b/SAPPub.Web/Areas/Profiles/Controllers/KS4Controller.cs @@ -89,7 +89,7 @@ public async Task AcademicPerformanceSubjectsEntered( string schoolName, CancellationToken ct) { - var establishmentDetails = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishmentDetails = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); if (string.IsNullOrWhiteSpace(establishmentDetails?.URN)) { @@ -114,7 +114,7 @@ public async Task AcademicPerformanceAdditionalMeasures( [FromServices] IAdditionalMeasuresService additionalMeasuresService, string urn, string schoolName, CancellationToken ct) { - var establishmentDetails = await establishmentService.GetEstablishmentAsync(urn, ct); + var establishmentDetails = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); var additionalMeasures = await additionalMeasuresService.GetAsync(urn, establishmentDetails.LAId, ct); var model = AcademicPerformanceAdditionalMeasuresViewModel.MapToMeasuresInTableFormat(additionalMeasures, establishmentDetails); diff --git a/SAPPub.Web/Areas/Profiles/Controllers/KS5Controller.cs b/SAPPub.Web/Areas/Profiles/Controllers/KS5Controller.cs index e72b76d86..66f7c86ad 100644 --- a/SAPPub.Web/Areas/Profiles/Controllers/KS5Controller.cs +++ b/SAPPub.Web/Areas/Profiles/Controllers/KS5Controller.cs @@ -2,9 +2,11 @@ using Microsoft.FeatureManagement.Mvc; using SAPPub.Core.Enums; using SAPPub.Core.Enums.KS5Qualifications; +using SAPPub.Core.Interfaces.Services; using SAPPub.Core.Interfaces.Services.KS4.AboutSchool; using SAPPub.Core.Interfaces.Services.Performance; using SAPPub.Core.Services.Performance; +using SAPPub.Core.Services; using SAPPub.Web.Areas.Profiles.ViewModels.KS5; using SAPPub.Web.Constants; @@ -117,7 +119,7 @@ public IActionResult SubjectsEnteredRedirect( [Route("school/{urn}/{schoolName}/16-to-19-performance/subjects-entered/{qualification}", Name = RouteConstants.KS5AcademicPerformanceSubjectsEnteredFilter)] public async Task SubjectsEntered( - [FromServices] IAboutSchoolService aboutSchoolService, + [FromServices] IEstablishmentService establishmentService, [FromServices] IKS5EstablishmentSubjectEntriesService establishmentSubjectEntriesService, QualificationType? qualification, string urn, @@ -128,10 +130,10 @@ public async Task SubjectsEntered( { return View("Error"); } + + var schoolDetails = await establishmentService.GetEstablishmentMinimumAsync(urn, ct); - var schoolDetails = await aboutSchoolService.GetAboutSchoolDetailsAsync(urn, ct); - - if (string.IsNullOrWhiteSpace(schoolDetails.Urn)) + if (string.IsNullOrWhiteSpace(schoolDetails.URN)) { logger.LogWarning("No establishment details found for URN: {URN}", urn); return View("Error"); diff --git a/SAPPub.Web/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilter.cs b/SAPPub.Web/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilter.cs index 17cf3c382..c888a3e93 100644 --- a/SAPPub.Web/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilter.cs +++ b/SAPPub.Web/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilter.cs @@ -21,7 +21,7 @@ public class DfEAnalyticsAddPhaseTagFilter(IEstablishmentService establishmentSe public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { - EstablishmentServiceModel? establishment = null; + EstablishmentMinimumServiceModel? establishment = null; if (context.Controller is IEstablishment controller) { @@ -35,7 +35,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE return; } - establishment = await establishmentService.GetEstablishmentAsync(urn); + establishment = await establishmentService.GetEstablishmentMinimumAsync(urn); } var webRequestEvent = context.HttpContext.GetWebRequestEvent(); diff --git a/SAPPub.Web/Areas/Profiles/Filters/IEstablishment.cs b/SAPPub.Web/Areas/Profiles/Filters/IEstablishment.cs index 1fa579e2c..32d562f19 100644 --- a/SAPPub.Web/Areas/Profiles/Filters/IEstablishment.cs +++ b/SAPPub.Web/Areas/Profiles/Filters/IEstablishment.cs @@ -4,5 +4,5 @@ namespace SAPPub.Web.Areas.Profiles.Filters; public interface IEstablishment { - public EstablishmentServiceModel Establishment { get; set; } + public EstablishmentMinimumServiceModel Establishment { get; set; } } diff --git a/SAPPub.Web/Areas/Profiles/Filters/PrimaryQueryValidationFilter.cs b/SAPPub.Web/Areas/Profiles/Filters/PrimaryQueryValidationFilter.cs index e0511e3df..076157788 100644 --- a/SAPPub.Web/Areas/Profiles/Filters/PrimaryQueryValidationFilter.cs +++ b/SAPPub.Web/Areas/Profiles/Filters/PrimaryQueryValidationFilter.cs @@ -18,7 +18,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE return; } - var establishment = await establishmentService.GetEstablishmentAsync(urn); + var establishment = await establishmentService.GetEstablishmentMinimumAsync(urn); if (!establishment.IsKS2) { diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceAdditionalMeasuresViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceAdditionalMeasuresViewModel.cs index 29f5c9183..5a95e7b74 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceAdditionalMeasuresViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceAdditionalMeasuresViewModel.cs @@ -21,7 +21,7 @@ public class AcademicPerformanceAdditionalMeasuresViewModel : BaseViewModel public required string LAName { get; set; } - public static AcademicPerformanceAdditionalMeasuresViewModel Map(EstablishmentServiceModel establishment, KS2AdditionalMeasuresModel kS2AdditionalMeasuresModel) + public static AcademicPerformanceAdditionalMeasuresViewModel Map(EstablishmentMinimumServiceModel establishment, KS2AdditionalMeasuresModel kS2AdditionalMeasuresModel) { return new AcademicPerformanceAdditionalMeasuresViewModel { diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceMeetingOrExceedingStandardsViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceMeetingOrExceedingStandardsViewModel.cs index e7584e603..7859e0b38 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceMeetingOrExceedingStandardsViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceMeetingOrExceedingStandardsViewModel.cs @@ -17,7 +17,7 @@ public class AcademicPerformanceMeetingOrExceedingStandardsViewModel : BaseViewM public required DataOverTimeViewModel AllExceedingStandardsOverTimeData { get; set; } public static AcademicPerformanceMeetingOrExceedingStandardsViewModel Map( - EstablishmentServiceModel establishment, + EstablishmentMinimumServiceModel establishment, KS2MeetingOrExceedingStandardsModel kS2MeetingOrExceedingStandardsModel) { var laAverageLabel = CommonHelper.GetLocalAuthorityDisplayName(establishment.LAName); diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformancePupilProgressViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformancePupilProgressViewModel.cs index 318c8049d..7cf331c22 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformancePupilProgressViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformancePupilProgressViewModel.cs @@ -36,7 +36,7 @@ public class AcademicPerformancePupilProgressViewModel : BaseViewModel public static AcademicPerformancePupilProgressViewModel Map( KS2PupilPerformance ks2PupilPerformance, - EstablishmentServiceModel establishment, + EstablishmentMinimumServiceModel establishment, AcademicYearSelection selectedAcademicYear, UrlLinksOptions urlLinksOptions) { diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceSubjectScaledScoresViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceSubjectScaledScoresViewModel.cs index 7f761ffee..c5a5e0298 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceSubjectScaledScoresViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/AcademicPerformanceSubjectScaledScoresViewModel.cs @@ -21,7 +21,7 @@ public class AcademicPerformanceSubjectScaledScoresViewModel : BaseViewModel public required DisplayField HasMathsEstablishmentData { get; set; } - public static AcademicPerformanceSubjectScaledScoresViewModel Map(EstablishmentServiceModel establishment, KS2ScaledScoreModel scaledScoreModel) + public static AcademicPerformanceSubjectScaledScoresViewModel Map(EstablishmentMinimumServiceModel establishment, KS2ScaledScoreModel scaledScoreModel) { var laAverageLabel = CommonHelper.GetLocalAuthorityDisplayName(establishment.LAName); diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/CurriculumAndExtraCurricularActivitiesViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/CurriculumAndExtraCurricularActivitiesViewModel.cs index 2e0d12337..4e879c7ad 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS2/CurriculumAndExtraCurricularActivitiesViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS2/CurriculumAndExtraCurricularActivitiesViewModel.cs @@ -8,7 +8,7 @@ public class CurriculumAndExtraCurricularActivitiesViewModel : BaseViewModel { public required DisplayField SchoolWebsite { get; set; } - public static CurriculumAndExtraCurricularActivitiesViewModel Map(EstablishmentServiceModel establishment) + public static CurriculumAndExtraCurricularActivitiesViewModel Map(EstablishmentMinimumServiceModel establishment) { return new CurriculumAndExtraCurricularActivitiesViewModel { diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceAdditionalMeasuresViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceAdditionalMeasuresViewModel.cs index 006542e7b..6ec01af12 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceAdditionalMeasuresViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceAdditionalMeasuresViewModel.cs @@ -8,7 +8,7 @@ public class AcademicPerformanceAdditionalMeasuresViewModel : BaseViewModel { public required IEnumerable MeasuresInTableFormat { get; set; } - public static AcademicPerformanceAdditionalMeasuresViewModel MapToMeasuresInTableFormat(AdditionalMeasuresModel additionalMeasuresModel, EstablishmentServiceModel establishmentDetails) + public static AcademicPerformanceAdditionalMeasuresViewModel MapToMeasuresInTableFormat(AdditionalMeasuresModel additionalMeasuresModel, EstablishmentMinimumServiceModel establishmentDetails) { return new AcademicPerformanceAdditionalMeasuresViewModel { diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceSubjectsEnteredViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceSubjectsEnteredViewModel.cs index dfee61f2a..1df0310f8 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceSubjectsEnteredViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS4/AcademicPerformanceSubjectsEnteredViewModel.cs @@ -12,7 +12,7 @@ public class AcademicPerformanceSubjectsEnteredViewModel : SubjectsEnteredBaseMo public List? OtherSubjects { get; set; } - public static AcademicPerformanceSubjectsEnteredViewModel Map(EstablishmentServiceModel establishment, + public static AcademicPerformanceSubjectsEnteredViewModel Map(EstablishmentMinimumServiceModel establishment, IEnumerable gcseSubjectEntries, IEnumerable vocationalSubjectEntries, IEnumerable otherSubjectEntries) diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS4/CurriculumAndExtraCurricularActivitiesViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS4/CurriculumAndExtraCurricularActivitiesViewModel.cs index 733b5a129..18bb164f0 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS4/CurriculumAndExtraCurricularActivitiesViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS4/CurriculumAndExtraCurricularActivitiesViewModel.cs @@ -8,7 +8,7 @@ public class CurriculumAndExtraCurricularActivitiesViewModel : BaseViewModel { public required DisplayField SchoolWebsite { get; set; } - public static CurriculumAndExtraCurricularActivitiesViewModel Map(EstablishmentServiceModel establishment) + public static CurriculumAndExtraCurricularActivitiesViewModel Map(EstablishmentMinimumServiceModel establishment) { return new CurriculumAndExtraCurricularActivitiesViewModel { diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS5/KS5ViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS5/KS5ViewModel.cs index 8410ddf60..f91965abd 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS5/KS5ViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS5/KS5ViewModel.cs @@ -1,4 +1,5 @@ using SAPPub.Core.Enums.KS5Qualifications; +using SAPPub.Core.ServiceModels; using SAPPub.Core.ServiceModels.KS4.AboutSchool; using SAPPub.Web.Models; @@ -11,13 +12,13 @@ public class KS5ViewModel : BaseViewModel public string LevelPageTitle => GetPageTitle(Level3Qualification, Level2Qualification); - public static KS5ViewModel Map(AboutSchoolModel schoolDetails) + public static KS5ViewModel Map(EstablishmentMinimumServiceModel schoolDetails) { return new KS5ViewModel { - URN = schoolDetails.Urn, - SchoolName = schoolDetails.SchoolName, + URN = schoolDetails.URN, + SchoolName = schoolDetails.EstablishmentName, IsKS2 = schoolDetails.IsKS2, IsKS4 = schoolDetails.IsKS4, IsKS5 = schoolDetails.IsKS5 diff --git a/SAPPub.Web/Areas/Profiles/ViewModels/KS5/Ks5SubjectEnteredViewModel.cs b/SAPPub.Web/Areas/Profiles/ViewModels/KS5/Ks5SubjectEnteredViewModel.cs index 9c5bbd1ee..185295ca4 100644 --- a/SAPPub.Web/Areas/Profiles/ViewModels/KS5/Ks5SubjectEnteredViewModel.cs +++ b/SAPPub.Web/Areas/Profiles/ViewModels/KS5/Ks5SubjectEnteredViewModel.cs @@ -1,4 +1,5 @@ using SAPPub.Core.Enums; +using SAPPub.Core.ServiceModels; using SAPPub.Core.ServiceModels.KS4.AboutSchool; using SAPPub.Core.ServiceModels.Performance; using SAPPub.Web.Areas.Profiles.ViewModels.Performance; @@ -14,12 +15,12 @@ public class Ks5SubjectEnteredViewModel : SubjectsEnteredBaseModel public required DisplayField EstablilshmentWebsite { get; set; } - public static Ks5SubjectEnteredViewModel Map(AboutSchoolModel schoolDetails, IEnumerable subjectsEntered) + public static Ks5SubjectEnteredViewModel Map(EstablishmentMinimumServiceModel schoolDetails, IEnumerable subjectsEntered) { return new Ks5SubjectEnteredViewModel { - URN = schoolDetails.Urn, - SchoolName = schoolDetails.SchoolName, + URN = schoolDetails.URN, + SchoolName = schoolDetails.EstablishmentName, IsKS2 = schoolDetails.IsKS2, IsKS4 = schoolDetails.IsKS4, IsKS5 = schoolDetails.IsKS5, diff --git a/SAPPub.Web/Middleware/MyMemoryCache.cs b/SAPPub.Web/Middleware/MyMemoryCache.cs new file mode 100644 index 000000000..451385ae4 --- /dev/null +++ b/SAPPub.Web/Middleware/MyMemoryCache.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Caching.Memory; + +namespace SAPPub.Web.Middleware +{ + public class MyMemoryCache + { + public MemoryCache Cache { get; } = new MemoryCache( + new MemoryCacheOptions + { + }); + } +} diff --git a/SAPPub.Web/Program.cs b/SAPPub.Web/Program.cs index 64318de76..9623a0320 100644 --- a/SAPPub.Web/Program.cs +++ b/SAPPub.Web/Program.cs @@ -1,3 +1,5 @@ +using Autofac.Core; +using Dapper.Extensions.MiniProfiler; using Dfe.Analytics; using Dfe.Analytics.AspNetCore; using GovUk.Frontend.AspNetCore; @@ -71,6 +73,11 @@ public static void Main(string[] args) if (builder.Environment.IsDevelopment()) { builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); + builder.Services.AddMiniProfiler(options => + { + options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(); + }); + builder.Services.AddMiniProfilerForDapper(); } else { @@ -142,8 +149,11 @@ public static void Main(string[] args) // Add feature management abilility builder.Services.AddFeatureManagement(); - var app = builder.Build(); + // Add caching + builder.Services.AddSingleton(); + var app = builder.Build(); + app.UseMiniProfiler(); app.UseStatusCodePagesWithReExecute("/Error/{0}"); //Configure the HTTP request pipeline. diff --git a/SAPPub.Web/SAPPub.Web.csproj b/SAPPub.Web/SAPPub.Web.csproj index a8f5e2580..c054c6547 100644 --- a/SAPPub.Web/SAPPub.Web.csproj +++ b/SAPPub.Web/SAPPub.Web.csproj @@ -6,16 +6,19 @@ enable aspnet-SAPPub.Web-c8941719-1a44-4549-a199-e682cd5f4391 Linux + Debug;Release + + diff --git a/SAPPub.Web/Views/Shared/_Layout.cshtml b/SAPPub.Web/Views/Shared/_Layout.cshtml index 7963d85da..b3c9836a4 100644 --- a/SAPPub.Web/Views/Shared/_Layout.cshtml +++ b/SAPPub.Web/Views/Shared/_Layout.cshtml @@ -60,6 +60,7 @@ + @{ if (loadAnalytics) { diff --git a/SAPPub.Web/Views/_ViewImports.cshtml b/SAPPub.Web/Views/_ViewImports.cshtml index f2abf10cb..7d56afb14 100644 --- a/SAPPub.Web/Views/_ViewImports.cshtml +++ b/SAPPub.Web/Views/_ViewImports.cshtml @@ -6,3 +6,6 @@ @addTagHelper *, Microsoft.FeatureManagement.AspNetCore @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, GovUk.Frontend.AspNetCore + +@using StackExchange.Profiling +@addTagHelper *, MiniProfiler.AspNetCore.Mvc diff --git a/Tests/SAPPub.Core.Tests/Services/DestinationsServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/DestinationsServiceTests.cs index 772bad3c7..56c39a31f 100644 --- a/Tests/SAPPub.Core.Tests/Services/DestinationsServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/DestinationsServiceTests.cs @@ -15,11 +15,10 @@ public class DestinationsServiceTests private readonly Mock _mockKs5DestinationsRepo; private readonly DestinationsService _service; - private readonly EstablishmentServiceModel fakeEstablishment = new() + private readonly EstablishmentMinimumServiceModel fakeEstablishment = new() { URN = "123456", EstablishmentName = "Test Establishment", - PhaseOfEducationName = "Secondary School", LAName = "Council", LAId = "E09000001" }; @@ -83,7 +82,7 @@ public async Task GetKS4DestinationsDetailsAsync_ShouldReturnData() }; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockKs4DestinationsRepo @@ -140,8 +139,8 @@ public async Task GetKS4DestinationsDetailsAsync_ReturnsEmptyWhenNoEstablishment { // Arrange _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel()); + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel()); // Act var result = await _service.GetKS4DestinationsDetailsAsync(fakeEstablishment.URN, CancellationToken.None); @@ -192,7 +191,7 @@ public async Task GetKS5DestinationsDetailsAsync_ShouldReturnData() }; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockKs5DestinationsRepo @@ -228,8 +227,8 @@ public async Task GetKS5DestinationsDetailsAsync_ReturnsEmptyWhenNoEstablishment { // Arrange _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel()); + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel()); // Act var result = await _service.GetKS5DestinationsDetailsAsync(fakeEstablishment.URN, CancellationToken.None); diff --git a/Tests/SAPPub.Core.Tests/Services/EstablishmentServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/EstablishmentServiceTests.cs index 4003fe28a..9a5ee1e62 100644 --- a/Tests/SAPPub.Core.Tests/Services/EstablishmentServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/EstablishmentServiceTests.cs @@ -1,4 +1,5 @@ -using Moq; +using Microsoft.Extensions.Caching.Memory; +using Moq; using SAPPub.Core.Entities; using SAPPub.Core.Exceptions; using SAPPub.Core.Interfaces.Repositories; @@ -11,12 +12,13 @@ namespace SAPPub.Core.Tests.Services public class EstablishmentServiceTests { private readonly Mock _mockRepo; + private readonly Mock _mockMemoryCache = new(); private readonly EstablishmentService _service; public EstablishmentServiceTests() { _mockRepo = new Mock(); - _service = new EstablishmentService(_mockRepo.Object); + _service = new EstablishmentService(_mockRepo.Object, _mockMemoryCache.Object); } private readonly Establishment FakeEstablishmentOne = new() diff --git a/Tests/SAPPub.Core.Tests/Services/KS4/Attendance/AttendanceServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/KS4/Attendance/AttendanceServiceTests.cs index b38fdcf48..9ce109b62 100644 --- a/Tests/SAPPub.Core.Tests/Services/KS4/Attendance/AttendanceServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/KS4/Attendance/AttendanceServiceTests.cs @@ -16,11 +16,10 @@ public class AttendanceServiceTests private readonly Mock _mockEnglandAbsenceService; private readonly AttendanceService _service; - private readonly EstablishmentServiceModel fakeEstablishment = new() + private readonly EstablishmentMinimumServiceModel fakeEstablishment = new() { URN = "123456", EstablishmentName = "Test Establishment", - PhaseOfEducationName = "Secondary School", LAName = "Council", LAId = "E09000001" }; @@ -60,8 +59,8 @@ public async Task GetAttendenceDetailsAsync_ShouldReturnEmptyModel_WhenEstablish // Arrange var urn = "99999"; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(urn, It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel()); // not found + .Setup(r => r.GetEstablishmentMinimumAsync(urn, It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel()); // not found // Act var result = await _service.GetAttendenceDetailsAsync(urn, CancellationToken.None); @@ -102,7 +101,7 @@ public async Task GetAttendenceDetailsAsync_ShouldReturnData( }; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockEstablishmentAbsenceService @@ -162,7 +161,7 @@ public async Task GetAttendenceDetailsAsync_ShouldReturn_Absence_Data( }; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockEstablishmentAbsenceService diff --git a/Tests/SAPPub.Core.Tests/Services/KS4/Performance/AttainmentAndProgressServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/KS4/Performance/AttainmentAndProgressServiceTests.cs index 598ab8a99..324110886 100644 --- a/Tests/SAPPub.Core.Tests/Services/KS4/Performance/AttainmentAndProgressServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/KS4/Performance/AttainmentAndProgressServiceTests.cs @@ -16,11 +16,10 @@ public class AttainmentAndProgressServiceTests private readonly Mock _mockEnglandPerformanceService; private readonly AttainmentAndProgressService _service; - private readonly EstablishmentServiceModel fakeEstablishment = new() + private readonly EstablishmentMinimumServiceModel fakeEstablishment = new() { URN = "123456", EstablishmentName = "Test Establishment", - PhaseOfEducationName = "Secondary School", LAName = "Council", LAId = "E09000001" }; @@ -45,8 +44,8 @@ public async Task GetAttainmentAndProgressAsync_ShouldReturnEmptyModel_WhenEstab // Arrange var urn = "99999"; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(urn, It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel()); // not found + .Setup(r => r.GetEstablishmentMinimumAsync(urn, It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel()); // not found // Act var result = await _service.GetAttainmentAndProgressAsync(urn, AcademicYearSelection.Previous, CancellationToken.None); @@ -102,7 +101,7 @@ public async Task AttainmentAndProgressAsync_ShouldReturnData(AcademicYearSelect }; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockEstablishmentPerformanceService diff --git a/Tests/SAPPub.Core.Tests/Services/KS4/Performance/EnglishAndMathsResultsServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/KS4/Performance/EnglishAndMathsResultsServiceTests.cs index 6c7d8a0b6..913ded58c 100644 --- a/Tests/SAPPub.Core.Tests/Services/KS4/Performance/EnglishAndMathsResultsServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/KS4/Performance/EnglishAndMathsResultsServiceTests.cs @@ -15,11 +15,10 @@ public class EnglishAndMathsResultsServiceTests private readonly Mock _mockEnglandPerformanceService; private readonly EnglishAndMathsResultsService _service; - private readonly EstablishmentServiceModel fakeEstablishment = new() + private readonly EstablishmentMinimumServiceModel fakeEstablishment = new() { URN = "123456", EstablishmentName = "Test Establishment", - PhaseOfEducationName = "Secondary School", LAName = "Council", LAId = "E09000001" }; @@ -91,7 +90,7 @@ public async Task GetEnglishAndMathsResultsAsync_ShouldReturnData(int selectedGr }; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockEstablishmentPerformanceService @@ -192,8 +191,8 @@ public async Task GetEnglishAndMathsResultsAsync_ShouldReturnEmptyModel_WhenEsta // Arrange var urn = "99999"; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(urn, It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel()); // not found + .Setup(r => r.GetEstablishmentMinimumAsync(urn, It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel()); // not found // Act var result = await _service.GetEnglishAndMathsResultsAsync(urn, 4, CancellationToken.None); diff --git a/Tests/SAPPub.Core.Tests/Services/Performance/EnglishAndMathsQualificationsServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/Performance/EnglishAndMathsQualificationsServiceTests.cs index 2e4638802..30508c02e 100644 --- a/Tests/SAPPub.Core.Tests/Services/Performance/EnglishAndMathsQualificationsServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/Performance/EnglishAndMathsQualificationsServiceTests.cs @@ -13,11 +13,10 @@ public class EnglishAndMathsQualificationsServiceTests private readonly Mock _mockKs5PerformanceRepository; private readonly EnglishAndMathsQualificationsService _service; - private readonly EstablishmentServiceModel fakeEstablishment = new() + private readonly EstablishmentMinimumServiceModel fakeEstablishment = new() { URN = "123456", EstablishmentName = "Test Establishment", - PhaseOfEducationName = "Secondary School", LAName = "Council", LAId = "E09000001" }; @@ -89,7 +88,7 @@ public async Task GetEnglishAndMathsQualificationDetailsAsync_ThrowsWhenCancella private void SetupMocks(out KS5EstablishmentPerformance establishmentPerformance, out KS5EnglandPerformance englandPerformance, out KS5LAPerformance laPerformance) { _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(fakeEstablishment.URN, It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(fakeEstablishment.URN, It.IsAny())) .ReturnsAsync(fakeEstablishment); establishmentPerformance = new KS5EstablishmentPerformance diff --git a/Tests/SAPPub.Core.Tests/Services/Performance/KS2AdditionalMeasuresServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/Performance/KS2AdditionalMeasuresServiceTests.cs index 4a6666059..c7e7d76d9 100644 --- a/Tests/SAPPub.Core.Tests/Services/Performance/KS2AdditionalMeasuresServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/Performance/KS2AdditionalMeasuresServiceTests.cs @@ -62,8 +62,8 @@ public async Task GetAdditionalMeasures_ReturnsAllDataCorrectly() var expectedModel = GetKS2AdditionalMeasuresModel(); _establishmentService - .Setup(a => a.GetEstablishmentAsync(urn, It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel { URN = urn, LAId = laId }); + .Setup(a => a.GetEstablishmentMinimumAsync(urn, It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel { URN = urn, LAId = laId }); _ks2PerformanceRepository .Setup(a => a.GetEstablishmentPerformanceAsync(urn, It.IsAny())) diff --git a/Tests/SAPPub.Core.Tests/Services/Performance/KS2MeetingOrExceedingStandardsServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/Performance/KS2MeetingOrExceedingStandardsServiceTests.cs index 21331b89c..4d1e64025 100644 --- a/Tests/SAPPub.Core.Tests/Services/Performance/KS2MeetingOrExceedingStandardsServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/Performance/KS2MeetingOrExceedingStandardsServiceTests.cs @@ -62,8 +62,8 @@ public async Task GetMeetingOrExceedingStandardsPercentages_ReturnsAllDataCorrec var expectedModel = GetKS2MeetingOrExceedingStandardsModel(); _establishmentService - .Setup(a => a.GetEstablishmentAsync(urn, It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel { URN = urn, LAId = laId }); + .Setup(a => a.GetEstablishmentMinimumAsync(urn, It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel { URN = urn, LAId = laId }); _ks2PerformanceRepository .Setup(a => a.GetEstablishmentPerformanceAsync(urn, It.IsAny())) diff --git a/Tests/SAPPub.Core.Tests/Services/Performance/KS2ScaledScoresServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/Performance/KS2ScaledScoresServiceTests.cs index 3df224c9d..386a742c5 100644 --- a/Tests/SAPPub.Core.Tests/Services/Performance/KS2ScaledScoresServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/Performance/KS2ScaledScoresServiceTests.cs @@ -60,8 +60,8 @@ public async Task GetScaledScoreModel_ReturnsAllDataCorrectly() var expectedModel = GetKS2ScaledScoreModelModel(); _establishmentService - .Setup(a => a.GetEstablishmentAsync(urn, It.IsAny())) - .ReturnsAsync(new EstablishmentServiceModel { URN = urn, LAId = laId }); + .Setup(a => a.GetEstablishmentMinimumAsync(urn, It.IsAny())) + .ReturnsAsync(new EstablishmentMinimumServiceModel { URN = urn, LAId = laId }); _ks2PerformanceRepository .Setup(a => a.GetEstablishmentPerformanceAsync(urn, It.IsAny())) diff --git a/Tests/SAPPub.Core.Tests/Services/Performance/Level3QualificationsServiceTests.cs b/Tests/SAPPub.Core.Tests/Services/Performance/Level3QualificationsServiceTests.cs index 8a03ff7fa..62d4c7233 100644 --- a/Tests/SAPPub.Core.Tests/Services/Performance/Level3QualificationsServiceTests.cs +++ b/Tests/SAPPub.Core.Tests/Services/Performance/Level3QualificationsServiceTests.cs @@ -15,11 +15,10 @@ public class Level3QualificationsServiceTests private readonly Mock _mockKs5PerformanceRepository; private readonly Level3QualificationsService _service; - private readonly EstablishmentServiceModel fakeEstablishment = new() + private readonly EstablishmentMinimumServiceModel fakeEstablishment = new() { URN = "123456", EstablishmentName = "Test Establishment", - PhaseOfEducationName = "Secondary School", LAName = "Council", LAId = "E09000001" }; @@ -43,7 +42,7 @@ public async Task GetLevel3QualificationDetailsAsync_ShouldReturnEmptyModel_When { // Arrange _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(fakeEstablishment.URN, It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(fakeEstablishment.URN, It.IsAny())) .ReturnsAsync(fakeEstablishment); _mockKs5PerformanceRepository @@ -105,7 +104,7 @@ public async Task GetLevel3QualificationDetailsAsync_ShouldReturnData(Level3 qua var isAcademicQual = qualificationLevel == Level3.Academic; _mockEstablishmentService - .Setup(r => r.GetEstablishmentAsync(fakeEstablishment.URN, It.IsAny())) + .Setup(r => r.GetEstablishmentMinimumAsync(fakeEstablishment.URN, It.IsAny())) .ReturnsAsync(fakeEstablishment); var establishmentPerformance = new KS5EstablishmentPerformance diff --git a/Tests/SAPPub.Core.Tests/TestBuilders/EstablishmentMinimumTestBuilder.cs b/Tests/SAPPub.Core.Tests/TestBuilders/EstablishmentMinimumTestBuilder.cs new file mode 100644 index 000000000..a611c51b4 --- /dev/null +++ b/Tests/SAPPub.Core.Tests/TestBuilders/EstablishmentMinimumTestBuilder.cs @@ -0,0 +1,103 @@ +using Bogus; +using SAPPub.Core.Entities; +using SAPPub.Core.Enums; +using SAPPub.Core.Extensions; +using SAPPub.Core.ServiceModels; + +namespace SAPPub.Core.Tests.TestBuilders; + +public class EstablishmentMinimumTestBuilder +{ + private readonly Establishment _establishment = new(); + + public static string GenerateUrn() + { + // Generates a random 6-digit URN as a string + var random = new Random(); + return random.Next(100000, 999999).ToString(); + } + + public static string GenerateEstablishmentName() + { + // Generates a random establishment name + var adjectives = new[] { "Green", "Oak", "River", "Hill", "Sunny", "Maple", "Elm", "Cedar" }; + var types = new[] { "Primary", "Secondary", "Academy", "School", "College" }; + var suffixes = new[] { "Academy", "School", "College", "Institute" }; + + var random = new Random(); + var adjective = adjectives[random.Next(adjectives.Length)]; + var type = types[random.Next(types.Length)]; + var suffix = suffixes[random.Next(suffixes.Length)]; + + return $"{adjective} {type} {suffix}"; + } + + public EstablishmentMinimumTestBuilder WithURN(string urn) + { + _establishment.URN = urn; + return this; + } + + public EstablishmentMinimumTestBuilder WithEstablishmentName(string name) + { + _establishment.EstablishmentName = name; + return this; + } + + public EstablishmentMinimumTestBuilder WithLAId(string laId) + { + _establishment.LAId = laId; + return this; + } + + public EstablishmentMinimumTestBuilder WithLAName(string laName) + { + _establishment.LAName = laName; + return this; + } + + public EstablishmentMinimumTestBuilder WithIsKeyStage2(bool isKS2) + { + _establishment.IsKS2 = isKS2; + return this; + } + + public EstablishmentMinimumTestBuilder WithIsKeyStage4(bool isKS4) + { + _establishment.IsKS4 = isKS4; + return this; + } + + public EstablishmentMinimumTestBuilder WithIsKeyStage5(bool isKS5) + { + _establishment.IsKS5 = isKS5; + return this; + } + + public EstablishmentMinimumTestBuilder WithWebsite(string website) + { + _establishment.Website = website; + return this; + } + + public Establishment Build() + { + // fill basic values automatically if not set + if (string.IsNullOrEmpty(_establishment.URN)) + { + _establishment.URN = GenerateUrn(); + } + if (string.IsNullOrEmpty(_establishment.EstablishmentName)) + { + _establishment.EstablishmentName = GenerateEstablishmentName(); + } + return _establishment; + } + + public EstablishmentMinimumServiceModel BuildServiceModel() + { + var est = Build(); + + return EstablishmentMinimum.MapToServiceModel(est); + } +} \ No newline at end of file diff --git a/Tests/SAPPub.Web.Tests/ControllerAndServicesTests/SecondarySchool/AdmissionsTests.cs b/Tests/SAPPub.Web.Tests/ControllerAndServicesTests/SecondarySchool/AdmissionsTests.cs index e18ec35a4..e920901b5 100644 --- a/Tests/SAPPub.Web.Tests/ControllerAndServicesTests/SecondarySchool/AdmissionsTests.cs +++ b/Tests/SAPPub.Web.Tests/ControllerAndServicesTests/SecondarySchool/AdmissionsTests.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using Microsoft.FeatureManagement; using Moq; @@ -23,6 +24,7 @@ public class AdmissionsTests private readonly Mock _mockEstablishmentRepository = new(); private readonly Mock> _mockLogger = new(); private readonly Mock _featureManager = new(); + private readonly Mock _mockMemoryCache = new(); private readonly IEstablishmentService _establishmentService; private readonly IAdmissionsService _admissionsService; @@ -40,7 +42,7 @@ public AdmissionsTests() var tempPath = Path.Combine(Path.GetTempPath(), "SAPPubTests", Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); - _establishmentService = new EstablishmentService(_mockEstablishmentRepository.Object); + _establishmentService = new EstablishmentService(_mockEstablishmentRepository.Object, _mockMemoryCache.Object); _admissionsService = new EstablishmentAdmissionsService(_establishmentService, _mockLaService.Object); _controller = new AdmissionsController(_mockLogger.Object, _featureManager.Object); diff --git a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/BaseProfilesTests.cs b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/BaseProfilesTests.cs index a5bc60f1a..ba49120bf 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/BaseProfilesTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/BaseProfilesTests.cs @@ -10,6 +10,7 @@ public class BaseProfilesTests { protected readonly Mock mockEstablishmentService; protected EstablishmentServiceModel fakeEstablishment; + protected EstablishmentMinimumServiceModel fakeMinimumEstablishment; public BaseProfilesTests() { @@ -43,11 +44,22 @@ public BaseProfilesTests() .WithIsKeyStage4(true) .BuildServiceModel(); + fakeMinimumEstablishment = new EstablishmentMinimumTestBuilder() + .WithIsKeyStage2(true) + .WithLAName("Sheffield") + .WithIsKeyStage4(true) + .WithWebsite("https://www.gov.uk/") + .BuildServiceModel(); + mockEstablishmentService = new(); mockEstablishmentService .Setup(es => es.GetEstablishmentAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(fakeEstablishment); + + mockEstablishmentService + .Setup(es => es.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(fakeMinimumEstablishment); } } diff --git a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/CurriculumControllerTests.cs b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/CurriculumControllerTests.cs index a50209179..8539492b4 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/CurriculumControllerTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/CurriculumControllerTests.cs @@ -19,36 +19,13 @@ public class CurriculumControllerTests private readonly Mock _mockFeatureManager = new(); private readonly Mock> _mockLogger = new(); private readonly CurriculumController _controller; - private EstablishmentServiceModel _fakeEstablishment; + private EstablishmentMinimumServiceModel _fakeEstablishment; public CurriculumControllerTests() { - _fakeEstablishment = new EstablishmentTestBuilder() - .WithTrustName("Trust") + _fakeEstablishment = new EstablishmentMinimumTestBuilder() + .WithEstablishmentName("cool school") .WithWebsite("https://www.gov.uk/") - .WithTelephoneNum("012154896") - .WithAddressStreet("Street") - .WithAddressLocality("Locality") - .WithAddressTown("Town") - .WithAddressPostcode("Postcode") - .WithLAName("Sheffield") - .WithLAGssCode("123") - .WithTypeOfEstablishmentName("EstablishmentName") - .WithHeadteacherTitle("Title") - .WithHeadteacherFirstName("FirstName") - .WithHeadteacherLastName("LastName") - .WithAgeRangeLow("11") - .WithAgeRangeHigh("18") - .WithTotalPupils("1117") - .WithGenderName("GenderName") - .WithReligiousCharacterName("ReligiousCharacter") - .WithSixthForm(false) - .WithResourcedProvisionName("Resourced provision") - .WithEstablishmentTypeGroupId((int)EstablishmentTypeGroup.Colleges) - .WithStatusCode(1) - .WithOpenReasonId(10) - .WithOpenDate() - .WithSenTypes("VI - Visual Impairment, HI - Hearing Impairment") .WithIsKeyStage2(true) .WithIsKeyStage4(true) .BuildServiceModel(); @@ -56,7 +33,7 @@ public CurriculumControllerTests() _mockEstablishmentService = new(); _mockEstablishmentService - .Setup(es => es.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(es => es.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(_fakeEstablishment); var tempPath = Path.Combine(Path.GetTempPath(), "SAPPubTests", Guid.NewGuid().ToString()); diff --git a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS2ControllerTests.cs b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS2ControllerTests.cs index 186af2639..21e35eee8 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS2ControllerTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS2ControllerTests.cs @@ -29,7 +29,7 @@ public KS2ControllerTests() }); _mockKS2AdditionalMeasuresService = new Mock(); - _controller = new(opts) { Establishment = fakeEstablishment }; + _controller = new(opts) { Establishment = fakeMinimumEstablishment }; } [Fact] @@ -73,14 +73,14 @@ public async Task Get_AcademicPerformancePupilProgress_ReturnsCorrectData() // Arrange var expectedModel = GetKS2PupilPerformance(); _mockKS2PupilProgressService - .Setup(a => a.GetPupilProgressAsync(fakeEstablishment.URN, AcademicYearSelection.Previous2, CancellationToken.None)) + .Setup(a => a.GetPupilProgressAsync(fakeMinimumEstablishment.URN, AcademicYearSelection.Previous2, CancellationToken.None)) .ReturnsAsync(expectedModel); //Act var result = await _controller.AcademicPerformancePupilProgress( _mockKS2PupilProgressService.Object, - fakeEstablishment.URN, - fakeEstablishment.EstablishmentName, + fakeMinimumEstablishment.URN, + fakeMinimumEstablishment.EstablishmentName, AcademicYearSelection.Previous2.ToString().ToLower(), CancellationToken.None) as ViewResult; @@ -113,7 +113,7 @@ public async Task Get_AcademicPerformancePupilProgress_ReturnsCorrectData() Assert.Equal(AcademicYearSelection.Previous2, model.SelectedAcademicYear); _mockKS2PupilProgressService - .Verify(a => a.GetPupilProgressAsync(fakeEstablishment.URN, AcademicYearSelection.Previous2, It.IsAny()), Times.Once); + .Verify(a => a.GetPupilProgressAsync(fakeMinimumEstablishment.URN, AcademicYearSelection.Previous2, It.IsAny()), Times.Once); } [Fact] @@ -123,19 +123,19 @@ public async Task Get_AcademicPerformanceAttainmentAndProgress_InvalidYearSelect var expectedModel = GetKS2AdditionalMeasuresModel(); _mockKS2AdditionalMeasuresService - .Setup(a => a.GetAdditionalMeasures(fakeEstablishment.URN, CancellationToken.None)) + .Setup(a => a.GetAdditionalMeasures(fakeMinimumEstablishment.URN, CancellationToken.None)) .ReturnsAsync(expectedModel); // Act var result = await _controller.AcademicPerformanceAdditionalMeasures( _mockKS2AdditionalMeasuresService.Object, - fakeEstablishment.URN, - fakeEstablishment.EstablishmentName, + fakeMinimumEstablishment.URN, + fakeMinimumEstablishment.EstablishmentName, CancellationToken.None) as ViewResult; Assert.NotNull(result); var model = Assert.IsType(result?.Model); - Assert.Equal(fakeEstablishment.URN, model.URN); + Assert.Equal(fakeMinimumEstablishment.URN, model.URN); Assert.True(model.IsKS2); Assert.Equal(expectedModel.EstablishmentGrammarAtExpectedStandard, model.EstablishmentGrammarAtExpectedStandard.Value); Assert.Equal(expectedModel.EstablishmentGrammarAtHigherStandard, model.EstablishmentGrammarAtHigherStandard.Value); @@ -149,7 +149,7 @@ public async Task Get_AcademicPerformanceAttainmentAndProgress_InvalidYearSelect Assert.Equal(expectedModel.EnglandSENSupportPopulation, model.EnglandSENSupportPopulation.Value); _mockKS2AdditionalMeasuresService - .Verify(a => a.GetAdditionalMeasures(fakeEstablishment.URN, CancellationToken.None), Times.Once); + .Verify(a => a.GetAdditionalMeasures(fakeMinimumEstablishment.URN, CancellationToken.None), Times.Once); } @@ -160,19 +160,19 @@ public async Task Get_AcademicPerformanceMeetingOrExceedingStandards_ReturnsVali var expectedModel = GetMeetingOrExceedingStandardsModel(); _mockKS2MeetingOrExceedingStandardsService - .Setup(a => a.GetMeetingOrExceedingStandardsPercentages(fakeEstablishment.URN, CancellationToken.None)) + .Setup(a => a.GetMeetingOrExceedingStandardsPercentages(fakeMinimumEstablishment.URN, CancellationToken.None)) .ReturnsAsync(expectedModel); // Act var result = await _controller.AcademicPerformanceMeetingOrExceedingStandards( _mockKS2MeetingOrExceedingStandardsService.Object, - fakeEstablishment.URN, - fakeEstablishment.EstablishmentName, + fakeMinimumEstablishment.URN, + fakeMinimumEstablishment.EstablishmentName, CancellationToken.None) as ViewResult; Assert.NotNull(result); var model = Assert.IsType(result?.Model); - Assert.Equal(fakeEstablishment.URN, model.URN); + Assert.Equal(fakeMinimumEstablishment.URN, model.URN); Assert.True(model.IsKS2); Assert.Equal(expectedModel.EstablishmentPercentageMeetingOrExceeding.CurrentYear.Value, model.AllMeetingExceedingStandardsData!.Data[0]!.Value); Assert.Equal(expectedModel.LocalAuthorityPercentageMeetingOrExceeding.CurrentYear.Value, model.AllMeetingExceedingStandardsData!.Data[1]!.Value); @@ -200,7 +200,7 @@ public async Task Get_AcademicPerformanceMeetingOrExceedingStandards_ReturnsVali Assert.Equal(expectedModel.EnglandPercentageExceeding.CurrentYear.Value, model.AllExceedingStandardsOverTimeData!.Datasets[2].Data[2]!.Value); _mockKS2MeetingOrExceedingStandardsService - .Verify(a => a.GetMeetingOrExceedingStandardsPercentages(fakeEstablishment.URN, CancellationToken.None), Times.Once); + .Verify(a => a.GetMeetingOrExceedingStandardsPercentages(fakeMinimumEstablishment.URN, CancellationToken.None), Times.Once); } private static KS2MeetingOrExceedingStandardsModel GetMeetingOrExceedingStandardsModel() @@ -269,7 +269,7 @@ private KS2PupilPerformance GetKS2PupilPerformance() { return new KS2PupilPerformance { - Urn = fakeEstablishment.URN, + Urn = fakeMinimumEstablishment.URN, EstablishmentReadingScore = new CodedDouble(1, "", ""), EstablishmentReadingDescription = new CodedString("2", "", ""), EstablishmentReadingConfidenceUpper = new CodedDouble(3, "", ""), diff --git a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS4ControllerTests.cs b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS4ControllerTests.cs index da2b33eed..bfb57ea5f 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS4ControllerTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS4ControllerTests.cs @@ -26,7 +26,7 @@ public class KS4ControllerTests private readonly Mock _mockEnglishAndMathsResultsService = new(); private readonly Mock _mockAttainmentAndProgressService = new(); private readonly KS4Controller _controller; - private EstablishmentServiceModel _fakeEstablishment; + private EstablishmentMinimumServiceModel _fakeEstablishment; private List GcseSubjects = new() @@ -136,32 +136,8 @@ private EnglishAndMathsResultsModel EnglishAndMathsResults( public KS4ControllerTests() { - _fakeEstablishment = new EstablishmentTestBuilder() - .WithTrustName("Trust") - .WithWebsite("https://www.gov.uk/") - .WithTelephoneNum("012154896") - .WithAddressStreet("Street") - .WithAddressLocality("Locality") - .WithAddressTown("Town") - .WithAddressPostcode("Postcode") + _fakeEstablishment = new EstablishmentMinimumTestBuilder() .WithLAName("Sheffield") - .WithLAGssCode("123") - .WithTypeOfEstablishmentName("EstablishmentName") - .WithHeadteacherTitle("Title") - .WithHeadteacherFirstName("FirstName") - .WithHeadteacherLastName("LastName") - .WithAgeRangeLow("11") - .WithAgeRangeHigh("18") - .WithTotalPupils("1117") - .WithGenderName("GenderName") - .WithReligiousCharacterName("ReligiousCharacter") - .WithSixthForm(false) - .WithResourcedProvisionName("Resourced provision") - .WithEstablishmentTypeGroupId((int)EstablishmentTypeGroup.Colleges) - .WithStatusCode(1) - .WithOpenReasonId(10) - .WithOpenDate() - .WithSenTypes("VI - Visual Impairment, HI - Hearing Impairment") .WithIsKeyStage2(true) .WithIsKeyStage4(true) .BuildServiceModel(); @@ -169,7 +145,7 @@ public KS4ControllerTests() _mockEstablishmentService = new(); _mockEstablishmentService - .Setup(es => es.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(es => es.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(_fakeEstablishment); var tempPath = Path.Combine(Path.GetTempPath(), "SAPPubTests", Guid.NewGuid().ToString()); diff --git a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS5ControllerTests.cs b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS5ControllerTests.cs index e0b8624d5..4ce9d6db1 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS5ControllerTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Controllers/KS5ControllerTests.cs @@ -3,8 +3,10 @@ using Moq; using SAPPub.Core.Enums; using SAPPub.Core.Enums.KS5Qualifications; +using SAPPub.Core.Interfaces.Services; using SAPPub.Core.Interfaces.Services.KS4.AboutSchool; using SAPPub.Core.Interfaces.Services.Performance; +using SAPPub.Core.ServiceModels; using SAPPub.Core.ServiceModels.Common; using SAPPub.Core.ServiceModels.KS4.AboutSchool; using SAPPub.Core.ServiceModels.Performance; @@ -23,7 +25,7 @@ public class KS5ControllerTests : BaseProfilesTests private readonly Mock _mockLevel2QualificationsService = new(); private readonly Mock _mockEnglishAndMathsQualificationsService = new(); private readonly Mock _mockKs5EstablishmentSubjectEntriesService = new(); - private readonly Mock _mockAboutSchoolService = new(); + private readonly Mock _establishmentService = new(); private readonly KS5Controller _controller; public KS5ControllerTests() @@ -606,12 +608,12 @@ public async Task Get_EnglishAndMaths_NotKs5ReturnsErrorView() public async Task Get_SubjectsEntered_ReturnsExpected() { var expectedResult = GetSubjectsEnteredList(); - _mockAboutSchoolService - .Setup(a => a.GetAboutSchoolDetailsAsync(It.IsAny(), CancellationToken.None)) - .ReturnsAsync(new AboutSchoolModel + _establishmentService + .Setup(a => a.GetEstablishmentMinimumAsync(It.IsAny(), CancellationToken.None)) + .ReturnsAsync(new EstablishmentMinimumServiceModel { - Urn = fakeEstablishment.URN, - SchoolName = fakeEstablishment.EstablishmentName, + URN = fakeEstablishment.URN, + EstablishmentName = fakeEstablishment.EstablishmentName, IsKS5 = true }); @@ -620,7 +622,7 @@ public async Task Get_SubjectsEntered_ReturnsExpected() .ReturnsAsync(expectedResult); var result = await _controller.SubjectsEntered( - _mockAboutSchoolService.Object, + _establishmentService.Object, _mockKs5EstablishmentSubjectEntriesService.Object, QualificationType.AcademicQualifications, fakeEstablishment.URN, @@ -645,16 +647,16 @@ public async Task Get_SubjectsEntered_ReturnsExpected() [Fact] public async Task Get_SubjectsEntered_NoEstablishment_ReturnsErrorView() { - _mockAboutSchoolService - .Setup(a => a.GetAboutSchoolDetailsAsync(It.IsAny(), CancellationToken.None)) - .ReturnsAsync(new AboutSchoolModel + _establishmentService + .Setup(a => a.GetEstablishmentMinimumAsync(It.IsAny(), CancellationToken.None)) + .ReturnsAsync(new EstablishmentMinimumServiceModel { - Urn = null!, - SchoolName = fakeEstablishment.EstablishmentName + URN = null!, + EstablishmentName = fakeEstablishment.EstablishmentName }); var result = await _controller.SubjectsEntered( - _mockAboutSchoolService.Object, + _establishmentService.Object, _mockKs5EstablishmentSubjectEntriesService.Object, QualificationType.AcademicQualifications, fakeEstablishment.URN, @@ -671,8 +673,8 @@ public async Task Get_SubjectsEntered_NoEstablishment_ReturnsErrorView() It.IsAny(), It.Is>((v, t) => true))); - _mockAboutSchoolService - .Verify(a => a.GetAboutSchoolDetailsAsync(It.IsAny(), CancellationToken.None), Times.Once); + _establishmentService + .Verify(a => a.GetEstablishmentMinimumAsync(It.IsAny(), CancellationToken.None), Times.Once); _mockKs5EstablishmentSubjectEntriesService .Verify(a => a.GetSubjectEntriesByUrnAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); @@ -681,15 +683,15 @@ public async Task Get_SubjectsEntered_NoEstablishment_ReturnsErrorView() [Fact] public async Task Get_SubjectsEntered_NotKs5ReturnsErrorView() { - _mockAboutSchoolService - .Setup(a => a.GetAboutSchoolDetailsAsync(It.IsAny(), CancellationToken.None)) - .ReturnsAsync(new AboutSchoolModel + _establishmentService + .Setup(a => a.GetEstablishmentMinimumAsync(It.IsAny(), CancellationToken.None)) + .ReturnsAsync(new EstablishmentMinimumServiceModel { - Urn = fakeEstablishment.URN, - SchoolName = fakeEstablishment.EstablishmentName + URN = fakeEstablishment.URN, + EstablishmentName = fakeEstablishment.EstablishmentName }); var result = await _controller.SubjectsEntered( - _mockAboutSchoolService.Object, + _establishmentService.Object, _mockKs5EstablishmentSubjectEntriesService.Object, QualificationType.AcademicQualifications, fakeEstablishment.URN, @@ -706,8 +708,8 @@ public async Task Get_SubjectsEntered_NotKs5ReturnsErrorView() It.IsAny(), It.Is>((v, t) => true))); - _mockAboutSchoolService - .Verify(a => a.GetAboutSchoolDetailsAsync(It.IsAny(), CancellationToken.None), Times.Once); + _establishmentService + .Verify(a => a.GetEstablishmentMinimumAsync(It.IsAny(), CancellationToken.None), Times.Once); _mockKs5EstablishmentSubjectEntriesService .Verify(a => a.GetSubjectEntriesByUrnAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); diff --git a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilterTests.cs b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilterTests.cs index e42734c64..3f159a8bb 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilterTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Areas/Profiles/Filters/DfEAnalyticsAddPhaseTagFilterTests.cs @@ -83,8 +83,8 @@ public async Task IEstablishmentNotImplemented_LoadsEstablishmentFromService(boo { // Arrange _establishmentService - .Setup(x => x.GetEstablishmentAsync(_urn, CancellationToken.None)) - .ReturnsAsync(new EstablishmentServiceModel() + .Setup(x => x.GetEstablishmentMinimumAsync(_urn, CancellationToken.None)) + .ReturnsAsync(new EstablishmentMinimumServiceModel() { IsKS2 = isKS2, IsKS4 = isKS4, @@ -114,7 +114,7 @@ public async Task IEstablishmentNotImplemented_LoadsEstablishmentFromService(boo // Assert _establishmentService.Verify( - x => x.GetEstablishmentAsync(_urn, It.IsAny()), + x => x.GetEstablishmentMinimumAsync(_urn, It.IsAny()), Times.Once); if (isKS2) @@ -141,7 +141,7 @@ public async Task IEstablishmentImplemented_UsesEstablishment(bool isKS2, bool i // Arrange _controllerWithIEstablishment .SetupGet(x => x.Establishment) - .Returns(new EstablishmentServiceModel() + .Returns(new EstablishmentMinimumServiceModel() { IsKS2 = isKS2, IsKS4 = isKS4, diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/AdmissionsPageTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/AdmissionsPageTests.cs index b70e7ec0b..11216668c 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/AdmissionsPageTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/AdmissionsPageTests.cs @@ -18,6 +18,7 @@ public class AdmissionsPageTests : PageTestsBase private string _schoolNameMultiPhase = "Abraham Moss Community School"; private string _urnMultiPhase = "150009"; private readonly EstablishmentServiceModel _establishment = new(); + private readonly EstablishmentMinimumServiceModel _establishmentMinimum = new(); private readonly Mock _mockEstablishmentService; private readonly AdmissionsServiceModel _admissionsServiceModel; @@ -37,10 +38,22 @@ public AdmissionsPageTests(WebAppFixture fixture) : base(fixture) .WithEstablishmentTypeGroupId((int)EstablishmentTypeGroup.Academies) .BuildServiceModel(); + _establishmentMinimum = new EstablishmentMinimumTestBuilder() + .WithURN(_urn) + .WithEstablishmentName(_schoolName) + .WithIsKeyStage2(true) + .WithIsKeyStage4(false) + .WithWebsite("https://www.stpaulsacademy.co.uk") + .BuildServiceModel(); + _mockEstablishmentService .Setup(a => a.GetEstablishmentAsync(_urn, It.IsAny())) .ReturnsAsync(_establishment); + _mockEstablishmentService + .Setup(a => a.GetEstablishmentMinimumAsync(_urn, It.IsAny())) + .ReturnsAsync(_establishmentMinimum); + _admissionsServiceModel = GetAdmissionsServiceModel(_schoolName, isKs2: true, isKs4: false, _establishment.Website); _mockAdmissionsService @@ -271,7 +284,7 @@ public async Task Admissions_DisplaysStartingPrimarySchool_Info() private void ConfigureMultiPhaseSchool() { - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -279,7 +292,7 @@ private void ConfigureMultiPhaseSchool() .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); _mockAdmissionsService diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/CurriculumAndExtraCurricularActivitiesPageTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/CurriculumAndExtraCurricularActivitiesPageTests.cs index a745a645b..a569ecc3b 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/CurriculumAndExtraCurricularActivitiesPageTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/CurriculumAndExtraCurricularActivitiesPageTests.cs @@ -1,4 +1,5 @@ using Moq; +using SAPPub.Core.Entities; using SAPPub.Core.Interfaces.Services; using SAPPub.Core.ServiceModels; using SAPPub.Core.Tests.TestBuilders; @@ -15,6 +16,7 @@ public class CurriculumAndExtraCurricularActivitiesPageTests : PageTestsBase private string _schoolNameMultiPhase = "Abraham Moss Community School"; private string _urnMultiPhase = "150009"; private readonly EstablishmentServiceModel _establishment = new(); + private readonly EstablishmentMinimumServiceModel _establishmentMinimum = new(); private readonly Mock _mockEstablishmentService; public CurriculumAndExtraCurricularActivitiesPageTests(WebAppFixture fixture) : base(fixture) @@ -28,9 +30,20 @@ public CurriculumAndExtraCurricularActivitiesPageTests(WebAppFixture fixture) : .WithIsKeyStage4(false) .BuildServiceModel(); + _establishmentMinimum = new EstablishmentMinimumTestBuilder() + .WithURN(_urn) + .WithEstablishmentName(_schoolName) + .WithIsKeyStage2(true) + .WithIsKeyStage4(false) + .BuildServiceModel(); + _mockEstablishmentService .Setup(a => a.GetEstablishmentAsync(_urn, It.IsAny())) .ReturnsAsync(_establishment); + + _mockEstablishmentService + .Setup(a => a.GetEstablishmentMinimumAsync(_urn, It.IsAny())) + .ReturnsAsync(_establishmentMinimum); } [Fact] @@ -110,7 +123,7 @@ public async Task CurriculumPage_DoesNotDisplay_SubNavigation_WhenOnlyKS2() public async Task CurriculumPage_Displays_SubNavigation_WhenMultiplePhases() { // Arrange - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -118,7 +131,7 @@ public async Task CurriculumPage_Displays_SubNavigation_WhenMultiplePhases() .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); var url = BuildUrl(_urnMultiPhase, _schoolNameMultiPhase, _pageRoute); @@ -135,7 +148,7 @@ public async Task CurriculumPage_Displays_SubNavigation_WhenMultiplePhases() public async Task CurriculumPage_SubNavigation_HasCorrectLinks_WhenMultiplePhases() { // Arrange - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -143,7 +156,7 @@ public async Task CurriculumPage_SubNavigation_HasCorrectLinks_WhenMultiplePhase .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); var url = BuildUrl(_urnMultiPhase, _schoolNameMultiPhase, _pageRoute); @@ -196,7 +209,7 @@ public async Task CurriculumAndExtraCurricularActivitiesPage_Displays_Extra_Curr public async Task CurriculumAndExtraCurricularActivitiesPage_CurrentCurriculum_ContactSchoolText() { // Arrange - var schoolWithNoWebsite = new EstablishmentTestBuilder() + var schoolWithNoWebsite = new EstablishmentMinimumTestBuilder() .WithURN("100273") .WithEstablishmentName("Saint Paul Roman Catholic Infant School") .WithIsKeyStage2(true) @@ -205,7 +218,7 @@ public async Task CurriculumAndExtraCurricularActivitiesPage_CurrentCurriculum_C .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync("100273", It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync("100273", It.IsAny())) .ReturnsAsync(schoolWithNoWebsite); var url = BuildUrl("100273", "Saint Paul Roman Catholic Infant School", _pageRoute); @@ -223,7 +236,7 @@ public async Task CurriculumAndExtraCurricularActivitiesPage_CurrentCurriculum_C public async Task CurriculumAndExtraCurricularActivitiesPage_Displays_Extra_Curriculum_Summary_ContactSchoolText() { // Arrange - var schoolWithNoWebsite = new EstablishmentTestBuilder() + var schoolWithNoWebsite = new EstablishmentMinimumTestBuilder() .WithURN("100273") .WithEstablishmentName("Saint Paul Roman Catholic Infant School") .WithIsKeyStage2(true) @@ -232,7 +245,7 @@ public async Task CurriculumAndExtraCurricularActivitiesPage_Displays_Extra_Curr .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync("100273", It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync("100273", It.IsAny())) .ReturnsAsync(schoolWithNoWebsite); var url = BuildUrl("100273", "Saint Paul Roman Catholic Infant School", _pageRoute); diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/KS2AdditionalMeasuresPageTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/KS2AdditionalMeasuresPageTests.cs index 98482f520..861f555a6 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/KS2AdditionalMeasuresPageTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/KS2AdditionalMeasuresPageTests.cs @@ -17,7 +17,7 @@ public class KS2AdditionalMeasuresPageTests : PageTestsBase private readonly string _urn = "149976"; private readonly string _laName = "Test LA"; - private readonly EstablishmentServiceModel _establishment = new(); + private readonly EstablishmentMinimumServiceModel _establishment = new(); private readonly Mock _mockEstablishmentService; private readonly KS2AdditionalMeasuresModel _ks2AdditionalMeasuresModel; @@ -28,7 +28,7 @@ public KS2AdditionalMeasuresPageTests(WebAppFixture fixture) : base(fixture) { _ks2AdditionalMeasuresService = UseMock(); _mockEstablishmentService = UseMock(); - _establishment = new EstablishmentTestBuilder() + _establishment = new EstablishmentMinimumTestBuilder() .WithURN(_urn) .WithEstablishmentName($"School{_urn}") .WithIsKeyStage2(true) @@ -38,7 +38,7 @@ public KS2AdditionalMeasuresPageTests(WebAppFixture fixture) : base(fixture) _ks2AdditionalMeasuresModel = GetKS2AdditionalMeasuresModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(_establishment); _ks2AdditionalMeasuresService diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/MeetingOrExceedingStandardsPageTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/MeetingOrExceedingStandardsPageTests.cs index ead583cd8..1a5423e3c 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/MeetingOrExceedingStandardsPageTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/MeetingOrExceedingStandardsPageTests.cs @@ -18,6 +18,7 @@ public class MeetingOrExceedingStandardsPageTests : PageTestsBase private readonly string _schoolNameMultiPhase = "Abraham Moss Community School"; private readonly string _urnMultiPhase = "150009"; private readonly EstablishmentServiceModel _establishment = new(); + private readonly EstablishmentMinimumServiceModel _establishmentMinimum = new(); private readonly Mock _mockEstablishmentService; private readonly AdmissionsServiceModel _admissionsServiceModel; @@ -37,10 +38,22 @@ public MeetingOrExceedingStandardsPageTests(WebAppFixture fixture) : base(fixtur .WithEstablishmentTypeGroupId((int)EstablishmentTypeGroup.Academies) .BuildServiceModel(); + _establishmentMinimum = new EstablishmentMinimumTestBuilder() + .WithURN(_urn) + .WithEstablishmentName(_schoolName) + .WithIsKeyStage2(true) + .WithIsKeyStage4(false) + .WithWebsite("https://www.stpaulsacademy.co.uk") + .BuildServiceModel(); + _mockEstablishmentService .Setup(a => a.GetEstablishmentAsync(_urn, It.IsAny())) .ReturnsAsync(_establishment); + _mockEstablishmentService + .Setup(a => a.GetEstablishmentMinimumAsync(_urn, It.IsAny())) + .ReturnsAsync(_establishmentMinimum); + _admissionsServiceModel = GetAdmissionsServiceModel(_schoolName, isKs2: true, isKs4: false, _establishment.Website); _mockAdmissionsService @@ -157,7 +170,7 @@ public async Task MeetingOrExceedingStandardsPage_Displays_ExceedingExpectedStan // Act var doc = await Fixture.BrowseToPage(url); - + // Assert var chartDataCurrent = doc.QuerySelector("#exs-current-year-chart-container"); var tableDataCurrent = doc.QuerySelector("#exs-current-year-table-container"); @@ -171,7 +184,7 @@ public async Task MeetingOrExceedingStandardsPage_Displays_ExceedingExpectedStan private void ConfigureMultiPhaseSchool() { - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -179,7 +192,7 @@ private void ConfigureMultiPhaseSchool() .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); _mockAdmissionsService diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/ScaledScoreAcademicPerformacePageTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/ScaledScoreAcademicPerformacePageTests.cs index 0cb6ed63e..7a0731c9a 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/ScaledScoreAcademicPerformacePageTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS2/ScaledScoreAcademicPerformacePageTests.cs @@ -15,7 +15,7 @@ public class ScaledScoresAcademicPerformacePageTests : PageTestsBase private string _pageRoute = "/primary-performance/subject-scaled-scores"; private string _urn = "149976"; private string _laName = "Test LA"; - private readonly EstablishmentServiceModel _establishment = new(); + private readonly EstablishmentMinimumServiceModel _establishment = new(); private readonly Mock _mockEstablishmentService; private readonly KS2ScaledScoreModel _scaledScoreModel; @@ -25,7 +25,7 @@ public ScaledScoresAcademicPerformacePageTests(WebAppFixture fixture) : base(fix { _scaledScoreService = UseMock(); _mockEstablishmentService = UseMock(); - _establishment = new EstablishmentTestBuilder() + _establishment = new EstablishmentMinimumTestBuilder() .WithURN(_urn) .WithEstablishmentName($"School{_urn}") .WithIsKeyStage2(true) @@ -35,7 +35,7 @@ public ScaledScoresAcademicPerformacePageTests(WebAppFixture fixture) : base(fix _scaledScoreModel = GetScaledScoreModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(_establishment); _scaledScoreService diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/AdditionalMeasuresTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/AdditionalMeasuresTests.cs index f710b9048..0c6c4daf8 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/AdditionalMeasuresTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/AdditionalMeasuresTests.cs @@ -23,11 +23,11 @@ public AdditionalMeasuresTests(WebAppFixture fixture) : base(fixture) _serviceMock = UseMock(); _establishmentServiceMock = UseMock(); _establishmentServiceMock - .Setup(service => service.GetEstablishmentAsync( + .Setup(service => service.GetEstablishmentMinimumAsync( _urn, It.IsAny())) .ReturnsAsync( - new EstablishmentTestBuilder() + new EstablishmentMinimumTestBuilder() .WithURN(_urn) .WithEstablishmentName(_establishmentName) .WithIsKeyStage4(true) diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/CurriculumAndExtraCurricularActivitiesPageTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/CurriculumAndExtraCurricularActivitiesPageTests.cs index 3d9bdfb5f..810e80a2d 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/CurriculumAndExtraCurricularActivitiesPageTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/CurriculumAndExtraCurricularActivitiesPageTests.cs @@ -16,14 +16,14 @@ public class CurriculumAndExtraCurricularActivitiesPageTests : PageTestsBase private string _schoolName = "St Paul's Church of England Academy"; private string _schoolNameMultiPhase = "Abraham Moss Community School"; private string _urnMultiPhase = "150009"; - private readonly EstablishmentServiceModel _establishment = new(); + private readonly EstablishmentMinimumServiceModel _establishment = new(); private readonly Mock _mockEstablishmentService; public CurriculumAndExtraCurricularActivitiesPageTests(WebAppFixture fixture) : base(fixture) { _mockEstablishmentService = UseMock(); - _establishment = new EstablishmentTestBuilder() + _establishment = new EstablishmentMinimumTestBuilder() .WithURN(_urn) .WithEstablishmentName(_schoolName) .WithIsKeyStage2(false) @@ -31,7 +31,7 @@ public CurriculumAndExtraCurricularActivitiesPageTests(WebAppFixture fixture) : .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urn, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urn, It.IsAny())) .ReturnsAsync(_establishment); } @@ -70,7 +70,7 @@ public async Task CurriculumAndExtraCurricularActivitiesPage_DisplaysMainHeading [InlineData(true, false, 6)] // ks4 only school public async Task CurriculumAndExtraCurricularActivitiesPage_Displays_VerticalNavigation(bool isKs4, bool isKs2, int expectedItemCount) { - var establishment = new EstablishmentTestBuilder() + var establishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(isKs2) @@ -78,7 +78,7 @@ public async Task CurriculumAndExtraCurricularActivitiesPage_Displays_VerticalNa .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(establishment); var url = BuildUrl(_urnMultiPhase, _schoolNameMultiPhase, _pageRoute); @@ -126,7 +126,7 @@ public async Task CurriculumPage_DoesNotDisplay_SubNavigation_WhenOnlyKS4() public async Task CurriculumPage_Displays_SubNavigation_WhenMultiplePhases() { // Arrange - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -134,7 +134,7 @@ public async Task CurriculumPage_Displays_SubNavigation_WhenMultiplePhases() .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); var url = BuildUrl(_urnMultiPhase, _schoolNameMultiPhase, _pageRoute); @@ -156,7 +156,7 @@ public async Task AdmissionsPage_DoesNotDisplay_SubNavigation_WhenFeatureFlagDis .Setup(f => f.IsEnabledAsync(Constants.Constants.EnablePrimary)) .ReturnsAsync(false); - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -164,7 +164,7 @@ public async Task AdmissionsPage_DoesNotDisplay_SubNavigation_WhenFeatureFlagDis .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); var url = BuildUrl(_urnMultiPhase, _schoolNameMultiPhase, _pageRoute); @@ -182,7 +182,7 @@ public async Task AdmissionsPage_DoesNotDisplay_SubNavigation_WhenFeatureFlagDis public async Task CurriculumPage_SubNavigation_HasCorrectLinks_WhenMultiplePhases() { // Arrange - var multiPhaseEstablishment = new EstablishmentTestBuilder() + var multiPhaseEstablishment = new EstablishmentMinimumTestBuilder() .WithURN(_urnMultiPhase) .WithEstablishmentName(_schoolNameMultiPhase) .WithIsKeyStage2(true) @@ -190,7 +190,7 @@ public async Task CurriculumPage_SubNavigation_HasCorrectLinks_WhenMultiplePhase .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(_urnMultiPhase, It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(_urnMultiPhase, It.IsAny())) .ReturnsAsync(multiPhaseEstablishment); var url = BuildUrl(_urnMultiPhase, _schoolNameMultiPhase, _pageRoute); diff --git a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/SubjectsEnteredTests.cs b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/SubjectsEnteredTests.cs index 22674ae74..4027a174e 100644 --- a/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/SubjectsEnteredTests.cs +++ b/Tests/SAPPub.Web.Tests/Unit/Page/Areas/Profiles/KS4/SubjectsEnteredTests.cs @@ -16,18 +16,18 @@ public class SubjectsEnteredTests : PageTestsBase private static string _pageRoute = "/secondary-performance/subjects-entered"; private readonly Mock _mockEstablishmentSubjectEntriesService; private readonly Mock _mockEstablishmentService; - private EstablishmentServiceModel _establishment; + private EstablishmentMinimumServiceModel _establishment; public SubjectsEnteredTests(WebAppFixture fixture) : base(fixture) { _mockEstablishmentSubjectEntriesService = UseMock(); _mockEstablishmentService = UseMock(); - _establishment = new EstablishmentTestBuilder() + _establishment = new EstablishmentMinimumTestBuilder() .WithURN(_urn) .BuildServiceModel(); _mockEstablishmentService - .Setup(a => a.GetEstablishmentAsync(It.IsAny(), It.IsAny())) + .Setup(a => a.GetEstablishmentMinimumAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(_establishment); } diff --git a/docs/adrs/021-establishment-caching.md b/docs/adrs/021-establishment-caching.md new file mode 100644 index 000000000..266fc8c5c --- /dev/null +++ b/docs/adrs/021-establishment-caching.md @@ -0,0 +1,43 @@ +# 021 - Establishment Caching + +**Status**: accepted +**Deciders**: Dan Murfitt +**Date**: 2026-08-19 + + +## Context and Problem Statement + +During Load testing, (and subsequent profiling) it was identified that a large number of requests were being made of the Establishment entity + +- DfE Analytics Phase - would query URN and return IsKS2, IsKS4, IsKS5. +- PrimaryPhaseValidator - would query URN and return IsKS2 +- Page Models - Would query URN and return School Name, and LA number/name for display on pages + +As a minimum these three calls could potentially double the number of calls made before a page can be loaded or invalidated. + +## Decision Drivers + +- We don't currently know the expected capacity of the service, but it this feels like a "quick-win" to cut down the number of unnecessary calls. This is because the load test results indicated the postgres DB as a limitation, AKS pods were at no more than 50% load. +- We could rework *at least* the first two uses (above) into a single method, but this would still be one call per page which could be eliminated entirely with the proposal. + +## Proposal + +We implement an in-memory cache of the basic Establishment information needed + +- URN +- Establishment Name +- LAId +- LA Name +- IsKS2 +- IsKS4 +- IsKS5 + +Further fields might be added in future. + +The largest this would be (exported data into CSV format) would be ~3MB, when the overall server memory is running around 200MB, this would be of little to no consequence. + +This would be done the first time the establishment is called by a user and then kept indefinitely. [ADR-022](016-establishment-caching-further.md) covers some extra options. + +## Decision Outcome + +Build the cache method and review. \ No newline at end of file diff --git a/docs/adrs/022-establishment-caching-further.md b/docs/adrs/022-establishment-caching-further.md new file mode 100644 index 000000000..21f95edb6 --- /dev/null +++ b/docs/adrs/022-establishment-caching-further.md @@ -0,0 +1,23 @@ +# 022 - Establishment Caching Further + +**Status**: proposed +**Deciders**: Dan Murfitt +**Date**: 2026-08-19 + + +## Context and Problem Statement + +Implementing the Establishment cache could be further improved by caching *all* the establishments on load of the application/pod. + +A cache clearing option may also need to be implemented, as the current only way to clear the cache is by deployment. This is not necessarily a problem currently due to the number of releases we are doing, however longer-term this could become an issue with daily GIAS updated. + +## Decision Drivers + + +## Proposal + +On application startup, load the list of establishments in to memory. + +Enable either a URL to clear the cache (and make sure it hits all pods some how) or maybe a Github pipeline to update all pods. -- Reviewing needed on options. + +## Decision Outcome