From 28be1d1b53d9cd8fe1c57c12ba250a3a49c75dd1 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Thu, 9 Jul 2020 12:16:20 +0100 Subject: [PATCH 01/13] CON-2087-DB-Changes new column MadeRedundant. --- src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql b/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql index 763ada6919..e5dd5346b7 100644 --- a/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql +++ b/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql @@ -36,7 +36,8 @@ [ContinuationOfId] BIGINT NULL, [OriginalStartDate] DATETIME NULL CONSTRAINT [FK_Apprenticeship_Commitment] FOREIGN KEY ([CommitmentId]) REFERENCES [Commitment]([Id]), - CONSTRAINT [FK_Apprenticeship_AssessmentOrganisation] FOREIGN KEY ([EPAOrgId]) REFERENCES [AssessmentOrganisation]([EPAOrgId]) + [MadeRedundant] BIT NULL, + CONSTRAINT [FK_Apprenticeship_AssessmentOrganisation] FOREIGN KEY ([EPAOrgId]) REFERENCES [AssessmentOrganisation]([EPAOrgId]) ) GO CREATE NONCLUSTERED INDEX [IX_Apprenticeship_CommitmentId] ON [dbo].[Apprenticeship] ([CommitmentId]) INCLUDE ([AgreedOn], [AgreementStatus], [Cost], [CreatedOn], [DateOfBirth], [EmployerRef], [EndDate], [FirstName], [LastName], [NINumber], [PaymentOrder], [PaymentStatus], [ProviderRef], [StartDate], [TrainingCode], [TrainingName], [TrainingType], [ULN], [StopDate], [PauseDate], [HasHadDataLockSuccess], [PendingUpdateOriginator]) WITH (ONLINE = ON) From 7e74217e435d90a7961faede8a5a034e238a2bff Mon Sep 17 00:00:00 2001 From: Shahzad Date: Thu, 9 Jul 2020 12:54:38 +0100 Subject: [PATCH 02/13] CON-2087 api changes to make the madeRedundant field visible. --- .../Apprenticeship/Apprenticeship.cs | 1 + .../Orchestrators/Mappers/ApprenticeshipMapper.cs | 3 ++- .../Views/ApprenticeshipSummary.sql | 3 ++- src/SFA.DAS.Commitments.Domain/Entities/Apprenticeship.cs | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/Apprenticeship.cs b/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/Apprenticeship.cs index b8e7dacea2..81e62c6be7 100644 --- a/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/Apprenticeship.cs +++ b/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/Apprenticeship.cs @@ -51,5 +51,6 @@ public class Apprenticeship public Guid? ReservationId { get; set; } public DateTime? OriginalStartDate { get; set; } public long? ContinuationOfId { get; set; } + public bool? MadeRedundant { get; set; } } } \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Api/Orchestrators/Mappers/ApprenticeshipMapper.cs b/src/SFA.DAS.Commitments.Api/Orchestrators/Mappers/ApprenticeshipMapper.cs index 96a2a427b5..330af862fb 100644 --- a/src/SFA.DAS.Commitments.Api/Orchestrators/Mappers/ApprenticeshipMapper.cs +++ b/src/SFA.DAS.Commitments.Api/Orchestrators/Mappers/ApprenticeshipMapper.cs @@ -57,7 +57,8 @@ public Apprenticeship MapFrom(Domain.Entities.Apprenticeship source, CallerType HasHadDataLockSuccess = source.HasHadDataLockSuccess, EndpointAssessorName = source.EndpointAssessorName, ReservationId = source.ReservationId, - ContinuationOfId = source.ContinuationOfId + ContinuationOfId = source.ContinuationOfId, + MadeRedundant = source.MadeRedundant }; } diff --git a/src/SFA.DAS.Commitments.Database/Views/ApprenticeshipSummary.sql b/src/SFA.DAS.Commitments.Database/Views/ApprenticeshipSummary.sql index cb366865d9..a9365bbde2 100644 --- a/src/SFA.DAS.Commitments.Database/Views/ApprenticeshipSummary.sql +++ b/src/SFA.DAS.Commitments.Database/Views/ApprenticeshipSummary.sql @@ -55,7 +55,8 @@ SELECT END AS 'ProviderCanApproveApprenticeship', ao.Name AS 'EndpointAssessorName', a.ReservationId, - a.OriginalStartDate + a.OriginalStartDate, + a.MadeRedundant FROM Apprenticeship a INNER JOIN diff --git a/src/SFA.DAS.Commitments.Domain/Entities/Apprenticeship.cs b/src/SFA.DAS.Commitments.Domain/Entities/Apprenticeship.cs index 3793646576..5fc8182b4b 100644 --- a/src/SFA.DAS.Commitments.Domain/Entities/Apprenticeship.cs +++ b/src/SFA.DAS.Commitments.Domain/Entities/Apprenticeship.cs @@ -59,6 +59,7 @@ public Apprenticeship() public DateTime? OriginalStartDate { get; set; } public long? ContinuationOfId { get; set; } public List DataLocks { get; set; } + public bool? MadeRedundant { get; set; } public Apprenticeship Clone() { From 6fcfbfd09f755ef3f6c68ad64f84f2ddc6aab562 Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Tue, 14 Jul 2020 16:54:40 +0100 Subject: [PATCH 03/13] CON-2087-add column --- src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql b/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql index e5dd5346b7..846f99670d 100644 --- a/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql +++ b/src/SFA.DAS.Commitments.Database/Tables/Apprenticeship.sql @@ -34,9 +34,9 @@ [IsApproved] AS (CASE WHEN [PaymentStatus] > (0) THEN CONVERT([BIT], (1)) ELSE CONVERT([BIT], (0)) END) PERSISTED, [CompletionDate] DATETIME NULL, [ContinuationOfId] BIGINT NULL, + [MadeRedundant] BIT NULL, [OriginalStartDate] DATETIME NULL - CONSTRAINT [FK_Apprenticeship_Commitment] FOREIGN KEY ([CommitmentId]) REFERENCES [Commitment]([Id]), - [MadeRedundant] BIT NULL, + CONSTRAINT [FK_Apprenticeship_Commitment] FOREIGN KEY ([CommitmentId]) REFERENCES [Commitment]([Id]), CONSTRAINT [FK_Apprenticeship_AssessmentOrganisation] FOREIGN KEY ([EPAOrgId]) REFERENCES [AssessmentOrganisation]([EPAOrgId]) ) GO From ad429a6fe94972fca37619adb9ed1683b4a81f9f Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Tue, 14 Jul 2020 22:36:43 +0100 Subject: [PATCH 04/13] CON-2087-add new field value --- .../Apprenticeship/ApprenticeshipSubmission.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs b/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs index a511674f36..238efb2036 100644 --- a/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs +++ b/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs @@ -10,5 +10,6 @@ public sealed class ApprenticeshipSubmission public DateTime DateOfChange { get; set; } public string UserId { get; set; } public LastUpdateInfo LastUpdatedByInfo { get; set; } + public bool MadeRedundant { get; set; } } } \ No newline at end of file From a1a1de79920b6efeeb295432571eec9b6ce9a751 Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Wed, 15 Jul 2020 09:52:11 +0100 Subject: [PATCH 05/13] CON-2087-make field nullable --- .../Apprenticeship/ApprenticeshipSubmission.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs b/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs index 238efb2036..3c59833946 100644 --- a/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs +++ b/src/SFA.DAS.Commitments.Api.Types/Apprenticeship/ApprenticeshipSubmission.cs @@ -10,6 +10,6 @@ public sealed class ApprenticeshipSubmission public DateTime DateOfChange { get; set; } public string UserId { get; set; } public LastUpdateInfo LastUpdatedByInfo { get; set; } - public bool MadeRedundant { get; set; } + public bool? MadeRedundant { get; set; } } } \ No newline at end of file From 6ccb0b38d330a5b95d0e35a1a4f3ea3bb5ee8c00 Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Wed, 15 Jul 2020 18:56:21 +0100 Subject: [PATCH 06/13] CON-2087-save redundant values. --- .../Orchestrators/EmployerOrchestrator.cs | 4 +++- .../WhenStoppingAnApprenticeship.cs | 1 - .../ApprenticeshipStatusChangeCommand.cs | 1 - .../StopApprenticeshipCommand.cs | 1 + .../StopApprenticeshipCommandHandler.cs | 11 ++++------- .../Entities/Apprenticeship.cs | 1 + 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs b/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs index 6e03ce5219..eaaf7a24c5 100644 --- a/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs +++ b/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs @@ -366,6 +366,7 @@ await _mediator.SendAsync(new UpdateCommitmentAgreementCommand public async Task PatchApprenticeship(long accountId, long apprenticeshipId, Apprenticeship.ApprenticeshipSubmission apprenticeshipSubmission) { + _logger.Trace($"Updating payment status to {apprenticeshipSubmission.PaymentStatus} for apprenticeship {apprenticeshipId} for employer account {accountId}", accountId: accountId, apprenticeshipId: apprenticeshipId); switch (apprenticeshipSubmission.PaymentStatus) @@ -394,7 +395,8 @@ await _mediator.SendAsync(new StopApprenticeshipCommand ApprenticeshipId = apprenticeshipId, DateOfChange = apprenticeshipSubmission.DateOfChange, UserId = apprenticeshipSubmission.UserId, - UserName = apprenticeshipSubmission.LastUpdatedByInfo?.Name + UserName = apprenticeshipSubmission.LastUpdatedByInfo?.Name, + MadeRedundant = apprenticeshipSubmission.MadeRedundant }); } diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnApprenticeship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnApprenticeship.cs index 9ac9ab925c..e88f0c6425 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnApprenticeship.cs @@ -45,7 +45,6 @@ public virtual void SetUp() MockCommitmentsLogger.Object, MockHistoryRepository.Object, MockDataLockRepository.Object, - MockAcademicYearValidator.Object, MockV2EventsPublisher.Object); } } diff --git a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/ApprenticeshipStatusChangeCommand.cs b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/ApprenticeshipStatusChangeCommand.cs index 439f8c4c78..eb93c5ba90 100644 --- a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/ApprenticeshipStatusChangeCommand.cs +++ b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/ApprenticeshipStatusChangeCommand.cs @@ -8,7 +8,6 @@ public abstract class ApprenticeshipStatusChangeCommand : IAsyncRequest { public long AccountId { get; set; } public long ApprenticeshipId { get; set; } - public Caller Caller { get; set; } public DateTime DateOfChange { get; set; } public string UserId { get; set; } diff --git a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommand.cs b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommand.cs index fe36a56ba6..cc7d58488f 100644 --- a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommand.cs +++ b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommand.cs @@ -2,5 +2,6 @@ { public sealed class StopApprenticeshipCommand : ApprenticeshipStatusChangeCommand { + public bool? MadeRedundant { get; set; } } } \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs index 5556a2590b..a5c90c66ec 100644 --- a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs +++ b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using SFA.DAS.Commitments.Application.Interfaces; using SFA.DAS.Commitments.Application.Services; -using SFA.DAS.Commitments.Domain.Entities.AcademicYear; using SFA.DAS.Commitments.Domain.Entities.DataLock; using SFA.DAS.Commitments.Domain.Entities.History; @@ -26,7 +25,6 @@ public sealed class StopApprenticeshipCommandHandler : AsyncRequestHandler DataLocks { get; set; } + public bool? MadeRedundant { get; set; } public Apprenticeship Clone() { From 9ac3cf4a368ff4a1d536bc905f6f0161071d2bed Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Mon, 20 Jul 2020 10:40:08 +0100 Subject: [PATCH 07/13] CON-2087-save value in db. --- .../StopApprenticeshipCommandHandler.cs | 10 +++++----- .../Data/IApprenticeshipRepository.cs | 2 +- .../Data/ApprenticeshipRepository.cs | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs index a5c90c66ec..5ec1f718a9 100644 --- a/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs +++ b/src/SFA.DAS.Commitments.Application/Commands/UpdateApprenticeshipStatus/StopApprenticeshipCommandHandler.cs @@ -98,7 +98,7 @@ private async Task SaveChange(StopApprenticeshipCommand command, Commitment comm apprenticeship.StopDate = command.DateOfChange; apprenticeship.MadeRedundant = command.MadeRedundant; - await _apprenticeshipRepository.StopApprenticeship(commitment.Id, command.ApprenticeshipId, command.DateOfChange); + await _apprenticeshipRepository.StopApprenticeship(commitment.Id, command.ApprenticeshipId, command.DateOfChange, command.MadeRedundant); if (command.DateOfChange == apprenticeship.StartDate) { @@ -108,7 +108,7 @@ private async Task SaveChange(StopApprenticeshipCommand command, Commitment comm { await ResolveAnyTriagedCourseDataLocks(command.ApprenticeshipId); } - + await historyService.Save(); } @@ -146,7 +146,7 @@ private bool IsCourseChangeError(DataLockErrorCode errorCode) private void ValidateChangeDateForStop(DateTime dateOfChange, Apprenticeship apprenticeship) { if (apprenticeship == null) throw new ArgumentException(nameof(apprenticeship)); - + if (apprenticeship.IsWaitingToStart(_currentDate)) { if (dateOfChange.Date != apprenticeship.StartDate.Value.Date) @@ -157,8 +157,8 @@ private void ValidateChangeDateForStop(DateTime dateOfChange, Apprenticeship app if (dateOfChange.Date > _currentDate.Now.Date) throw new ValidationException("Invalid Date of Change. Date cannot be in the future."); - if ( dateOfChange.Date < apprenticeship.StartDate.Value.Date) - throw new ValidationException("Invalid Date of Change. Date cannot be before the training start date."); + if (dateOfChange.Date < apprenticeship.StartDate.Value.Date) + throw new ValidationException("Invalid Date of Change. Date cannot be before the training start date."); } } diff --git a/src/SFA.DAS.Commitments.Domain/Data/IApprenticeshipRepository.cs b/src/SFA.DAS.Commitments.Domain/Data/IApprenticeshipRepository.cs index 05b30c4643..9f72c6cf28 100644 --- a/src/SFA.DAS.Commitments.Domain/Data/IApprenticeshipRepository.cs +++ b/src/SFA.DAS.Commitments.Domain/Data/IApprenticeshipRepository.cs @@ -9,7 +9,7 @@ public interface IApprenticeshipRepository { Task UpdateApprenticeship(Apprenticeship apprenticeship, Caller caller); - Task StopApprenticeship(long commitmentId, long apprenticeshipId, DateTime dateOfChange); + Task StopApprenticeship(long commitmentId, long apprenticeshipId, DateTime dateOfChange, bool? madeRedundant); Task ResumeApprenticeship(long commitmentId, long apprenticeshipId); diff --git a/src/SFA.DAS.Commitments.Infrastructure/Data/ApprenticeshipRepository.cs b/src/SFA.DAS.Commitments.Infrastructure/Data/ApprenticeshipRepository.cs index ef3444d034..231a3245cd 100644 --- a/src/SFA.DAS.Commitments.Infrastructure/Data/ApprenticeshipRepository.cs +++ b/src/SFA.DAS.Commitments.Infrastructure/Data/ApprenticeshipRepository.cs @@ -44,7 +44,7 @@ await WithTransaction(async (connection, trans) => }); } - public async Task StopApprenticeship(long commitmentId, long apprenticeshipId, DateTime dateOfChange) + public async Task StopApprenticeship(long commitmentId, long apprenticeshipId, DateTime dateOfChange, bool? madeRedundant) { _logger.Debug($"Stopping apprenticeship {apprenticeshipId} for commitment {commitmentId}", commitmentId: commitmentId, apprenticeshipId: apprenticeshipId); @@ -54,10 +54,13 @@ await WithTransaction(async (conn, tran) => parameters.Add("@id", apprenticeshipId, DbType.Int64); parameters.Add("@paymentStatus", PaymentStatus.Withdrawn, DbType.Int16); parameters.Add("@stopDate", dateOfChange, DbType.Date); + parameters.Add("@madeRedundant", madeRedundant, DbType.Byte); var returnCode = await conn.ExecuteAsync( sql: - "UPDATE [dbo].[Apprenticeship] SET PaymentStatus = @paymentStatus, StopDate = @stopDate " + + "UPDATE [dbo].[Apprenticeship] SET PaymentStatus = @paymentStatus, " + + "StopDate = @stopDate, " + + "MadeRedundant = @madeRedundant " + "WHERE PaymentStatus != 4 AND Id = @id;", transaction: tran, param: parameters, From 3f6dc78ca03f7087b9de0f2061ccb5b6a4075db0 Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Mon, 20 Jul 2020 13:36:31 +0100 Subject: [PATCH 08/13] CON-2087-fis failing build --- .../WhenStoppingAnAwaitingApprenticeship.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs index ed33ed2e4a..0be0334b51 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs @@ -11,7 +11,6 @@ using SFA.DAS.Commitments.Application.Exceptions; using SFA.DAS.Commitments.Domain; using SFA.DAS.Commitments.Domain.Entities; -using SFA.DAS.Commitments.Domain.Entities.AcademicYear; using SFA.DAS.Commitments.Domain.Entities.DataLock; using SFA.DAS.Commitments.Domain.Entities.History; @@ -168,7 +167,7 @@ public async Task ThenShouldCallTheRepositoryToUpdateTheStatus() MockApprenticeshipRespository.Verify(x => x.StopApprenticeship( It.Is(a => a == 123L), It.Is(a => a == ExampleValidRequest.ApprenticeshipId), - It.Is(a => a == ExampleValidRequest.DateOfChange))); + It.Is(a => a == ExampleValidRequest.DateOfChange),It.IsAny())); } [Test] From c5a87abfb50969a4ff6cd57c42c10e58d0fc0c76 Mon Sep 17 00:00:00 2001 From: Shoma Gujjar Date: Tue, 21 Jul 2020 09:50:25 +0100 Subject: [PATCH 09/13] CON-2087-fix build --- .../WhenStoppingAStartedApprenticeship.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAStartedApprenticeship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAStartedApprenticeship.cs index 1ed765474d..ae16c680a5 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAStartedApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAStartedApprenticeship.cs @@ -11,7 +11,6 @@ using SFA.DAS.Commitments.Application.Exceptions; using SFA.DAS.Commitments.Domain; using SFA.DAS.Commitments.Domain.Entities; -using SFA.DAS.Commitments.Domain.Entities.AcademicYear; using SFA.DAS.Commitments.Domain.Entities.DataLock; using SFA.DAS.Commitments.Domain.Entities.History; @@ -225,7 +224,21 @@ public async Task ThenShouldCallTheRepositoryToUpdateTheStatus() MockApprenticeshipRespository.Verify(x => x.StopApprenticeship( It.Is(a => a == 123L), It.Is(a => a == ExampleValidRequest.ApprenticeshipId), - It.Is(a => a == ExampleValidRequest.DateOfChange))); + It.Is(a => a == ExampleValidRequest.DateOfChange),null)); + } + + [TestCase(true)] + [TestCase(false)] + public async Task ThenShouldCallTheRepositoryToUpdateTheStatus_WithRedundancyStatus(bool madeRedundant) + { + ExampleValidRequest.MadeRedundant = madeRedundant; + + await Handler.Handle(ExampleValidRequest); + + MockApprenticeshipRespository.Verify(x => x.StopApprenticeship( + It.Is(a => a == 123L), + It.Is(a => a == ExampleValidRequest.ApprenticeshipId), + It.Is(a => a == ExampleValidRequest.DateOfChange), madeRedundant)); } [Test] From 1ac3613b5c92d25d6765fd2a4b8110f277e1cd0e Mon Sep 17 00:00:00 2001 From: Shahzad Date: Fri, 24 Jul 2020 14:10:48 +0100 Subject: [PATCH 10/13] CON-2087-DB fixed broken test. --- .../WhenStoppingAnAwaitingApprenticeship.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs index 0be0334b51..f97b11695b 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs @@ -167,7 +167,7 @@ public async Task ThenShouldCallTheRepositoryToUpdateTheStatus() MockApprenticeshipRespository.Verify(x => x.StopApprenticeship( It.Is(a => a == 123L), It.Is(a => a == ExampleValidRequest.ApprenticeshipId), - It.Is(a => a == ExampleValidRequest.DateOfChange),It.IsAny())); + It.Is(a => a == ExampleValidRequest.DateOfChange),It.IsAny())); } [Test] From ae0580c1360dfaeaf1527f8690b0feb95844ecb1 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Mon, 27 Jul 2020 09:23:56 +0100 Subject: [PATCH 11/13] adding test. --- .../WhenGettingASingleApprenticeship.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs b/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs index f58294c4ca..8e6fd8a805 100644 --- a/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs @@ -101,6 +101,23 @@ public async Task ThenAccountLegalEntityPublicHashedIdIsMapped(GetApprenticeship Assert.AreEqual(accountLegalEntityPublicHashedId, result.Content.AccountLegalEntityPublicHashedId); } + [Test, AutoData] + public async Task ThenMadRedundantIsMapped(GetApprenticeshipResponse mediatorResponse) + { + _mockMediator.Setup(x => x.SendAsync(It.IsAny())).ReturnsAsync(mediatorResponse); + + // for this unit test we want a controller where the employerOrchestrator contains a real ApprenticeshipMapper + _employerOrchestrator = new EmployerOrchestrator(_mockMediator.Object, Mock.Of(), new FacetMapper(Mock.Of()), new ApprenticeshipFilterService(new FacetMapper(Mock.Of())), + new ApprenticeshipMapper(), _commitmentMapper.Object, Mock.Of(), Mock.Of()); + + _controller = new EmployerController(_employerOrchestrator, _apprenticeshipsOrchestrator); + + var result = await _controller.GetApprenticeship(TestProviderId, TestApprenticeshipId) as OkNegotiatedContentResult; + + result.Content.Should().NotBeNull(); + Assert.AreEqual(mediatorResponse.Data.MadeRedundant, result.Content.MadeRedundant); + } + [Test] public async Task ThenTheMediatorIsCalledWithTheCommitmentIdApprenticeshipIdProviderId() { From c731f2eac3240ca8789eee42cc454adb49e3c59f Mon Sep 17 00:00:00 2001 From: Shahzad Date: Mon, 27 Jul 2020 10:03:08 +0100 Subject: [PATCH 12/13] code review changes. --- .../Orchestrators/EmployerOrchestrator.cs | 1 - .../WhenStoppingAnAwaitingApprenticeship.cs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs b/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs index eaaf7a24c5..fb40d63540 100644 --- a/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs +++ b/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs @@ -366,7 +366,6 @@ await _mediator.SendAsync(new UpdateCommitmentAgreementCommand public async Task PatchApprenticeship(long accountId, long apprenticeshipId, Apprenticeship.ApprenticeshipSubmission apprenticeshipSubmission) { - _logger.Trace($"Updating payment status to {apprenticeshipSubmission.PaymentStatus} for apprenticeship {apprenticeshipId} for employer account {accountId}", accountId: accountId, apprenticeshipId: apprenticeshipId); switch (apprenticeshipSubmission.PaymentStatus) diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs index f97b11695b..c0f1bb759d 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/UpdateApprenticeshipStatus/WhenStoppingAnAwaitingApprenticeship.cs @@ -167,7 +167,8 @@ public async Task ThenShouldCallTheRepositoryToUpdateTheStatus() MockApprenticeshipRespository.Verify(x => x.StopApprenticeship( It.Is(a => a == 123L), It.Is(a => a == ExampleValidRequest.ApprenticeshipId), - It.Is(a => a == ExampleValidRequest.DateOfChange),It.IsAny())); + It.Is(a => a == ExampleValidRequest.DateOfChange), + It.IsAny())); } [Test] From cc91bd30661562844c3b5990089dd40cefeb8ee4 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Mon, 27 Jul 2020 10:06:20 +0100 Subject: [PATCH 13/13] typo fix. --- .../EmployerControllerTests/WhenGettingASingleApprenticeship.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs b/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs index 8e6fd8a805..262ba0e6c4 100644 --- a/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs +++ b/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenGettingASingleApprenticeship.cs @@ -102,7 +102,7 @@ public async Task ThenAccountLegalEntityPublicHashedIdIsMapped(GetApprenticeship } [Test, AutoData] - public async Task ThenMadRedundantIsMapped(GetApprenticeshipResponse mediatorResponse) + public async Task ThenMadeRedundantIsMapped(GetApprenticeshipResponse mediatorResponse) { _mockMediator.Setup(x => x.SendAsync(It.IsAny())).ReturnsAsync(mediatorResponse);