public void ScenariosThatDoNotCreateDlockErrors(string errorMessage, TransactionType transactionType, DateTime ilrDate, DateTime commitmentDate)
        {
            var validation = new DataLockValidationModel
            {
                PriceEpisode = new PriceEpisode
                {
                    Identifier    = PriceEpisodeIdentifier,
                    ActualEndDate = ilrDate,
                },
                EarningPeriod  = period,
                Apprenticeship = new ApprenticeshipModel
                {
                    Id     = 1,
                    Status = ApprenticeshipStatus.Stopped,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel
                        {
                            Id = 100,
                        },
                    },
                    StopDate = commitmentDate,
                },
                AcademicYear    = 1920,
                TransactionType = transactionType,
            };

            var validator = new CompletionStoppedValidator();
            var result    = validator.Validate(validation);

            result.DataLockErrorCode.Should().BeNull();
            result.ApprenticeshipPriceEpisodes.Should().HaveCount(1);
            result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(100);
        }
        public void ReturnsOnlyCommitmentsThatAreNotStopped(ApprenticeshipModel apprenticeshipA, ApprenticeshipModel apprenticeshipB, PriceEpisode priceEpisode)
        {
            priceEpisode.EffectiveTotalNegotiatedPriceStartDate = new DateTime(2018, 8, 1);
            priceEpisode.ActualEndDate = new DateTime(2020, 8, 30);

            apprenticeshipA.StopDate = new DateTime(2019, 8, 1);
            apprenticeshipA.Status   = ApprenticeshipStatus.Stopped;
            apprenticeshipA.ApprenticeshipPriceEpisodes[0].StartDate = new DateTime(2018, 8, 1);
            apprenticeshipA.ApprenticeshipPriceEpisodes[0].EndDate   = new DateTime(2019, 8, 30);

            apprenticeshipB.Status = ApprenticeshipStatus.Active;
            apprenticeshipB.ApprenticeshipPriceEpisodes[0].StartDate = new DateTime(2019, 8, 1);
            apprenticeshipB.ApprenticeshipPriceEpisodes[0].EndDate   = new DateTime(2020, 8, 30);

            var apprenticeships = new List <ApprenticeshipModel> {
                apprenticeshipA, apprenticeshipB
            };

            var validator = new CompletionStoppedValidator();
            var result    = validator.Validate(priceEpisode, apprenticeships, TransactionType.Completion);

            result.dataLockFailures.Should().BeEmpty();
            result.validApprenticeships.Should().NotBeNull();
            result.validApprenticeships.All(x => x.Id == apprenticeshipB.Id).Should().BeTrue();
        }
        public void ScenariosThatDoNotCreateDlockErrors(string errorMessage, TransactionType transactionType, DateTime ilrDate, DateTime commitmentDate)
        {
            var priceEpisode = new PriceEpisode
            {
                Identifier    = PriceEpisodeIdentifier,
                ActualEndDate = ilrDate,
            };
            var apprenticeships = new List <ApprenticeshipModel>
            {
                new ApprenticeshipModel
                {
                    Id     = 2,
                    Status = ApprenticeshipStatus.Stopped,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel
                        {
                            Id = 200,
                        }
                    },
                    StopDate = commitmentDate,
                },
            };

            var validator = new CompletionStoppedValidator();
            var result    = validator.Validate(priceEpisode, apprenticeships, transactionType);

            result.dataLockFailures.Should().BeEmpty();
            result.validApprenticeships[0].Id.Should().Be(2);
            result.validApprenticeships[0].ApprenticeshipPriceEpisodes[0].Id.Should().Be(200);
        }
        public void ScenariosThatCreateDlockErrors(string errorMessage, TransactionType transactionType, DateTime ilrDate, DateTime commitmentDate)
        {
            var priceEpisode = new PriceEpisode
            {
                Identifier    = PriceEpisodeIdentifier,
                ActualEndDate = ilrDate,
            };
            var apprenticeships = new List <ApprenticeshipModel>
            {
                new ApprenticeshipModel
                {
                    Id = 1,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel
                        {
                            Id = 100,
                        },
                        new ApprenticeshipPriceEpisodeModel
                        {
                            Id      = 200,
                            Removed = true
                        },
                    },
                    StopDate = commitmentDate, // Last day of 1819
                    Status   = ApprenticeshipStatus.Stopped,
                }
            };

            var validator = new CompletionStoppedValidator();
            var result    = validator.Validate(priceEpisode, apprenticeships, transactionType);

            result.validApprenticeships.Should().BeEmpty(errorMessage);
            result.dataLockFailures.Should().HaveCount(1);
            result.dataLockFailures[0].DataLockError.Should().Be(DataLockErrorCode.DLOCK_10);
            result.dataLockFailures[0].ApprenticeshipId.Should().Be(1);

            result.dataLockFailures[0].ApprenticeshipPriceEpisodeIds.Should().HaveCount(1);
            result.dataLockFailures[0].ApprenticeshipPriceEpisodeIds[0].Should().Be(100);
        }