public void Then_the_minimum_agreement_version_is_set(Phase phase, int year, int month, int day, int minimumAgreementVersion)
        {
            // Arrange
            var plannedStartDate = new DateTime(year, month, day);
            // Act
            var agreementVersion = AgreementVersion.Create(phase, plannedStartDate);

            // Assert
            agreementVersion.MinimumRequiredVersion.Should().Be(minimumAgreementVersion);
        }
        public void Then_the_minimum_agreement_isnt_updated_for_phase2()
        {
            var agreementVersion = new AgreementVersion(6);
            var newStartDate     = new DateTime(2020, 8, 1);

            // Act
            var newAgreementVersion = agreementVersion.ChangedStartDate(Phase.Phase2, newStartDate);

            // Assert
            newAgreementVersion.Should().Be(agreementVersion);
        }
        public void Then_the_minimum_agreement_version_is_set(
            int existingMinimumAgreementVersion,
            int newYear, int newMonth, int newDay,
            int minimumAgreementVersion)
        {
            // Arrange
            var agreementVersion = new AgreementVersion(existingMinimumAgreementVersion);
            var newStartDate     = new DateTime(newYear, newMonth, newDay);

            // Act
            var newAgreementVersion = agreementVersion.ChangedStartDate(Phase.Phase1, newStartDate);

            // Assert
            newAgreementVersion.MinimumRequiredVersion.Should().Be(minimumAgreementVersion);
        }
        public async Task Handle(CreateIncentiveCommand command, CancellationToken cancellationToken = default)
        {
            var existing = await _apprenticeshipIncentiveDomainRepository.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId);

            if (existing != null)
            {
                return;
            }

            var incentive = _apprenticeshipIncentiveFactory.CreateNew(
                Guid.NewGuid(),
                command.IncentiveApplicationApprenticeshipId,
                new Account(command.AccountId, command.AccountLegalEntityId),
                new Apprenticeship(
                    command.ApprenticeshipId,
                    command.FirstName,
                    command.LastName,
                    command.DateOfBirth,
                    command.Uln,
                    command.ApprenticeshipEmployerTypeOnApproval,
                    command.CourseName,
                    command.EmploymentStartDate
                    ),
                command.PlannedStartDate,
                command.SubmittedDate,
                command.SubmittedByEmail,
                AgreementVersion.Create(command.Phase, command.PlannedStartDate),
                new IncentivePhase(command.Phase)
                );

            if (command.UKPRN.HasValue)
            {
                incentive.Apprenticeship.SetProvider(new Provider(command.UKPRN.Value));
            }

            await _apprenticeshipIncentiveDomainRepository.Save(incentive);
        }
 internal static ApprenticeshipIncentive New(Guid id, Guid applicationApprenticeshipId, Account account, Apprenticeship apprenticeship, DateTime plannedStartDate, DateTime submittedDate, string submittedByEmail, AgreementVersion agreementVersion, IncentivePhase phase)
 {
     return(new ApprenticeshipIncentive(
                id,
                new ApprenticeshipIncentiveModel
     {
         Id = id,
         ApplicationApprenticeshipId = applicationApprenticeshipId,
         Account = account,
         Apprenticeship = apprenticeship,
         StartDate = plannedStartDate,
         PausePayments = false,
         SubmittedDate = submittedDate,
         SubmittedByEmail = submittedByEmail,
         Status = IncentiveStatus.Active,
         MinimumAgreementVersion = agreementVersion,
         Phase = phase
     }, true));
 }
 public ApprenticeshipIncentive CreateNew(Guid id, Guid applicationApprenticeshipId, Account account, Apprenticeship apprenticeship, DateTime plannedStartDate, DateTime submittedDate, string submittedByEmail, AgreementVersion agreementVersion, IncentivePhase phase)
 {
     return(ApprenticeshipIncentive.New(id, applicationApprenticeshipId, account, apprenticeship, plannedStartDate, submittedDate, submittedByEmail, agreementVersion, phase));
 }
        internal static ApprenticeshipIncentiveModel Map(this ApprenticeshipIncentive entity, IEnumerable <CollectionCalendarPeriod> collectionPeriods)
        {
            var apprenticeship = new Apprenticeship(
                entity.ApprenticeshipId,
                entity.FirstName,
                entity.LastName,
                entity.DateOfBirth,
                entity.ULN,
                entity.EmployerType,
                entity.CourseName,
                entity.EmploymentStartDate
                );

            if (entity.UKPRN.HasValue)
            {
                apprenticeship.SetProvider(new Provider(entity.UKPRN.Value));
            }

            return(new ApprenticeshipIncentiveModel
            {
                Id = entity.Id,
                Account = new Domain.ApprenticeshipIncentives.ValueTypes.Account(entity.AccountId, entity.AccountLegalEntityId),
                Apprenticeship = apprenticeship,
                StartDate = entity.StartDate,
                ApplicationApprenticeshipId = entity.IncentiveApplicationApprenticeshipId,
                PendingPaymentModels = entity.PendingPayments.Map(collectionPeriods),
                PaymentModels = entity.Payments.Map(),
                ClawbackPaymentModels = entity.ClawbackPayments.Map(),
                RefreshedLearnerForEarnings = entity.RefreshedLearnerForEarnings,
                HasPossibleChangeOfCircumstances = entity.HasPossibleChangeOfCircumstances,
                PausePayments = entity.PausePayments,
                SubmittedDate = entity.SubmittedDate,
                SubmittedByEmail = entity.SubmittedByEmail,
                Status = entity.Status,
                BreakInLearnings = entity.BreakInLearnings.Map(),
                MinimumAgreementVersion = entity.MinimumAgreementVersion.HasValue ? new AgreementVersion(entity.MinimumAgreementVersion.Value) : AgreementVersion.Create(entity.Phase, entity.StartDate),
                Phase = new Domain.ValueObjects.IncentivePhase(entity.Phase)
            });
        }