public void ThenTheFollowingCappingWillApplyToThePriceEpisodes(Table table)
        {
            for (var rowIndex = 0; rowIndex < table.RowCount; rowIndex++)
            {
                var provider = table.Rows[rowIndex].Contains("provider")
                    ? StepDefinitionsContext.GetProvider(table.Rows[rowIndex].Value <string>("provider"))
                    : StepDefinitionsContext.GetDefaultProvider();

                var priceEpisode                = provider.GetPriceEpisode(table.Rows[rowIndex].Value <string>("price episode"));
                var expectedNegotiatedPrice     = table.Rows[rowIndex].Value <decimal>("negotiated price");
                var expectedPreviousFunding     = table.Rows[rowIndex].Value <decimal>("previous funding paid");
                var expectedPriceAboveCap       = table.Rows[rowIndex].Value <decimal>("price above cap");
                var expectedPriceForSfaPayments = table.Rows[rowIndex].Value <decimal>("effective price for SFA payments");

                var actualPriceEpisode = LearnerDataHelper.GetOpaApprenticeshipPriceEpisode(provider.Ukprn, priceEpisode.Id, EnvironmentVariables);

                Assert.AreEqual(expectedNegotiatedPrice, actualPriceEpisode.PriceEpisodeTotalTNPPrice, $"Expecting a total negotiated price of {expectedNegotiatedPrice} for pride episode {priceEpisode.DataLockMatchKey} but found {actualPriceEpisode.PriceEpisodeTotalTNPPrice}.");
                Assert.AreEqual(expectedPreviousFunding, actualPriceEpisode.PriceEpisodePreviousEarnings, $"Expecting previous funding of {expectedPreviousFunding} for pride episode {priceEpisode.DataLockMatchKey} but found {actualPriceEpisode.PriceEpisodePreviousEarnings}.");
                Assert.AreEqual(expectedPriceAboveCap, actualPriceEpisode.PriceEpisodeUpperLimitAdjustment, $"Expecting a price above cap of {expectedPriceAboveCap} for pride episode {priceEpisode.DataLockMatchKey} but found {actualPriceEpisode.PriceEpisodeUpperLimitAdjustment}.");
                Assert.AreEqual(expectedPriceForSfaPayments, actualPriceEpisode.PriceEpisodeUpperBandLimit, $"Expecting an effective price for SFA payments of {expectedPriceForSfaPayments} for pride episode {priceEpisode.DataLockMatchKey} but found {actualPriceEpisode.PriceEpisodeUpperBandLimit}.");
            }
        }
Exemple #2
0
        protected void SetupContexLearners(Table table)
        {
            if (table.Header.Contains("Employment Status") && StepDefinitionsContext.ReferenceDataContext.EmploymentStatuses == null)
            {
                PopulateEmploymentStatuses(table);
            }

            for (var rowIndex = 0; rowIndex < table.RowCount; rowIndex++)
            {
                var provider = table.ContainsColumn("Provider")
                    ? table.Rows[rowIndex]["Provider"]
                    : "provider";

                if (table.Header.Contains("LearnDelFAM") && !string.IsNullOrEmpty(table.Rows[rowIndex]["LearnDelFAM"]))
                {
                    var famValue = table.Rows[rowIndex]["LearnDelFAM"];
                    var famCode  = new LearningDeliveryFam
                    {
                        FamType = famValue.Substring(0, 3),
                        FamCode = int.Parse(famValue.Substring(3))
                    };

                    StepDefinitionsContext.ReferenceDataContext.AddLearningDeliveryFam(famCode);
                }

                var learningDelivery = new LearningDelivery
                {
                    LearningDeliveryFams = StepDefinitionsContext.ReferenceDataContext.LearningDeliveryFams,
                    LearnerType          = table.Header.Contains("learner type")
                                    ? GetLearnerType(table.Rows[rowIndex]["learner type"])
                                    : LearnerType.ProgrammeOnlyDas,
                    StartDate      = DateTime.Parse(table.Rows[rowIndex]["start date"]),
                    PlannedEndDate = table.Header.Contains("planned end date") ?
                                     DateTime.Parse(table.Rows[rowIndex]["planned end date"]) :
                                     DateTime.Parse(table.Rows[rowIndex]["start date"]).AddMonths(12),
                    ActualEndDate =
                        !table.Header.Contains("actual end date") ||
                        string.IsNullOrWhiteSpace(table.Rows[rowIndex]["actual end date"])
                               ? null
                               : (DateTime?)DateTime.Parse(table.Rows[rowIndex]["actual end date"]),
                    CompletionStatus = table.Header.Contains("completion status") ?
                                       IlrTranslator.TranslateCompletionStatus(table.Rows[rowIndex]["completion status"]) :
                                       CompletionStatus.Continuing,
                    FrameworkCode = table.Rows[rowIndex].Value <int>("framework code") > 0 ? table.Rows[rowIndex].Value <int>("framework code") : IlrBuilder.Defaults.FrameworkCode,
                    ProgrammeType = table.Rows[rowIndex].Value <int>("programme type") > 0 ? table.Rows[rowIndex].Value <int>("programme type") : IlrBuilder.Defaults.ProgrammeType,
                    PathwayCode   = table.Rows[rowIndex].Value <int>("pathway code") > 0 ? table.Rows[rowIndex].Value <int>("pathway code") : IlrBuilder.Defaults.PathwayCode,
                    Type          = table.Rows[rowIndex].Contains("aim type")
                        ? GetAimType(table.Rows[rowIndex].Value <string>("aim type"))
                        : Enums.AimType.Programme
                };

                var standardCode = table.Rows[rowIndex].Value <int>("standard code") > 0 ? table.Rows[rowIndex].Value <int>("standard code")  : IlrBuilder.Defaults.StandardCode;
                learningDelivery.StandardCode = learningDelivery.FrameworkCode > 0 &&
                                                learningDelivery.PathwayCode > 0 &&
                                                learningDelivery.ProgrammeType > 0 ? 0 : standardCode;

                var priceEpisodes = SetupPriceEpisodes(table, rowIndex, learningDelivery.StandardCode);
                learningDelivery.PriceEpisodes = priceEpisodes.ToArray();

                Learner learner = null;
                if (table.Rows[rowIndex].ContainsKey("ULN"))
                {
                    var learners = StepDefinitionsContext.GetProvider(provider).Learners;

                    if (learners != null)
                    {
                        learner = learners.SingleOrDefault(x => x.Name == table.Rows[rowIndex]["ULN"]);
                    }
                }

                if (learner == null)
                {
                    learner      = new Learner();
                    learner.Name = table.Rows[rowIndex].ContainsKey("ULN") ? table.Rows[rowIndex]["ULN"] : string.Empty;

                    if (table.Rows[rowIndex].ContainsKey("ULN"))
                    {
                        learner.Uln = GetUln(learner.Name, table.Rows[rowIndex]["ULN"]);
                    }
                    else
                    {
                        learner.Uln = GetUln(learner.Name, string.Empty);
                    }

                    learner.LearnRefNumber = $"{StepDefinitionsContext.GetProvider(provider).Ukprn}-{rowIndex+1}";
                    learner.DateOfBirth    = GetDateOfBirth(learningDelivery.LearnerType, learningDelivery.StartDate);

                    learner.EmploymentStatuses = StepDefinitionsContext.ReferenceDataContext.EmploymentStatuses;


                    StepDefinitionsContext.AddProviderLearner(provider, learner);
                }

                learner.LearningDeliveries.Add(learningDelivery);
            }
        }