public async Task Then_the_incentive_is_not_pausePayments_when_the_incentive_has_paid_earnings() { //Arrange var incentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>()) .With(p => p.PaymentModels, new List <PaymentModel>()) .With(p => p.ClawbackPaymentModels, new List <ClawbackPaymentModel>()) .Create(); var pendingPaymentModel = _fixture.Build <PendingPaymentModel>() .With(p => p.ApprenticeshipIncentiveId, incentiveModel.Id) .Create(); incentiveModel.PendingPaymentModels.Add(pendingPaymentModel); var paymentModel = _fixture.Build <PaymentModel>() .With(p => p.ApprenticeshipIncentiveId, incentiveModel.Id) .With(p => p.PendingPaymentId, pendingPaymentModel.Id) .With(p => p.PaidDate, DateTime.Today.AddDays(-1)) .Create(); incentiveModel.PaymentModels.Add(paymentModel); var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.Id, incentiveModel); var command = new WithdrawCommand(incentive.Account.Id, incentive.Id); _mockIncentiveDomainRepository.Setup(x => x.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId)).ReturnsAsync(incentive); // Act await _sut.Handle(command); // Assert incentive.PausePayments.Should().BeFalse(); }
public async Task Then_the_existing_learner_is_returned() { // Arrange var incentiveModel = _fixture.Create <ApprenticeshipIncentiveModel>(); var payments = _fixture.Build <PendingPaymentModel>() .With(pp => pp.ApprenticeshipIncentiveId, incentiveModel.ApplicationApprenticeshipId) .Without(pp => pp.PaymentMadeDate) // null for "not paid" .CreateMany(5).ToArray(); payments[0].DueDate = DateTime.Parse("01/09/2020", new CultureInfo("en-GB")); payments[0].PaymentMadeDate = DateTime.Parse("30/09/2020", new CultureInfo("en-GB")); payments[1].DueDate = DateTime.Parse("01/10/2020", new CultureInfo("en-GB")); // next pending payment payments[2].DueDate = DateTime.Parse("01/11/2020", new CultureInfo("en-GB")); payments[3].DueDate = DateTime.Parse("01/12/2020", new CultureInfo("en-GB")); payments[4].DueDate = DateTime.Parse("01/01/2021", new CultureInfo("en-GB")); incentiveModel.PendingPaymentModels = payments; var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.ApplicationApprenticeshipId, incentiveModel); incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>()); var learner = _fixture.Create <LearnerModel>(); _learnerDataRepositoryMock.Setup(r => r.GetByApprenticeshipIncentiveId(incentive.Id)).ReturnsAsync(learner); // Act var result = await _sut.GetOrCreate(incentive); // Assert result.Id.Should().Be(learner.Id, "should return existing"); }
public async Task Then_a_new_learner_is_returned() { // Arrange var incentiveModel = _fixture.Create <ApprenticeshipIncentiveModel>(); var payments = _fixture.Build <PendingPaymentModel>() .With(pp => pp.ApprenticeshipIncentiveId, incentiveModel.ApplicationApprenticeshipId) .Without(pp => pp.PaymentMadeDate) // null for "not paid" .CreateMany(2).ToArray(); payments[0].DueDate = DateTime.Parse("01/09/2020", new CultureInfo("en-GB")); // next pending payment payments[1].DueDate = DateTime.Parse("01/10/2020", new CultureInfo("en-GB")); incentiveModel.PendingPaymentModels = payments; var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.ApplicationApprenticeshipId, incentiveModel); incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>()); _learnerDataRepositoryMock.Setup(r => r.GetByApprenticeshipIncentiveId(incentive.Id)).ReturnsAsync((LearnerModel)null); // Act var result = await _sut.GetOrCreate(incentive); // Assert result.Id.Should().NotBeEmpty("should set a new Id"); result.ApprenticeshipIncentiveId.Should().Be(incentive.Id); result.ApprenticeshipId.Should().Be(incentive.Apprenticeship.Id); result.SubmissionData.SubmissionFound.Should().Be(false); result.Ukprn.Should().Be(incentive.Apprenticeship.Provider.Ukprn); result.UniqueLearnerNumber.Should().Be(incentive.Apprenticeship.UniqueLearnerNumber); }
public void Arrange() { _sut = new ApprenticeshipIncentiveFactory(); _fixture = new Fixture(); _id = _fixture.Create <Guid>(); _model = _fixture.Create <ApprenticeshipIncentiveModel>(); }
public void Arrange() { var today = new DateTime(2021, 1, 30); _fixture = new Fixture(); _mockPaymentProfilesService = new Mock <IIncentivePaymentProfilesService>(); _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _mockCollectionCalendarService = new Mock <ICollectionCalendarService>(); _paymentProfiles = new List <IncentivePaymentProfile> { new IncentivePaymentProfile( IncentiveType.TwentyFiveOrOverIncentive, new List <PaymentProfile> { new PaymentProfile(10, 100), new PaymentProfile(100, 1000) }) }; _mockPaymentProfilesService .Setup(m => m.Get()) .ReturnsAsync(_paymentProfiles); _collectionPeriods = new List <Domain.ValueObjects.CollectionPeriod>() { new Domain.ValueObjects.CollectionPeriod(1, (byte)today.Month, (short)today.Year, today.AddDays(-1), _fixture.Create <DateTime>(), _fixture.Create <short>(), false) }; _mockCollectionCalendarService .Setup(m => m.Get()) .ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(_collectionPeriods)); var incentive = new ApprenticeshipIncentiveFactory() .CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <Account>(), new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>() ), today, _fixture.Create <DateTime>(), _fixture.Create <string>()); incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>()); _fixture.Register(() => incentive); _sut = new CalculateEarningsCommandHandler( _mockIncentiveDomainRespository.Object, _mockPaymentProfilesService.Object, _mockCollectionCalendarService.Object); }
private async Task <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive> ApprenticeshipIncentiveCreator() { var today = new DateTime(2021, 1, 30); var incentive = new ApprenticeshipIncentiveFactory() .CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <Account>(), new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>() ), today, _fixture.Create <DateTime>(), _fixture.Create <string>()); incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>()); var paymentProfiles = new List <IncentivePaymentProfile> { new IncentivePaymentProfile( IncentiveType.TwentyFiveOrOverIncentive, new List <PaymentProfile> { new PaymentProfile(10, 100), new PaymentProfile(100, 1000) }) }; var collectionPeriods = new List <Domain.ValueObjects.CollectionPeriod>() { new Domain.ValueObjects.CollectionPeriod( 1, (byte)today.Month, (short)today.Year, today.AddDays(-1), today, (short)today.Year, true) }; _mockCollectionCalendarService.Setup(m => m.Get()).ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(collectionPeriods)); _mockIncentivePaymentProfilesService.Setup(m => m.Get()).ReturnsAsync(paymentProfiles); await incentive.CalculateEarnings(_mockIncentivePaymentProfilesService.Object, _mockCollectionCalendarService.Object); var account = Domain.Accounts.Account.New(incentive.Account.Id); var legalEntityModel = _fixture.Build <LegalEntityModel>().With(x => x.AccountLegalEntityId, incentive.PendingPayments.First().Account.AccountLegalEntityId).With(x => x.VrfVendorId, "kjhdfhjksdfg").Create(); account.AddLegalEntity(incentive.PendingPayments.First().Account.AccountLegalEntityId, LegalEntity.Create(legalEntityModel)); incentive.ValidatePendingPaymentBankDetails(incentive.PendingPayments.First().Id, account, _collectionPeriods.First()); return(incentive); }
public void Arrange() { var today = new DateTime(2021, 1, 30); _fixture = new Fixture(); _mockPaymentProfilesService = new Mock <IIncentivePaymentProfilesService>(); _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _mockCollectionCalendarService = new Mock <ICollectionCalendarService>(); _paymentProfiles = new IncentivePaymentProfileListBuilder().Build(); _mockPaymentProfilesService .Setup(m => m.Get()) .ReturnsAsync(_paymentProfiles); _collectionPeriods = new List <CollectionCalendarPeriod>() { new CollectionCalendarPeriod(new Domain.ValueObjects.CollectionPeriod(1, _fixture.Create <short>()), (byte)today.Month, (short)today.Year, today.AddDays(-1), _fixture.Create <DateTime>(), true, false) }; _mockCollectionCalendarService .Setup(m => m.Get()) .ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(_collectionPeriods)); var incentive = new ApprenticeshipIncentiveFactory() .CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <Account>(), new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>(), _fixture.Create <DateTime>() ), today, _fixture.Create <DateTime>(), _fixture.Create <string>(), new AgreementVersion(_fixture.Create <int>()), new IncentivePhase(Phase.Phase1)); incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>()); _fixture.Register(() => incentive); _mockCommandPublisher = new Mock <IScheduledCommandPublisher>(); _sut = new CalculateEarningsCommandHandler( _mockIncentiveDomainRespository.Object, _mockPaymentProfilesService.Object, _mockCollectionCalendarService.Object, _mockCommandPublisher.Object); }
public void Then_the_apprenticeshipId_is_set() { // Arrange var apprenticeshipId = _fixture.Create <Guid>(); // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), apprenticeshipId, _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <string>()); // Assert incentive.GetModel().ApplicationApprenticeshipId.Should().Be(apprenticeshipId); }
public void Then_there_are_no_pending_payments() { // Arrange // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <string>()); // Assert incentive.PendingPayments.Count.Should().Be(0); incentive.GetModel().PendingPaymentModels.Count.Should().Be(0); }
public void Then_the_submittedDate_is_set() { // Arrange var submittedDate = _fixture.Create <DateTime>(); // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), _fixture.Create <DateTime>(), submittedDate, _fixture.Create <string>(), new AgreementVersion(_fixture.Create <int>()), new IncentivePhase(Phase.Phase1)); // Assert incentive.GetModel().SubmittedDate.Should().Be(submittedDate); }
public void Then_the_phase_is_set(Phase phase) { // Arrange var incentivePhase = new IncentivePhase(phase); // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <string>(), new AgreementVersion(_fixture.Create <int>()), incentivePhase); // Assert incentive.GetModel().Phase.Identifier.Should().Be(phase); }
public void Arrange() { _fixture = new Fixture(); _mockIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _mockLearnerDomainRepository = new Mock <ILearnerDomainRepository>(); var collectionPeriods = new List <CollectionCalendarPeriod>() { new CollectionCalendarPeriod(new Domain.ValueObjects.CollectionPeriod(1, _fixture.Create <short>()), _fixture.Create <byte>(), _fixture.Create <short>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), true, false), }; var collectionCalendar = new Domain.ValueObjects.CollectionCalendar(collectionPeriods); _mockCollectionCalendarService = new Mock <ICollectionCalendarService>(); _mockCollectionCalendarService.Setup(m => m.Get()).ReturnsAsync(collectionCalendar); _incentiveModel = _fixture .Build <ApprenticeshipIncentiveModel>() .With(p => p.Apprenticeship, new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), DateTime.Today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>(), _fixture.Create <DateTime>() )) .With(p => p.StartDate, DateTime.Today) .With(p => p.Status, Enums.IncentiveStatus.Active) .With(p => p.HasPossibleChangeOfCircumstances, true) .With(p => p.Phase, new IncentivePhase(Phase.Phase1)) .With(p => p.MinimumAgreementVersion, new AgreementVersion(_fixture.Create <int>())) .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>()) .Create(); _incentiveModel.Apprenticeship.SetProvider(_fixture.Create <Provider>()); _incentiveModel.HasPossibleChangeOfCircumstances = true; var incentive = new ApprenticeshipIncentiveFactory().GetExisting(_incentiveModel.Id, _incentiveModel); _fixture.Register(() => incentive); _sut = new LearnerChangeOfCircumstanceCommandHandler(_mockIncentiveDomainRepository.Object, _mockLearnerDomainRepository.Object, _mockCollectionCalendarService.Object); _incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>(); _learner = new LearnerFactory().GetExisting( _fixture.Build <LearnerModel>() .With(x => x.SubmissionData, _fixture.Create <SubmissionData>()) .With(x => x.ApprenticeshipIncentiveId, _incentive.Id) .Create()); _mockIncentiveDomainRepository.Setup(x => x.Find(incentive.Id)).ReturnsAsync(_incentive); _mockLearnerDomainRepository.Setup(m => m.GetOrCreate(incentive)).ReturnsAsync(_learner); }
public void Then_the_submittedByEmail_is_set() { // Arrange var submittedByEmail = _fixture.Create <string>(); // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), submittedByEmail); // Assert incentive.GetModel().SubmittedByEmail.Should().Be(submittedByEmail); }
public void Then_the_account_is_set() { // Arrange var account = _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(); // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), account, _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <string>(), new AgreementVersion(_fixture.Create <int>()), new IncentivePhase(Phase.Phase1)); // Assert incentive.Account.Should().Be(account); incentive.GetModel().Account.Id.Should().Be(account.Id); }
public void Then_the_startDate_is_set() { // Arrange var plannedStartDate = _fixture.Create <DateTime>(); // Act var incentive = new ApprenticeshipIncentiveFactory().CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Account>(), _fixture.Create <ApprenticeshipIncentives.ValueTypes.Apprenticeship>(), plannedStartDate, _fixture.Create <DateTime>(), _fixture.Create <string>()); // Assert incentive.StartDate.Should().Be(plannedStartDate); incentive.GetModel().StartDate.Should().Be(plannedStartDate); }
public void Arrange() { _fixture = new Fixture(); _mockIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _fixture.Customize(new ApprenticeshipIncentiveCustomization()); _fixture.Customize(new IncentiveApplicationCustomization()); _factory = new ApprenticeshipIncentiveFactory(); _sut = new CreateIncentiveCommandHandler( _factory, _mockIncentiveDomainRepository.Object); }
public void Arrange() { _fixture = new Fixture(); _mockIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _mockLearnerDomainRepository = new Mock <ILearnerDomainRepository>(); var incentiveModel = _fixture .Build <ApprenticeshipIncentiveModel>() .With(p => p.Apprenticeship, new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), DateTime.Today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>(), _fixture.Create <DateTime>() )) .With(p => p.StartDate, DateTime.Today) .With(p => p.Status, Enums.IncentiveStatus.Active) .With(p => p.HasPossibleChangeOfCircumstances, true) .With(p => p.Phase, new IncentivePhase(Phase.Phase2)) .With(p => p.MinimumAgreementVersion, new AgreementVersion(_fixture.Create <int>())) .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>()) .Create(); var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.Id, incentiveModel); _fixture.Register(() => incentive); _incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>(); _succeeded = _fixture.Create <bool>(); _learner = new LearnerFactory().GetExisting( _fixture.Build <LearnerModel>() .With(x => x.SuccessfulLearnerMatch, !_succeeded) .With(x => x.ApprenticeshipIncentiveId, _incentive.Id) .Create()); _mockIncentiveDomainRepository.Setup(x => x.Find(_incentive.Id)).ReturnsAsync(_incentive); _mockLearnerDomainRepository.Setup(m => m.GetOrCreate(_incentive)).ReturnsAsync(_learner); _sut = new SetSuccessfulLearnerMatchCommandHandler( _mockIncentiveDomainRepository.Object, _mockLearnerDomainRepository.Object); }
public async Task Then_a_Clawback_is_added_for_the_payment_when_the_incentive_has_paid_earnings() { //Arrange var incentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>()) .With(p => p.PaymentModels, new List <PaymentModel>()) .With(p => p.ClawbackPaymentModels, new List <ClawbackPaymentModel>()) .Create(); var pendingPaymentModel = _fixture.Build <PendingPaymentModel>() .With(p => p.ApprenticeshipIncentiveId, incentiveModel.Id) .Create(); incentiveModel.PendingPaymentModels.Add(pendingPaymentModel); var paymentModel = _fixture.Build <PaymentModel>() .With(p => p.ApprenticeshipIncentiveId, incentiveModel.Id) .With(p => p.PendingPaymentId, pendingPaymentModel.Id) .With(p => p.PaidDate, DateTime.Today.AddDays(-1)) .Create(); incentiveModel.PaymentModels.Add(paymentModel); var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.Id, incentiveModel); var command = new WithdrawCommand(incentive.Account.Id, incentive.Id); _mockIncentiveDomainRepository.Setup(x => x.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId)).ReturnsAsync(incentive); // Act await _sut.Handle(command); // Assert incentive.Clawbacks.Count.Should().Be(1); var clawback = incentive.Clawbacks.Single().GetModel(); clawback.Account.Should().Be(incentive.Account); clawback.Amount.Should().Be(pendingPaymentModel.Amount * -1); clawback.ApprenticeshipIncentiveId.Should().Be(incentive.Id); clawback.PendingPaymentId.Should().Be(pendingPaymentModel.Id); clawback.SubnominalCode.Should().Be(paymentModel.SubnominalCode); clawback.PaymentId.Should().Be(paymentModel.Id); clawback.CreatedDate.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMinutes(1)); clawback.CollectionPeriod.Should().Be(_activePeriod.PeriodNumber); clawback.CollectionPeriodYear.Should().Be(_activePeriod.AcademicYear); }
public void Arrange() { _fixture = new Fixture(); _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _mockLearnerDomainRespository = new Mock <ILearnerDomainRepository>(); var incentive = new ApprenticeshipIncentiveFactory() .CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <Account>(), new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), DateTime.Today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>() ), DateTime.Today, _fixture.Create <DateTime>(), _fixture.Create <string>()); incentive.SetHasPossibleChangeOfCircumstances(true); incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>()); _fixture.Register(() => incentive); _sut = new LearnerChangeOfCircumstanceCommandHandler(_mockIncentiveDomainRespository.Object, _mockLearnerDomainRespository.Object); _incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>(); _learner = new LearnerFactory().GetExisting( _fixture.Build <LearnerModel>() .With(x => x.SubmissionData, _fixture.Create <SubmissionData>()) .With(x => x.ApprenticeshipIncentiveId, _incentive.Id) .Create()); _mockIncentiveDomainRespository.Setup(x => x.Find(incentive.Id)).ReturnsAsync(_incentive); _mockLearnerDomainRespository.Setup(m => m.GetOrCreate(incentive)).ReturnsAsync(_learner); }
public async Task Then_a_PendingPaymentDeleted_event_is_raised_for_the_incentive_unpaid_earnings_when_the_incentive_has_paid_earnings() { //Arrange var incentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>()) .With(p => p.PaymentModels, new List <PaymentModel>()) .With(p => p.ClawbackPaymentModels, new List <ClawbackPaymentModel>()) .Create(); var pendingPaymentModel = _fixture.Build <PendingPaymentModel>() .With(p => p.ApprenticeshipIncentiveId, incentiveModel.Id) .With(p => p.PaymentMadeDate, (DateTime?)null) .Create(); incentiveModel.PendingPaymentModels.Add(pendingPaymentModel); var paymentModel = _fixture.Build <PaymentModel>() .With(p => p.ApprenticeshipIncentiveId, incentiveModel.Id) .With(p => p.PendingPaymentId, pendingPaymentModel.Id) .With(p => p.PaidDate, DateTime.Today.AddDays(-1)) .Create(); incentiveModel.PaymentModels.Add(paymentModel); var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.Id, incentiveModel); var command = new WithdrawCommand(incentive.Account.Id, incentive.Id); _mockIncentiveDomainRepository.Setup(x => x.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId)).ReturnsAsync(incentive); // Act await _sut.Handle(command); // Assert var raisedEvent = incentive.FlushEvents().OfType <PendingPaymentDeleted>().Single(); raisedEvent.AccountId.Should().Be(incentive.Account.Id); raisedEvent.AccountLegalEntityId.Should().Be(incentive.Account.AccountLegalEntityId); raisedEvent.UniqueLearnerNumber.Should().Be(incentive.Apprenticeship.UniqueLearnerNumber); raisedEvent.Model.Should().Be(pendingPaymentModel); }
private Domain.ApprenticeshipIncentives.ApprenticeshipIncentive ApprenticeshipIncentiveCreator() { var incentive = new ApprenticeshipIncentiveFactory() .CreateNew(_fixture.Create <Guid>(), _fixture.Create <Guid>(), _fixture.Create <Account>(), new Apprenticeship( _fixture.Create <long>(), _fixture.Create <string>(), _fixture.Create <string>(), DateTime.Today.AddYears(-26), _fixture.Create <long>(), ApprenticeshipEmployerType.Levy, _fixture.Create <string>() ), DateTime.Today, _fixture.Create <DateTime>(), _fixture.Create <string>()); return(incentive); }
public async Task Then_the_LearningPeriods_are_set_when_there_are_price_episodes_with_periods_for_the_apprenticeship() { //Arrange var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId); var apprenticeship = _fixture.Create <Apprenticeship>(); apprenticeship.SetProvider(_fixture.Create <Provider>()); var apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(p => p.Apprenticeship, apprenticeship) .Create(); _mockApprenticeshipIncentiveDomainRepository .Setup(m => m.Find(_apprenticeshipIncentiveId)) .ReturnsAsync(new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.ApplicationApprenticeshipId, apprenticeshipIncentiveModel)); var apprenticeshipIncentive = new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.Id, apprenticeshipIncentiveModel); var learner = new LearnerFactory().GetExisting(_fixture.Create <LearnerModel>()); _mockLearnerDomainRepository .Setup(m => m.GetOrCreate(apprenticeshipIncentive)) .ReturnsAsync(learner); var learnerSubmissionDto = _fixture .Build <LearnerSubmissionDto>() .With(l => l.Training, new List <TrainingDto> { _fixture.Create <TrainingDto>(), _fixture .Build <TrainingDto>() .With(p => p.Reference, "ZPROG001") .With(t => t.PriceEpisodes, new List <PriceEpisodeDto> { _fixture .Build <PriceEpisodeDto>() .With(pe => pe.Periods, new List <PeriodDto> { _fixture .Build <PeriodDto>() .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id) .Create() }) .Create() }).Create(), _fixture.Create <TrainingDto>() }) .Create(); _mockLearnerService .Setup(m => m.Get(It.IsAny <Learner>())) .ReturnsAsync(learnerSubmissionDto); //Act await _sut.Handle(command); //Assert _mockLearnerDomainRepository.Verify(m => m.Save( It.Is <Learner>(l => l.GetModel().LearningPeriods.Count == 1) ), Times.Once); }
public async Task Then_the_inlearning_flag_is_true_when_there_is_a_pending_payment_with_a_matching_inlearning_period() { //Arrange var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId); var apprenticeship = _fixture.Create <Apprenticeship>(); apprenticeship.SetProvider(_fixture.Create <Provider>()); var pendingPaymentModel = _fixture.Create <PendingPaymentModel>(); pendingPaymentModel.PaymentMadeDate = null; var apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(p => p.Apprenticeship, apprenticeship) .With(p => p.PendingPaymentModels, new List <PendingPaymentModel> { pendingPaymentModel }) .Create(); _mockApprenticeshipIncentiveDomainRepository .Setup(m => m.Find(_apprenticeshipIncentiveId)) .ReturnsAsync(new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.ApplicationApprenticeshipId, apprenticeshipIncentiveModel)); var apprenticeshipIncentive = new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.Id, apprenticeshipIncentiveModel); var learner = new LearnerFactory().GetExisting(_fixture.Create <LearnerModel>()); _mockLearnerDomainRepository .Setup(m => m.GetOrCreate(apprenticeshipIncentive)) .ReturnsAsync(learner); var learnerSubmissionDto = _fixture .Build <LearnerSubmissionDto>() .With(l => l.Training, new List <TrainingDto> { _fixture.Create <TrainingDto>(), _fixture .Build <TrainingDto>() .With(p => p.Reference, "ZPROG001") .With(t => t.PriceEpisodes, new List <PriceEpisodeDto> { _fixture .Build <PriceEpisodeDto>() .With(pe => pe.StartDate, pendingPaymentModel.DueDate.AddDays(-1)) .With(pe => pe.EndDate, pendingPaymentModel.DueDate.AddDays(1)) .With(pe => pe.Periods, new List <PeriodDto> { _fixture .Build <PeriodDto>() .With(p => p.Period, pendingPaymentModel.PeriodNumber) .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id) .Create() }) .Create() }).Create(), _fixture.Create <TrainingDto>() }) .Create(); _mockLearnerService .Setup(m => m.Get(It.IsAny <Learner>())) .ReturnsAsync(learnerSubmissionDto); //Act await _sut.Handle(command); //Assert _mockLearnerDomainRepository.Verify(m => m.Save( It.Is <Learner>(l => l.SubmissionData.LearningData.IsInlearning == true) ), Times.Once); }
public void Arrange() { _sut = new ApprenticeshipIncentiveFactory(); _fixture = new Fixture(); }
public void Arrange() { _fixture = new Fixture(); _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>(); _mockCollectionCalendarService = new Mock <ICollectionCalendarService>(); _mockAccountDomainRepository = new Mock <IAccountDomainRepository>(); _mockLearnerDomainRepository = new Mock <ILearnerDomainRepository>(); _startDate = DateTime.Today; _payment1DueDate = _startDate.AddDays(10); _collectionCalendarPeriods = new List <Domain.ValueObjects.CollectionCalendarPeriod>() { new Domain.ValueObjects.CollectionCalendarPeriod( new Domain.ValueObjects.CollectionPeriod(1, (short)DateTime.Now.Year), (byte)DateTime.Now.Month, (short)DateTime.Now.Year, DateTime.Now.AddDays(-1), DateTime.Now, true, false) }; _mockCollectionCalendarService .Setup(m => m.Get()) .ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(_collectionCalendarPeriods)); _vrfVendorId = Guid.NewGuid().ToString(); var legalEntity = _fixture.Build <LegalEntityModel>() .With(l => l.VrfVendorId, _vrfVendorId) .With(l => l.SignedAgreementVersion, 5) .Create(); var accountModel = _fixture.Build <AccountModel>() .With(a => a.LegalEntityModels, new List <LegalEntityModel>() { legalEntity }) .Create(); var domainAccount = Domain.Accounts.Account.Create(accountModel); _account = new Account(accountModel.Id, legalEntity.AccountLegalEntityId); var pendingPayment1 = _fixture.Build <PendingPaymentModel>() .With(m => m.Account, _account) .With(m => m.DueDate, _payment1DueDate) .With(m => m.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create(); var pendingPayment2 = _fixture.Build <PendingPaymentModel>() .With(m => m.Account, _account) .With(m => m.DueDate, _payment1DueDate.AddDays(2)) .With(m => m.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create(); var pendingPayments = new List <PendingPaymentModel>() { pendingPayment1, pendingPayment2 }; var model = _fixture.Build <ApprenticeshipIncentiveModel>() .With(m => m.Account, _account) .With(m => m.StartDate, _startDate) .With(m => m.PendingPaymentModels, pendingPayments) .With(m => m.PausePayments, false) .With(m => m.MinimumAgreementVersion, new AgreementVersion(4)) .Create(); var incentive = new ApprenticeshipIncentiveFactory().GetExisting(model.Id, model); _fixture.Register(() => incentive); _mockIncentiveDomainRespository .Setup(m => m.Find(incentive.Id)) .ReturnsAsync(incentive); _mockAccountDomainRepository .Setup(m => m.Find(incentive.Account.Id)) .ReturnsAsync(domainAccount); var submissionData = new SubmissionData(); submissionData.SetSubmissionDate(DateTime.UtcNow); submissionData.SetLearningData(new LearningData(true)); submissionData.LearningData.SetIsInLearning(true); _daysInLearning = new DaysInLearning(new Domain.ValueObjects.CollectionPeriod(1, (short)DateTime.Now.Year), 90); _learnerModel = _fixture.Build <LearnerModel>() .With(m => m.ApprenticeshipId, incentive.Apprenticeship.Id) .With(m => m.ApprenticeshipIncentiveId, incentive.Id) .With(m => m.UniqueLearnerNumber, incentive.Apprenticeship.UniqueLearnerNumber) .With(m => m.SubmissionData, submissionData) .With(m => m.DaysInLearnings, new List <DaysInLearning>() { _daysInLearning }) .Create(); _learner = new LearnerFactory().GetExisting(_learnerModel); _mockLearnerDomainRepository .Setup(m => m.GetOrCreate(incentive)) .ReturnsAsync(_learner); _sut = new ValidatePendingPaymentCommandHandler( _mockIncentiveDomainRespository.Object, _mockAccountDomainRepository.Object, _mockCollectionCalendarService.Object, _mockLearnerDomainRepository.Object); }
public async Task Then_the_learning_stopped_status_has_false_stopped_flag_when_there_are_matching_learner_records_and_the_learning_has_resumed_from_stopped() { //Arrange var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId); var apprenticeship = _fixture.Create <Apprenticeship>(); apprenticeship.SetProvider(_fixture.Create <Provider>()); var apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>() .With(p => p.Apprenticeship, apprenticeship) .With(p => p.Status, Enums.IncentiveStatus.Stopped) .Create(); _mockApprenticeshipIncentiveDomainRepository .Setup(m => m.Find(_apprenticeshipIncentiveId)) .ReturnsAsync(new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.ApplicationApprenticeshipId, apprenticeshipIncentiveModel)); var apprenticeshipIncentive = new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.Id, apprenticeshipIncentiveModel); var learner = new LearnerFactory().GetExisting(_fixture.Create <LearnerModel>()); _mockLearnerDomainRepository .Setup(m => m.GetOrCreate(apprenticeshipIncentive)) .ReturnsAsync(learner); var learnerSubmissionDto = _fixture .Build <LearnerSubmissionDto>() .With(l => l.Training, new List <TrainingDto> { _fixture.Create <TrainingDto>(), _fixture .Build <TrainingDto>() .With(p => p.Reference, "ZPROG001") .With(t => t.PriceEpisodes, new List <PriceEpisodeDto> { _fixture .Build <PriceEpisodeDto>() .With(pe => pe.Periods, new List <PeriodDto> { _fixture .Build <PeriodDto>() .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id) .Create() }) .With(pe => pe.StartDate, DateTime.Today.AddDays(-20)) .With(pe => pe.EndDate, DateTime.Today.AddDays(10)) .Create(), _fixture .Build <PriceEpisodeDto>() .With(pe => pe.Periods, new List <PeriodDto> { _fixture .Build <PeriodDto>() .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id) .Create() }) .With(pe => pe.StartDate, DateTime.Today.AddDays(-10)) .With(pe => pe.EndDate, DateTime.Today) .Create() }).Create(), _fixture.Create <TrainingDto>() }) .Create(); _mockLearnerService .Setup(m => m.Get(It.IsAny <Learner>())) .ReturnsAsync(learnerSubmissionDto); //Act await _sut.Handle(command); //Assert _mockLearnerDomainRepository.Verify(m => m.Save( It.Is <Learner>(l => !l.SubmissionData.LearningData.StoppedStatus.LearningStopped && l.SubmissionData.LearningData.StoppedStatus.DateResumed.HasValue && !l.SubmissionData.LearningData.StoppedStatus.DateStopped.HasValue) ), Times.Once); }