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 OnprogPayableDataLockEventWithNoApprenticeshipIdShouldNotBeStored( IReceivedDataLockEventStore receivedDataLockEventStore, PayableEarningEvent payableEarningEvent, EarningPeriod period, ApprenticeshipModel apprenticeship, List <DataLockFailure> dataLockFailures, ManageReceivedDataLockEvent manageReceivedDataLockEvent) { period.ApprenticeshipId = default(long?); period.AccountId = default(long?); payableEarningEvent.OnProgrammeEarnings = new List <OnProgrammeEarning> { new OnProgrammeEarning { Periods = (new List <EarningPeriod> { period }).AsReadOnly(), Type = OnProgrammeEarningType.Learning, CensusDate = DateTime.UtcNow } }; await manageReceivedDataLockEvent.ProcessDataLockEvent(payableEarningEvent); var result = (await receivedDataLockEventStore .GetDataLocks(payableEarningEvent.JobId, payableEarningEvent.Ukprn)).ToList(); result.Should().BeEmpty(); }
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 PriceEpisodesReceivedService( ICurrentPriceEpisodeForJobStore store, IReceivedDataLockEventStore receivedEventStore, PriceEpisodeStatusChangeBuilder statusChangeBuilder) { currentPriceEpisodesStore = store; this.receivedEventStore = receivedEventStore; this.statusChangeBuilder = statusChangeBuilder; }
public async Task AddDataLockEventToContext(IReceivedDataLockEventStore receivedContext) { await receivedContext.Add(new ReceivedDataLockEvent { JobId = earning.JobId, Ukprn = earning.Ukprn, MessageType = earning.GetType().AssemblyQualifiedName, Message = JsonConvert.SerializeObject(earning), }); }
public async Task When_job_succeeded_removes_received_dataLock_events( IReceivedDataLockEventStore receivedContext, PriceEpisodesReceivedService sut, TestCaseData testCaseData) { testCaseData.CommonSetup(); await testCaseData.AddDataLockEventToContext(receivedContext); await sut.GetPriceEpisodeChanges(testCaseData.earning.JobId, testCaseData.earning.Ukprn, testCaseData.earning.CollectionYear); (await receivedContext.GetDataLocks(testCaseData.earning.JobId, testCaseData.earning.Ukprn)) .Should().BeEmpty(); }
public async Task StoreOnprogPayableDataLockEvents( IReceivedDataLockEventStore receivedDataLockEventStore, PayableEarningEvent payableEarningEvent, List <EarningPeriod> periods, ApprenticeshipModel apprenticeship, ManageReceivedDataLockEvent manageReceivedDataLockEvent) { CommonTestSetup(payableEarningEvent, periods, apprenticeship); await manageReceivedDataLockEvent.ProcessDataLockEvent(payableEarningEvent); var result = (await receivedDataLockEventStore .GetDataLocks(payableEarningEvent.JobId, payableEarningEvent.Ukprn)).ToList(); result.Should().NotBeNull(); result.Should().HaveCount(1); result[0].MessageType.Should().Be(typeof(PayableEarningEvent).AssemblyQualifiedName); result[0].Message.Should().Be(payableEarningEvent.ToJson()); }
public async Task When_job_succeeded_builds_approval_event_for_new_and_updated_price_episodes( ICurrentPriceEpisodeForJobStore currentContext, IReceivedDataLockEventStore receivedContext, TestCaseData testCaseData, PriceEpisode newPriceEpisode, EarningPeriod newPeriod, PriceEpisodesReceivedService sut) { // Given testCaseData.earning.PriceEpisodes.Add(newPriceEpisode); newPeriod.ApprenticeshipId = testCaseData.apprenticeship.Id; newPeriod.AccountId = testCaseData.apprenticeship.AccountId; newPeriod.PriceEpisodeIdentifier = newPriceEpisode.Identifier; testCaseData.earning.OnProgrammeEarnings[0].Periods = testCaseData.earning.OnProgrammeEarnings[0].Periods.Append(newPeriod).ToList().AsReadOnly(); await currentContext.Add(CreateCurrentPriceEpisodeFor(testCaseData.earning)); await testCaseData.AddDataLockEventToContext(receivedContext); // When var changeMessages = await sut.GetPriceEpisodeChanges(testCaseData.earning.JobId, testCaseData.earning.Ukprn, testCaseData.earning.CollectionYear); // Then changeMessages.Should().ContainEquivalentOf( new { DataLock = new { PriceEpisodeIdentifier = testCaseData.earning.PriceEpisodes[0].Identifier, Status = PriceEpisodeStatus.Updated, }, }); changeMessages.Should().ContainEquivalentOf( new { DataLock = new { PriceEpisodeIdentifier = newPriceEpisode.Identifier, Status = PriceEpisodeStatus.New, }, }); }
public async Task StoreValidOnprogNonPayableDataLockEvents( IReceivedDataLockEventStore receivedDataLockEventStore, EarningFailedDataLockMatching nonPayableEarningEvent, List <EarningPeriod> periods, ApprenticeshipModel apprenticeship, List <DataLockFailure> dataLockFailures, ManageReceivedDataLockEvent manageReceivedDataLockEvent) { CommonTestSetup(nonPayableEarningEvent, periods, apprenticeship, dataLockFailures); await manageReceivedDataLockEvent.ProcessDataLockEvent(nonPayableEarningEvent); var result = (await receivedDataLockEventStore .GetDataLocks(nonPayableEarningEvent.JobId, nonPayableEarningEvent.Ukprn)).ToList(); result.Should().NotBeNull(); result.Should().HaveCount(1); result[0].MessageType.Should().Be(nonPayableEarningEvent.GetType().AssemblyQualifiedName); result[0].Message.Should().Be(nonPayableEarningEvent.ToJson()); }
public async Task When_job_succeeded_replaces_current_price_episodes( [Frozen] Mock <IApprenticeshipRepository> apprenticeshipRepo, ICurrentPriceEpisodeForJobStore currentContext, IReceivedDataLockEventStore receivedContext, TestCaseData testCaseData, PriceEpisodesReceivedService sut) { testCaseData.CommonSetup(); 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().BeEquivalentTo(expected, c => { c.Excluding(info => info.Id); c.Excluding(info => info.Message); return(c); }); results[0].Message.Should().NotBeNull(); }
public async Task When_job_succeeded_builds_approval_event_for_new_price_episode( IReceivedDataLockEventStore receivedContext, TestCaseData testCaseData, PriceEpisodesReceivedService sut) { testCaseData.CommonSetup(); await testCaseData.AddDataLockEventToContext(receivedContext); var changeMessages = await sut.GetPriceEpisodeChanges(testCaseData.earning.JobId, testCaseData.earning.Ukprn, testCaseData.earning.CollectionYear); changeMessages.Should().ContainEquivalentOf( new { DataLock = new { PriceEpisodeIdentifier = testCaseData.earning.PriceEpisodes.First().Identifier, Status = PriceEpisodeStatus.New, }, }); }
public async Task DataLockFunctionalSkillEventsShouldNotBeStored( IReceivedDataLockEventStore receivedDataLockEventStore, ManageReceivedDataLockEvent manageReceivedDataLockEvent, long jobId, long ukprn) { await manageReceivedDataLockEvent.ProcessDataLockEvent(new FunctionalSkillEarningFailedDataLockMatching { JobId = jobId, Ukprn = ukprn }); await manageReceivedDataLockEvent.ProcessDataLockEvent(new PayableFunctionalSkillEarningEvent { JobId = jobId, Ukprn = ukprn }); var result = await receivedDataLockEventStore.GetDataLocks(jobId, ukprn); result.Should().BeEmpty(); }
public ManageReceivedDataLockEvent(IReceivedDataLockEventStore receivedDataLockEventStore) { this.receivedDataLockEventStore = receivedDataLockEventStore; }