public async Task When_job_succeeded_builds_approval_event_for_removed_price_episode( [Frozen] Mock <IApprenticeshipRepository> apprenticeshipRepo, ICurrentPriceEpisodeForJobStore currentContext, IReceivedDataLockEventStore receivedContext, TestCaseData testCaseData, PriceEpisodesReceivedService sut, CurrentPriceEpisode priceEpisode) { testCaseData.CommonSetup(); await testCaseData.AddDataLockEventToContext(receivedContext); priceEpisode.AssociateWith(testCaseData.earning); await currentContext.Add(priceEpisode); var changeMessages = await sut.GetPriceEpisodeChanges(testCaseData.earning.JobId, testCaseData.earning.Ukprn, testCaseData.earning.CollectionYear); changeMessages.Should().ContainEquivalentOf( new { DataLock = new { priceEpisode.PriceEpisodeIdentifier, Status = PriceEpisodeStatus.Removed, }, }); }
public async Task When_job_succeeded_builds_approval_event_for_new_and_removed_price_episodes( ICurrentPriceEpisodeForJobStore currentContext, IReceivedDataLockEventStore receivedContext, PriceEpisodesReceivedService sut, TestCaseData testCaseData, CurrentPriceEpisode removed) { testCaseData.CommonSetup(); await testCaseData.AddDataLockEventToContext(receivedContext); removed.AssociateWith(testCaseData.earning); await currentContext.Add(removed); var changeMessages = await sut.GetPriceEpisodeChanges(testCaseData.earning.JobId, testCaseData.earning.Ukprn, testCaseData.earning.CollectionYear); changeMessages.Should().ContainEquivalentOf( new { DataLock = new { PriceEpisodeIdentifier = testCaseData.earning.PriceEpisodes[0].Identifier, Status = PriceEpisodeStatus.New, }, }); changeMessages.Should().ContainEquivalentOf( new { DataLock = new { removed.PriceEpisodeIdentifier, Status = PriceEpisodeStatus.Removed, }, }); }
public async Task When_job_succeeded_removes_current_price_episode( [Frozen] Mock <IApprenticeshipRepository> apprenticeshipRepo, CurrentPriceEpisode previousPriceEpisode, ICurrentPriceEpisodeForJobStore currentContext, IReceivedDataLockEventStore receivedContext, TestCaseData testCaseData, PriceEpisodesReceivedService sut) { testCaseData.CommonSetup(); previousPriceEpisode.Ukprn = testCaseData.earning.Ukprn; await currentContext.Add(previousPriceEpisode); apprenticeshipRepo .Setup(x => x.Get(It.IsAny <List <long> >(), CancellationToken.None)) .Returns(Task.FromResult(new List <ApprenticeshipModel> { testCaseData.apprenticeship })); await testCaseData.AddDataLockEventToContext(receivedContext); await sut.GetPriceEpisodeChanges(testCaseData.earning.JobId, testCaseData.earning.Ukprn, testCaseData.earning.CollectionYear); var expected = testCaseData.earning.PriceEpisodes.Select(x => new CurrentPriceEpisode { JobId = testCaseData.earning.JobId, Ukprn = testCaseData.earning.Ukprn, Uln = testCaseData.earning.Learner.Uln, PriceEpisodeIdentifier = x.Identifier, AgreedPrice = x.AgreedPrice, MessageType = typeof(List <PriceEpisodeStatusChange>).AssemblyQualifiedName, Message = "[]" }); var results = (await currentContext .GetCurrentPriceEpisodes(testCaseData.earning.Ukprn)).ToList(); results.Should().NotContain(previousPriceEpisode); }
public static CurrentPriceEpisode AssociateWith(this CurrentPriceEpisode priceEpisode, DataLockEvent dlock) { priceEpisode.Uln = dlock.Learner.Uln; priceEpisode.Ukprn = dlock.Ukprn; priceEpisode.JobId = dlock.JobId + 1; priceEpisode.MessageType = typeof(List <PriceEpisodeStatusChange>).AssemblyQualifiedName; priceEpisode.Message = JsonConvert.SerializeObject( new List <PriceEpisodeStatusChange> { new PriceEpisodeStatusChange { DataLock = new LegacyDataLockEvent { PriceEpisodeIdentifier = priceEpisode.PriceEpisodeIdentifier, Status = PriceEpisodeStatus.New, UKPRN = dlock.Ukprn, ULN = dlock.Learner.Uln, AcademicYear = "1920" } } }); return(priceEpisode); }
public async Task Add(CurrentPriceEpisode priceEpisode) { await paymentsDataContext.CurrentPriceEpisodes.AddAsync(priceEpisode); await paymentsDataContext.SaveChangesAsync(); }