public async Task TestStoresRequiredPayment()
        {
            // arrange
            long expectedUln   = 100;
            long expectedUkprn = 100;

            var requiredPaymentEvent = new CalculatedRequiredLevyAmount
            {
                Ukprn     = expectedUkprn,
                StartDate = DateTime.Today,
                EventId   = Guid.NewGuid(),
                Priority  = 1,
                Learner   = new Learner
                {
                    Uln = expectedUln
                },
                AccountId = 1,
            };

            eventCacheMock.Setup(c => c.AddOrReplace(requiredPaymentEvent.EventId.ToString(), requiredPaymentEvent, CancellationToken.None)).Returns(Task.CompletedTask)
            .Verifiable();

            requiredPaymentSortKeysCacheMock
            .Setup(c => c.TryGet(CacheKeys.RequiredPaymentKeyListKey, CancellationToken.None))
            .ReturnsAsync(() => new ConditionalValue <List <RequiredPaymentSortKeyModel> >(false, null))
            .Verifiable();

            requiredPaymentSortKeysCacheMock
            .Setup(c =>
                   c.AddOrReplace(CacheKeys.RequiredPaymentKeyListKey,
                                  It.Is <List <RequiredPaymentSortKeyModel> >(list => list.Count == 1 &&
                                                                              list[0].Uln == expectedUln &&
                                                                              list[0].Ukprn == expectedUkprn), CancellationToken.None))
            .Returns(Task.CompletedTask)
            .Verifiable();

            // act
            await service.AddRequiredPayment(requiredPaymentEvent);

            // assert in teardown
        }
Exemple #2
0
        public async Task HandleRequiredPayment(CalculatedRequiredLevyAmount message)
        {
            try
            {
                using (var operation = telemetry.StartOperation("LevyFundedService.HandleRequiredPayment", message.EventId.ToString()))
                {
                    var stopwatch = Stopwatch.StartNew();
                    paymentLogger.LogVerbose($"Handling RequiredPayment for {Id}, Job: {message.JobId}, UKPRN: {message.Ukprn}, Account: {message.AccountId}");
                    await fundingSourceService.AddRequiredPayment(message).ConfigureAwait(false);

                    paymentLogger.LogInfo($"Finished handling required payment for {Id}, Job: {message.JobId}, UKPRN: {message.Ukprn}, Account: {message.AccountId}");
                    telemetry.TrackDuration("LevyFundedService.HandleRequiredPayment", stopwatch, message);
                    telemetry.StopOperation(operation);
                }
            }
            catch (Exception e)
            {
                paymentLogger.LogError($"Error handling required levy payment. Error:{e.Message}", e);
                throw;
            }
        }