Ejemplo n.º 1
0
        public async Task CreateFunder()
        {
            Console.WriteLine("CreateFunder");

            var logger = ServiceScope.ServiceProvider.GetService <ILogger <FundingTest> >();

            var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow());

            logger.LogInformation($"Funder reference = {funderReference}");

            var funderId = await FundingMicroService.AllocateFunderAsync(funderReference);

            logger.LogInformation($"Funder ID = {funderId}");

            var funder = await FundingMicroService.GetFunderAsync(funderId);

            Assert.IsNotNull(funder);
            logger.LogInformation($"Funder retrieved.  Funder reference = {funder.FunderReference}");
            Assert.AreEqual(funderReference, funder.FunderReference);

            var funders = await FundingMicroService.GetFunderSummariesAsync(null, null, null, null);

            Assert.IsNotNull(funders);
            Assert.IsNotNull(funders.Summaries);
            Assert.IsTrue(funders.Summaries.Any(r => r.FunderReference == funderReference));
        }
Ejemplo n.º 2
0
        public async Task TransferRefund()
        {
            Console.WriteLine("TransferRefund");

            var logger     = ServiceScope.ServiceProvider.GetService <ILogger <FundingTest> >();
            var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow());

            var incomeAmount         = 100m;
            var salesTaxAmount       = 5m;
            var totalAmount          = incomeAmount + salesTaxAmount;
            var incomeRefundAmount   = 10;
            var salesTaxRefundAmount = 1;
            var salesTaxJurisdiction = "XX";

            // Create references.
            //
            var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow());

            logger.LogInformation($"Funder reference = {funderReference}");

            var fundableReference = CreateFundableReference.FromTimestamp(GetUniqueNow());

            logger.LogInformation($"Fundable reference = {fundableReference}");

            // Create funder and set funds received.
            //
            var funderId = await FundingMicroService.AllocateFunderAsync(funderReference);

            logger.LogInformation($"Funder ID = {funderId}");

            await FundingMicroService.SetFundsReceivedAsync(funderId, fundableReference, totalAmount, unitOfWork.Next());

            logger.LogInformation($"Set {totalAmount:c} funds received.");

            var eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            // Create fundable and set funds required.
            //
            var fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference);

            logger.LogInformation($"Fundable ID = {fundableId}");

            await FundingMicroService.SetFundsRequiredAsync(fundableId, incomeAmount, salesTaxAmount, salesTaxJurisdiction, unitOfWork.Next());

            logger.LogInformation($"Set {incomeAmount:c} + {salesTaxAmount:c} funds required.");

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            // Ensure funds transferred.
            //
            var fundable = await FundingMicroService.GetFundableAsync(fundableId);

            Assert.IsNotNull(fundable);
            logger.LogInformation($"Fundable retrieved.  Fundable reference = {fundable.FundableReference}");
            Assert.AreEqual(fundableReference, fundable.FundableReference);
            Assert.AreEqual(fundable.FundsRequiredTotal, totalAmount);
            Assert.AreEqual(fundable.FundsReceived, totalAmount);

            // Reduce funds required.
            //
            await FundingMicroService.SetFundsRequiredAsync(fundableId, incomeAmount - incomeRefundAmount, salesTaxAmount - salesTaxRefundAmount, salesTaxJurisdiction, unitOfWork.Next());

            logger.LogInformation($"Set {incomeAmount - incomeRefundAmount:c} + {salesTaxAmount - salesTaxRefundAmount:c} funds required.");

            // Ensure funds refunded.
            //
            var funder = await FundingMicroService.GetFunderAsync(funderId);

            Assert.AreEqual(funder.TotalFundsRefundable, incomeRefundAmount + salesTaxRefundAmount);
        }