Beispiel #1
0
        public async Task <List <PriceEpisodeStatusChange> > GetPriceEpisodeChanges(long jobId, long ukprn, short currentAcademicYear)
        {
            var priceEpisodeReplacements     = new List <CurrentPriceEpisode>();
            var allPriceEpisodeStatusChanges = new List <PriceEpisodeStatusChange>();

            var dataLockEvents       = (await GetDataLocks(jobId, ukprn)).ToList();
            var currentPriceEpisodes = await currentPriceEpisodesStore.GetCurrentPriceEpisodes(ukprn);

            var learnerUlns = dataLockEvents.Select(d => d.Learner.Uln).Distinct();

            foreach (var learnerUln in learnerUlns)
            {
                var learnerDataLocks            = dataLockEvents.Where(x => x.Learner.Uln == learnerUln).ToList();
                var leanerPriceEpisodes         = currentPriceEpisodes.Where(x => x.Uln == learnerUln).ToList();
                var changes                     = CalculatePriceEpisodeStatus(learnerDataLocks, leanerPriceEpisodes);
                var previousPriceEpisodesStatus = GetPreviousPriceEpisodeStatus(leanerPriceEpisodes);

                var priceEpisodeStatusChanges = await CreateStatusChangedEvents(learnerDataLocks, changes, previousPriceEpisodesStatus, currentAcademicYear);

                var learnerPriceEpisodeReplacements = CreateLearnerCurrentPriceEpisodesReplacement(jobId, ukprn, learnerUln, priceEpisodeStatusChanges);
                priceEpisodeReplacements.AddRange(learnerPriceEpisodeReplacements);

                allPriceEpisodeStatusChanges.AddRange(priceEpisodeStatusChanges);
            }

            await ReplaceCurrentPriceEpisodes(jobId, ukprn, priceEpisodeReplacements);
            await RemoveReceivedDataLockEvents(jobId, ukprn);

            return(allPriceEpisodeStatusChanges);
        }
        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();
        }