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>(),
                                           _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>());

            var paymentProfiles = new IncentivePaymentProfileListBuilder().Build();

            var collectionPeriods = new List <CollectionCalendarPeriod>()
            {
                new CollectionCalendarPeriod(
                    new Domain.ValueObjects.CollectionPeriod(1, (short)today.Year),
                    (byte)today.Month,
                    (short)today.Year,
                    today.AddDays(-1),
                    today,
                    true,
                    false)
            };

            _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().CollectionPeriod);

            return(incentive);
        }
Beispiel #2
0
        public TestFunction(TestContext testContext, string hubName)
        {
            HubName            = hubName;
            _orchestrationData = new OrchestrationData();

            _appConfig = new Dictionary <string, string> {
                { "EnvironmentName", "LOCAL_ACCEPTANCE_TESTS" },
                { "AzureWebJobsStorage", "UseDevelopmentStorage=true" },
                { "NServiceBusConnectionString", "UseDevelopmentStorage=true" },
                { "ConfigNames", "SFA.DAS.EmployerIncentives" }
            };

            _testContext = testContext;

            var paymentProfiles = new IncentivePaymentProfileListBuilder().Build();

            _host = new HostBuilder()
                    .ConfigureAppConfiguration(a =>
            {
                a.Sources.Clear();
                a.AddInMemoryCollection(_appConfig);
            })
                    .ConfigureWebJobs(builder => builder
                                      .AddHttp(options => options.SetResponse = (request, o) =>
            {
                ResponseObject = o;
            })
                                      .AddDurableTask(options =>
            {
                options.HubName                 = HubName;
                options.UseAppLease             = false;
                options.UseGracefulShutdown     = false;
                options.ExtendedSessionsEnabled = false;
                options.StorageProvider["maxQueuePollingInterval"] = new TimeSpan(0, 0, 0, 0, 500);
                options.StorageProvider["partitionCount"]          = 1;
                options.NotificationUrl = new Uri("localhost:7071");
#pragma warning disable S125 // Sections of code should not be commented out
                             //options.StorageProvider["controlQueueBatchSize"] = 5;
                             //options.HttpSettings.DefaultAsyncRequestSleepTimeMilliseconds = 500;
                             //options.MaxConcurrentActivityFunctions = 10;
                             //options.MaxConcurrentOrchestratorFunctions = 5;
#pragma warning restore S125
            })
                                      .AddAzureStorageCoreServices()
                                      .ConfigureServices(s =>
            {
                new Startup().Configure(builder);

                s.Configure <MatchedLearnerApi>(l =>
                {
                    l.ApiBaseUrl = _testContext.LearnerMatchApi.BaseAddress;
                    l.Identifier = "";
                    l.Version    = "1.0";
                });

                s.Configure <BusinessCentralApiClient>(c =>
                {
                    c.ApiBaseUrl           = _testContext.PaymentsApi.BaseAddress;
                    c.PaymentRequestsLimit = BusinessCentralPaymentRequestsLimit;
                });

                s.Configure <ApplicationSettings>(a =>
                {
                    a.DbConnectionString                  = _testContext.SqlDatabase.DatabaseInfo.ConnectionString;
                    a.DistributedLockStorage              = "UseDevelopmentStorage=true";
                    a.NServiceBusConnectionString         = "UseLearningEndpoint=true";
                    a.UseLearningEndpointStorageDirectory = Path.Combine(testContext.TestDirectory.FullName, ".learningtransport");
                    a.IncentivePaymentProfiles            = paymentProfiles;
                });

                s.AddSingleton <IDistributedLockProvider, NullLockProvider>();
                s.AddSingleton(typeof(IOrchestrationData), _orchestrationData);
                s.Decorate(typeof(ICommandHandler <>), typeof(CommandHandlerWithTimings <>));
            })
                                      )
                    .ConfigureServices(s =>
            {
                s.AddHostedService <PurgeBackgroundJob>();
            })
                    .Build();
        }