From 1adfc35c9edace0e5c2e113b96410f6cb27f3bac Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 15 Apr 2020 15:26:21 +0100 Subject: [PATCH 01/12] Split WithAlerts between providers and employers, added tests --- ...loyerAppernticeshipsWithOrWithoutAlerts.cs | 162 ++++++++++++++++++ ...iderApprenticeshipsWithOrWithoutAlerts.cs} | 9 +- .../Services/ApprenticeshipSearchService.cs | 2 +- .../OrderedApprenticeshipSearchService.cs | 2 +- ...verseOrderedApprenticeshipSearchService.cs | 2 +- .../Domain/Extensions/AlertsExtensions.cs | 4 +- .../QueryableApprenticeshipsExtensions.cs | 33 +++- 7 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/{WhenGettingApprenticeshipsWithOrWithoutAlerts.cs => WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs} (89%) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs new file mode 100644 index 0000000000..d5fff9ea32 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -0,0 +1,162 @@ +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Services.Parameters; +using SFA.DAS.CommitmentsV2.Domain.Interfaces; +using SFA.DAS.CommitmentsV2.Extensions; +using SFA.DAS.CommitmentsV2.Models; +using SFA.DAS.CommitmentsV2.Types; + +namespace SFA.DAS.CommitmentsV2.UnitTests.Extensions.QueryableApprenticeshipsExtensions +{ + public class WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts + { + private IQueryable _apprenticeships; + private readonly ApprenticeshipSearchParameters _parameters = new ApprenticeshipSearchParameters { EmployerAccountId = 1 }; + + [SetUp] + public void Arrange() + { + _apprenticeships = GetTestData(); + } + + [Test] + public void ThenWillReturnApprenticeshipsWithAlerts() + { + //Act + var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); + + //Assert + Assert.AreEqual(1, result.Count); + Assert.AreEqual(3, result[0].Id); + } + + [Test] + public void ThenWillReturnApprenticeshipsWithoutAlerts() + { + //Act + var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); + + //Assert + Assert.AreEqual(6, result.Count); + + Assert.AreEqual(1, result[0].Id); + Assert.AreEqual(2, result[1].Id); + Assert.AreEqual(4, result[2].Id); + Assert.AreEqual(5, result[3].Id); + Assert.AreEqual(6, result[4].Id); + Assert.AreEqual(7, result[5].Id); + } + + private static IQueryable GetTestData() + { + var apprenticeships = new List + { + new Apprenticeship + { + Id = 1, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = false, + Status = Status.Fail, + EventStatus = EventStatus.New + } + } + }, + new Apprenticeship {Id = 2}, + new Apprenticeship + { + Id = 3, + ApprenticeshipUpdate = new List + { + new ApprenticeshipUpdate + { + Status = ApprenticeshipUpdateStatus.Pending, + Originator = Originator.Provider + } + } + }, + new Apprenticeship + { + Id = 4, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = true, + Status = Status.Fail, + EventStatus = EventStatus.New + } + } + }, + new Apprenticeship + { + Id = 5, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = false, + Status = Status.Pass, + EventStatus = EventStatus.New + } + } + }, + new Apprenticeship + { + Id = 6, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = false, + Status = Status.Fail, + EventStatus = EventStatus.Removed + } + } + }, + new Apprenticeship + { + Id = 7, + ApprenticeshipUpdate = new List + { + new ApprenticeshipUpdate + { + Status = ApprenticeshipUpdateStatus.Deleted, + Originator = Originator.Provider + } + } + }, + new Apprenticeship + { + Id = 8, + ApprenticeshipUpdate = new List + { + new ApprenticeshipUpdate + { + Status = ApprenticeshipUpdateStatus.Pending, + Originator = Originator.Unknown + } + } + }, + new Apprenticeship + { + Id = 9, + DataLockStatus = new List + { + new DataLockStatus + { + ErrorCode = DataLockErrorCode.Dlock03, + TriageStatus = TriageStatus.Unknown, + IsResolved = false + + } + } + } + }.AsQueryable(); + return apprenticeships; + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs similarity index 89% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeshipsWithOrWithoutAlerts.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs index 2bd8898dbf..315c93d943 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs @@ -1,15 +1,18 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Services.Parameters; +using SFA.DAS.CommitmentsV2.Domain.Interfaces; using SFA.DAS.CommitmentsV2.Extensions; using SFA.DAS.CommitmentsV2.Models; using SFA.DAS.CommitmentsV2.Types; namespace SFA.DAS.CommitmentsV2.UnitTests.Extensions.QueryableApprenticeshipsExtensions { - public class WhenGettingApprenticeshipsWithOrWithoutAlerts + public class WhenGettingProviderApprenticeshipsWithOrWithoutAlerts { private IQueryable _apprenticeships; + private readonly ApprenticeshipSearchParameters _parameters = new ApprenticeshipSearchParameters { ProviderId = 1 }; [SetUp] public void Arrange() @@ -21,7 +24,7 @@ public void Arrange() public void ThenWillReturnApprenticeshipsWithAlerts() { //Act - var result = _apprenticeships.WithAlerts(true).ToList(); + var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); //Assert Assert.AreEqual(2, result.Count); @@ -33,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts() public void ThenWillReturnApprenticeshipsWithoutAlerts() { //Act - var result = _apprenticeships.WithAlerts(false).ToList(); + var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); //Assert Assert.AreEqual(5, result.Count); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs index 92ad651b93..9dbdae7eff 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs @@ -223,7 +223,7 @@ private IQueryable GetApprenticeshipsQuery(ApprenticeshipSearchP private IQueryable GetApprenticeshipsWithFiltersQuery(ApprenticeshipSearchParameters searchParameters, bool withAlerts) { return GetApprenticeshipsQuery(searchParameters) - .WithAlerts(withAlerts) + .WithAlertsProviderOrEmployer(withAlerts, searchParameters) .Filter(searchParameters.Filters); } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 383a7bf9b3..9ec696575d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -27,7 +27,7 @@ public async Task Find(OrderedApprenticeshipSearchPa apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderBy(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index 613b582eb5..b681f9b303 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -27,7 +27,7 @@ public async Task Find(ReverseOrderedApprenticeshipS apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderByDescending(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index c1e1ca8cb4..ecf756def4 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -51,7 +51,7 @@ public static IEnumerable MapAlerts(this Apprenticeship source) return result; } - private static bool HasCourseDataLock(Apprenticeship source) + public static bool HasCourseDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.WithCourseError() && @@ -59,7 +59,7 @@ private static bool HasCourseDataLock(Apprenticeship source) !x.IsResolved); } - private static bool HasPriceDataLock(Apprenticeship source) + public static bool HasPriceDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.IsPriceOnly() && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 07b778523a..242c45c755 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using SFA.DAS.CommitmentsV2.Domain.Extensions; using SFA.DAS.CommitmentsV2.Domain.Interfaces; using SFA.DAS.CommitmentsV2.Models; using SFA.DAS.CommitmentsV2.Types; @@ -105,7 +106,14 @@ public static IQueryable Filter(this IQueryable return apprenticeships; } - public static IQueryable WithAlerts(this IQueryable apprenticeships, bool hasAlerts) + public static IQueryable WithAlertsProviderOrEmployer( + this IQueryable apprenticeships, bool hasAlerts, + IEmployerProviderIdentifier identifier) + { + return identifier.ProviderId.HasValue ? WithAlertsProvider(apprenticeships, hasAlerts) : WithAlertsEmployer(apprenticeships, hasAlerts); + } + + public static IQueryable WithAlertsProvider(this IQueryable apprenticeships, bool hasAlerts) { if (hasAlerts) { @@ -122,6 +130,29 @@ public static IQueryable WithAlerts(this IQueryable c.Status != ApprenticeshipUpdateStatus.Pending))); } + public static IQueryable WithAlertsEmployer(this IQueryable apprenticeships, bool hasAlerts) + { + if (hasAlerts) + { + return apprenticeships.Where(apprenticeship => apprenticeship.DataLockStatus.Any(c => !c.IsResolved + && c.Status == Status.Fail + && c.TriageStatus != TriageStatus.Unknown + && c.EventStatus != EventStatus.Removed) || + apprenticeship.ApprenticeshipUpdate != null && + apprenticeship.ApprenticeshipUpdate.Any( + c => c.Status == ApprenticeshipUpdateStatus.Pending + && (c.Originator == Originator.Employer + || c.Originator == Originator.Provider))); + } + var apprenticesWithAlerts = apprenticeships.Where(apprenticeship => + !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed && c.TriageStatus != TriageStatus.Unknown) + && + (apprenticeship.ApprenticeshipUpdate == null || + apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); + return apprenticesWithAlerts.Where + (x => !AlertsExtensions.HasCourseDataLock(x) + && !AlertsExtensions.HasPriceDataLock(x)); + } public static IQueryable WithProviderOrEmployerId( this IQueryable apprenticeships, IEmployerProviderIdentifier identifier) From f145f8b7e668ff6359182a67503245304b393ef4 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Fri, 17 Apr 2020 09:28:31 +0100 Subject: [PATCH 02/12] Change employer query Changed so that the DataLockStatus that have a TriageStatus of Unkown are not included for employer search. --- ...ingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 12 ++++++------ .../Domain/Extensions/AlertsExtensions.cs | 4 ++-- .../QueryableApprenticeshipsExtensions.cs | 13 +++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index d5fff9ea32..e658d68851 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -40,12 +40,12 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() //Assert Assert.AreEqual(6, result.Count); - Assert.AreEqual(1, result[0].Id); - Assert.AreEqual(2, result[1].Id); - Assert.AreEqual(4, result[2].Id); - Assert.AreEqual(5, result[3].Id); - Assert.AreEqual(6, result[4].Id); - Assert.AreEqual(7, result[5].Id); + Assert.AreEqual(2, result[0].Id); + Assert.AreEqual(4, result[1].Id); + Assert.AreEqual(5, result[2].Id); + Assert.AreEqual(6, result[3].Id); + Assert.AreEqual(7, result[4].Id); + Assert.AreEqual(9, result[5].Id); } private static IQueryable GetTestData() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index ecf756def4..c1e1ca8cb4 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -51,7 +51,7 @@ public static IEnumerable MapAlerts(this Apprenticeship source) return result; } - public static bool HasCourseDataLock(Apprenticeship source) + private static bool HasCourseDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.WithCourseError() && @@ -59,7 +59,7 @@ public static bool HasCourseDataLock(Apprenticeship source) !x.IsResolved); } - public static bool HasPriceDataLock(Apprenticeship source) + private static bool HasPriceDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.IsPriceOnly() && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 242c45c755..767c76eab1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -136,22 +136,19 @@ public static IQueryable WithAlertsEmployer(this IQueryable apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail - && c.TriageStatus != TriageStatus.Unknown - && c.EventStatus != EventStatus.Removed) || + && c.EventStatus != EventStatus.Removed ) && + apprenticeship.DataLockStatus.All(c=>c.TriageStatus!= TriageStatus.Unknown) || apprenticeship.ApprenticeshipUpdate != null && apprenticeship.ApprenticeshipUpdate.Any( c => c.Status == ApprenticeshipUpdateStatus.Pending && (c.Originator == Originator.Employer || c.Originator == Originator.Provider))); } - var apprenticesWithAlerts = apprenticeships.Where(apprenticeship => - !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed && c.TriageStatus != TriageStatus.Unknown) - && + return apprenticeships.Where(apprenticeship => + !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed) && + apprenticeship.DataLockStatus.All(c=>c.TriageStatus == TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); - return apprenticesWithAlerts.Where - (x => !AlertsExtensions.HasCourseDataLock(x) - && !AlertsExtensions.HasPriceDataLock(x)); } public static IQueryable WithProviderOrEmployerId( From 050d7e51b1895b6dae5a55d1864900070948c00f Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 17 Apr 2020 15:09:23 +0100 Subject: [PATCH 03/12] modified employer with alerts logic --- ...WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 3 ++- .../Domain/Extensions/AlertsExtensions.cs | 6 +++--- .../Extensions/QueryableApprenticeshipsExtensions.cs | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index d5fff9ea32..70a224e2ff 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -38,7 +38,7 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); //Assert - Assert.AreEqual(6, result.Count); + Assert.AreEqual(7, result.Count); Assert.AreEqual(1, result[0].Id); Assert.AreEqual(2, result[1].Id); @@ -46,6 +46,7 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() Assert.AreEqual(5, result[3].Id); Assert.AreEqual(6, result[4].Id); Assert.AreEqual(7, result[5].Id); + Assert.AreEqual(9, result[6].Id); } private static IQueryable GetTestData() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index ecf756def4..9d09e7714e 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -51,7 +51,7 @@ public static IEnumerable MapAlerts(this Apprenticeship source) return result; } - public static bool HasCourseDataLock(Apprenticeship source) + private static bool HasCourseDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.WithCourseError() && @@ -59,7 +59,7 @@ public static bool HasCourseDataLock(Apprenticeship source) !x.IsResolved); } - public static bool HasPriceDataLock(Apprenticeship source) + private static bool HasPriceDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.IsPriceOnly() && @@ -92,7 +92,7 @@ private static bool HasCourseDataLockChangesRequested(Apprenticeship source) } - private static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) + public static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) { return !source.IsProviderSearch && source.DataLockStatus.Any(x => x.Status == Status.Fail && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 242c45c755..cff4f7349e 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -150,8 +150,7 @@ public static IQueryable WithAlertsEmployer(this IQueryable c.Status != ApprenticeshipUpdateStatus.Pending))); return apprenticesWithAlerts.Where - (x => !AlertsExtensions.HasCourseDataLock(x) - && !AlertsExtensions.HasPriceDataLock(x)); + (x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); } public static IQueryable WithProviderOrEmployerId( From db4bd5615a70f951dc3b831035495986495272ed Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 17 Apr 2020 15:13:53 +0100 Subject: [PATCH 04/12] slight change to employer with alerts --- .../Extensions/QueryableApprenticeshipsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 72675bb248..52d6462ea6 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -149,7 +149,7 @@ public static IQueryable WithAlertsEmployer(this IQueryablec.TriageStatus == TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); - (x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); + return apprenticesWithAlerts.Where(x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); } public static IQueryable WithProviderOrEmployerId( From 128c39223c122dadad62d3a1baf31162f94f80fb Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 17 Apr 2020 17:12:37 +0100 Subject: [PATCH 05/12] more with alerts stuff --- ...WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 3 +-- .../Domain/Extensions/AlertsExtensions.cs | 6 +++--- .../Extensions/QueryableApprenticeshipsExtensions.cs | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index 88f88d2a2c..e658d68851 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -38,7 +38,7 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); //Assert - Assert.AreEqual(7, result.Count); + Assert.AreEqual(6, result.Count); Assert.AreEqual(2, result[0].Id); Assert.AreEqual(4, result[1].Id); @@ -46,7 +46,6 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() Assert.AreEqual(6, result[3].Id); Assert.AreEqual(7, result[4].Id); Assert.AreEqual(9, result[5].Id); - Assert.AreEqual(9, result[6].Id); } private static IQueryable GetTestData() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index 9d09e7714e..90cd7376a3 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -61,7 +61,7 @@ private static bool HasCourseDataLock(Apprenticeship source) private static bool HasPriceDataLock(Apprenticeship source) { - return source.DataLockStatus.Any(x => + return source.IsProviderSearch && source.DataLockStatus.Any(x => x.IsPriceOnly() && x.TriageStatus == TriageStatus.Unknown && !x.IsResolved); @@ -69,7 +69,7 @@ private static bool HasPriceDataLock(Apprenticeship source) private static bool HasCourseDataLockPendingChanges(Apprenticeship source) { - return source.DataLockStatus.Any(x => + return source.IsProviderSearch && source.DataLockStatus.Any(x => x.WithCourseError() && x.TriageStatus == TriageStatus.Change && !x.IsResolved); @@ -92,7 +92,7 @@ private static bool HasCourseDataLockChangesRequested(Apprenticeship source) } - public static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) + private static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) { return !source.IsProviderSearch && source.DataLockStatus.Any(x => x.Status == Status.Fail && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 52d6462ea6..767c76eab1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -144,12 +144,11 @@ public static IQueryable WithAlertsEmployer(this IQueryable + return apprenticeships.Where(apprenticeship => !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed) && apprenticeship.DataLockStatus.All(c=>c.TriageStatus == TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); - return apprenticesWithAlerts.Where(x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); } public static IQueryable WithProviderOrEmployerId( From 4998195b61b89595be720cf7d5d28a301bdfb092 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Mon, 20 Apr 2020 14:31:47 +0100 Subject: [PATCH 06/12] Correct query for employer alerts and non alerts --- .../SearchTests/SearchParameterServiceTestBase.cs | 6 ------ .../Extensions/QueryableApprenticeshipsExtensions.cs | 9 +++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs index 44839959d3..796f0f9596 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs @@ -62,8 +62,6 @@ protected static List GetTestApprenticeshipsWithAlerts(Apprentic CourseName = "Course", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(12), - ProviderRef = searchParameters.ProviderId.ToString(), - EmployerRef = searchParameters.EmployerAccountId.ToString(), Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")}, ApprenticeshipUpdate = new List(), DataLockStatus = new List() @@ -76,8 +74,6 @@ protected static List GetTestApprenticeshipsWithAlerts(Apprentic CourseName = "Course", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(12), - ProviderRef = searchParameters.ProviderId.ToString(), - EmployerRef = searchParameters.EmployerAccountId.ToString(), Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")}, ApprenticeshipUpdate = new List(), DataLockStatus = new List() @@ -89,8 +85,6 @@ protected static List GetTestApprenticeshipsWithAlerts(Apprentic Uln = "Uln", CourseName = "Course", StartDate = DateTime.UtcNow, - ProviderRef = searchParameters.ProviderId.ToString(), - EmployerRef = searchParameters.EmployerAccountId.ToString(), Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")}, ApprenticeshipUpdate = new List(), DataLockStatus = new List() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 767c76eab1..938c50385d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -136,8 +136,8 @@ public static IQueryable WithAlertsEmployer(this IQueryable apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail - && c.EventStatus != EventStatus.Removed ) && - apprenticeship.DataLockStatus.All(c=>c.TriageStatus!= TriageStatus.Unknown) || + && c.EventStatus != EventStatus.Removed + || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) || apprenticeship.ApprenticeshipUpdate != null && apprenticeship.ApprenticeshipUpdate.Any( c => c.Status == ApprenticeshipUpdateStatus.Pending @@ -145,8 +145,9 @@ public static IQueryable WithAlertsEmployer(this IQueryable - !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed) && - apprenticeship.DataLockStatus.All(c=>c.TriageStatus == TriageStatus.Unknown) && + !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed + || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) && + (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); } From 3444bff1068645eb8c2d930b3f6a353437bd7d0e Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Tue, 21 Apr 2020 15:36:09 +0100 Subject: [PATCH 07/12] slight unit test fix --- .../WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index e658d68851..53fd39d592 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -27,8 +27,9 @@ public void ThenWillReturnApprenticeshipsWithAlerts() var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); //Assert - Assert.AreEqual(1, result.Count); - Assert.AreEqual(3, result[0].Id); + Assert.AreEqual(2, result.Count); + Assert.AreEqual(1, result[0].Id); + Assert.AreEqual(3, result[1].Id); } [Test] From 15b5bad1359216bad4746f24fe6742ee8f074412 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Tue, 21 Apr 2020 17:33:57 +0100 Subject: [PATCH 08/12] fixed incorrect extension change --- .../SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index 90cd7376a3..fe19e7cb75 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -69,7 +69,7 @@ private static bool HasPriceDataLock(Apprenticeship source) private static bool HasCourseDataLockPendingChanges(Apprenticeship source) { - return source.IsProviderSearch && source.DataLockStatus.Any(x => + return source.DataLockStatus.Any(x => x.WithCourseError() && x.TriageStatus == TriageStatus.Change && !x.IsResolved); From 8a429bedbf607ce93ae7ff6a08fe579bdd53a622 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Wed, 22 Apr 2020 10:58:04 +0100 Subject: [PATCH 09/12] Correct employer query for search --- .../WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 3 ++- .../Extensions/QueryableApprenticeshipsExtensions.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index 53fd39d592..6537874848 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -62,7 +62,8 @@ private static IQueryable GetTestData() { IsResolved = false, Status = Status.Fail, - EventStatus = EventStatus.New + EventStatus = EventStatus.New, + TriageStatus = TriageStatus.Change } } }, diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 938c50385d..a5e78457bc 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -137,7 +137,7 @@ public static IQueryable WithAlertsEmployer(this IQueryable apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed - || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) || + && c.TriageStatus != TriageStatus.Unknown) || apprenticeship.ApprenticeshipUpdate != null && apprenticeship.ApprenticeshipUpdate.Any( c => c.Status == ApprenticeshipUpdateStatus.Pending @@ -146,7 +146,7 @@ public static IQueryable WithAlertsEmployer(this IQueryable !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed - || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) && + && c.TriageStatus != TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); From 44f10b3e56dea18643ce0de3a9c5ea10726b0e88 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Apr 2020 11:54:07 +0100 Subject: [PATCH 10/12] Renamed unhelpfully named function. Also fixed some incorrect accessibility modifiers. --- .../WhenGettingApprenticeships.cs | 6 +++--- ...ttingEmployerApprenticeshipsWithOrWithoutAlerts.cs} | 4 ++-- ...ettingProviderApprenticeshipsWithOrWithoutAlerts.cs | 4 ++-- .../Search/Services/ApprenticeshipSearchService.cs | 2 +- .../Services/OrderedApprenticeshipSearchService.cs | 4 ++-- .../ReverseOrderedApprenticeshipSearchService.cs | 4 ++-- .../GetApprenticeshipsFilterValuesQueryHandler.cs | 10 +++++----- .../Extensions/QueryableApprenticeshipsExtensions.cs | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/{WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs => WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs} (96%) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs index 1dce4a1c89..3261aea00b 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs @@ -28,7 +28,7 @@ public void Then_Returns_Provider_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.ProviderId == searchParameters.ProviderId); - var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); + var result = apprenticeships.AsQueryable().WithId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -53,7 +53,7 @@ public void Then_Returns_Employer_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.EmployerAccountId == searchParameters.EmployerAccountId); - var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); + var result = apprenticeships.AsQueryable().WithId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -73,7 +73,7 @@ public void Then_Returns_All_Apprenticeships_If_No_Provider_Or_Employer_Id_Found searchParameters.ProviderId = null; searchParameters.EmployerAccountId = null; - var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); + var result = apprenticeships.AsQueryable().WithId(searchParameters); result.Should().BeEquivalentTo(apprenticeships); } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs similarity index 96% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs index 53fd39d592..f2ce8b967a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs @@ -24,7 +24,7 @@ public void Arrange() public void ThenWillReturnApprenticeshipsWithAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(true, _parameters).ToList(); //Assert Assert.AreEqual(2, result.Count); @@ -36,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts() public void ThenWillReturnApprenticeshipsWithoutAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(false, _parameters).ToList(); //Assert Assert.AreEqual(6, result.Count); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs index 315c93d943..a98ef73336 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs @@ -24,7 +24,7 @@ public void Arrange() public void ThenWillReturnApprenticeshipsWithAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(true, _parameters).ToList(); //Assert Assert.AreEqual(2, result.Count); @@ -36,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts() public void ThenWillReturnApprenticeshipsWithoutAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(false, _parameters).ToList(); //Assert Assert.AreEqual(5, result.Count); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs index 9dbdae7eff..fa987c67ef 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs @@ -223,7 +223,7 @@ private IQueryable GetApprenticeshipsQuery(ApprenticeshipSearchP private IQueryable GetApprenticeshipsWithFiltersQuery(ApprenticeshipSearchParameters searchParameters, bool withAlerts) { return GetApprenticeshipsQuery(searchParameters) - .WithAlertsProviderOrEmployer(withAlerts, searchParameters) + .WithAlerts(withAlerts, searchParameters) .Filter(searchParameters.Filters); } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 9ec696575d..334a545e1b 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -20,14 +20,14 @@ public async Task Find(OrderedApprenticeshipSearchPa { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithProviderOrEmployerId(searchParameters) + .WithId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderBy(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index b681f9b303..67034d6624 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -20,14 +20,14 @@ public async Task Find(ReverseOrderedApprenticeshipS { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithProviderOrEmployerId(searchParameters) + .WithId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderByDescending(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs index c392f47965..20fd7d7820 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs @@ -101,7 +101,7 @@ public async Task Handle(GetApprentic private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Select(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Distinct() @@ -111,7 +111,7 @@ private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValu private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.Provider.Name) .Select(apprenticeship => apprenticeship.Cohort.Provider.Name) .Distinct() @@ -121,7 +121,7 @@ private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValu private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .OrderBy(apprenticeship => apprenticeship.CourseName) .Select(apprenticeship => apprenticeship.CourseName) .Distinct() @@ -131,7 +131,7 @@ private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValues private Task> GetDistinctStartDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .Where(apprenticeship => apprenticeship.StartDate.HasValue) .OrderBy(apprenticeship => apprenticeship.StartDate) .Select(apprenticeship => apprenticeship.StartDate.Value) @@ -142,7 +142,7 @@ private Task> GetDistinctStartDates(GetApprenticeshipsFilterValue private Task> GetDistinctEndDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .Where(apprenticeship => apprenticeship.EndDate.HasValue) .OrderBy(apprenticeship => apprenticeship.EndDate) .Select(apprenticeship => apprenticeship.EndDate.Value) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 938c50385d..47df6214de 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -106,14 +106,14 @@ public static IQueryable Filter(this IQueryable return apprenticeships; } - public static IQueryable WithAlertsProviderOrEmployer( + public static IQueryable WithAlerts( this IQueryable apprenticeships, bool hasAlerts, IEmployerProviderIdentifier identifier) { return identifier.ProviderId.HasValue ? WithAlertsProvider(apprenticeships, hasAlerts) : WithAlertsEmployer(apprenticeships, hasAlerts); } - public static IQueryable WithAlertsProvider(this IQueryable apprenticeships, bool hasAlerts) + private static IQueryable WithAlertsProvider(this IQueryable apprenticeships, bool hasAlerts) { if (hasAlerts) { @@ -130,7 +130,7 @@ public static IQueryable WithAlertsProvider(this IQueryable c.Status != ApprenticeshipUpdateStatus.Pending))); } - public static IQueryable WithAlertsEmployer(this IQueryable apprenticeships, bool hasAlerts) + private static IQueryable WithAlertsEmployer(this IQueryable apprenticeships, bool hasAlerts) { if (hasAlerts) { From 3679d94f7a4587659e996ebffba2dbb00a0286c5 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Apr 2020 12:04:27 +0100 Subject: [PATCH 11/12] fixed poorly done refactoring --- .../WhenGettingApprenticeships.cs | 6 +++--- .../Services/OrderedApprenticeshipSearchService.cs | 2 +- .../ReverseOrderedApprenticeshipSearchService.cs | 2 +- .../GetApprenticeshipsFilterValuesQueryHandler.cs | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs index 3261aea00b..1dce4a1c89 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs @@ -28,7 +28,7 @@ public void Then_Returns_Provider_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.ProviderId == searchParameters.ProviderId); - var result = apprenticeships.AsQueryable().WithId(searchParameters); + var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -53,7 +53,7 @@ public void Then_Returns_Employer_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.EmployerAccountId == searchParameters.EmployerAccountId); - var result = apprenticeships.AsQueryable().WithId(searchParameters); + var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -73,7 +73,7 @@ public void Then_Returns_All_Apprenticeships_If_No_Provider_Or_Employer_Id_Found searchParameters.ProviderId = null; searchParameters.EmployerAccountId = null; - var result = apprenticeships.AsQueryable().WithId(searchParameters); + var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); result.Should().BeEquivalentTo(apprenticeships); } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 334a545e1b..99ff875fa7 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -20,7 +20,7 @@ public async Task Find(OrderedApprenticeshipSearchPa { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithId(searchParameters) + .WithProviderOrEmployerId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index 67034d6624..72cf89b1dd 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -20,7 +20,7 @@ public async Task Find(ReverseOrderedApprenticeshipS { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithId(searchParameters) + .WithProviderOrEmployerId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs index 20fd7d7820..c392f47965 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs @@ -101,7 +101,7 @@ public async Task Handle(GetApprentic private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Select(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Distinct() @@ -111,7 +111,7 @@ private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValu private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.Provider.Name) .Select(apprenticeship => apprenticeship.Cohort.Provider.Name) .Distinct() @@ -121,7 +121,7 @@ private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValu private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .OrderBy(apprenticeship => apprenticeship.CourseName) .Select(apprenticeship => apprenticeship.CourseName) .Distinct() @@ -131,7 +131,7 @@ private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValues private Task> GetDistinctStartDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .Where(apprenticeship => apprenticeship.StartDate.HasValue) .OrderBy(apprenticeship => apprenticeship.StartDate) .Select(apprenticeship => apprenticeship.StartDate.Value) @@ -142,7 +142,7 @@ private Task> GetDistinctStartDates(GetApprenticeshipsFilterValue private Task> GetDistinctEndDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .Where(apprenticeship => apprenticeship.EndDate.HasValue) .OrderBy(apprenticeship => apprenticeship.EndDate) .Select(apprenticeship => apprenticeship.EndDate.Value) From 8ee266aa20120de7804b8fd5879538abe3c5e100 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Thu, 23 Apr 2020 09:11:36 +0100 Subject: [PATCH 12/12] Add missing include for provider on search sorting (cherry picked from commit 76a8268c7e4d7ea5df4e086fdd6e705bfd243b60) --- .../Search/Services/OrderedApprenticeshipSearchService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 99ff875fa7..59530b064d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -35,7 +35,9 @@ public async Task Find(OrderedApprenticeshipSearchPa .Include(apprenticeship => apprenticeship.ApprenticeshipUpdate) .Include(apprenticeship => apprenticeship.DataLockStatus) .Include(apprenticeship => apprenticeship.Cohort) - .ThenInclude(cohort => cohort.AccountLegalEntity); + .ThenInclude(cohort => cohort.AccountLegalEntity) + .Include(apprenticeship => apprenticeship.Cohort) + .ThenInclude(cohort => cohort.Provider); var totalApprenticeshipsFound = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken);