Esempio n. 1
0
        public void shouldMakePaymentOfFullPaid()
        {
            var paymentDto    = fakePaymentDto();
            var invoiceDetail = fakeInvoiceDetail(paymentDto.InvoiceId);

            _invoiceRepository.Setup(m => m.InvoiceExists(paymentDto.InvoiceId)).Returns(true);
            _contactRepository.Setup(m => m.GetContactById(paymentDto.ContactId)).Returns(new MpMyContact()
            {
                Contact_ID = paymentDto.ContactId
            });
            _contactRepository.Setup(m => m.GetContactById(invoiceDetail.RecipientContactId)).Returns(new MpMyContact()
            {
                Congregation_ID = 1
            });
            _paymentTypeRepository.Setup(m => m.PaymentTypeExists(5)).Returns(true);
            _invoiceRepository.Setup(m => m.GetInvoiceDetailForInvoice(paymentDto.InvoiceId)).Returns(invoiceDetail);

            var retVal = new MpPaymentDetailReturn()
            {
                InvoiceDetailId = invoiceDetail.InvoiceDetailId,
                PaymentAmount   = paymentDto.DonationAmt,
                PaymentDetailId = 398457,
                PaymentId       = 2897234
            };

            _paymentRepository.Setup(m => m.CreatePaymentAndDetail(It.IsAny <MpPaymentDetail>())).Returns(new Result <MpPaymentDetailReturn>(true, retVal));

            var invoice = new MpInvoice()
            {
                InvoiceId    = paymentDto.InvoiceId,
                InvoiceTotal = 500
            };

            var paymentsSoFar = new List <MpPayment>
            {
                new MpPayment()
                {
                    PaymentTotal  = 300,
                    PaymentStatus = 3
                },
                new MpPayment()
                {
                    PaymentTotal  = 200,
                    PaymentStatus = 3
                }
            };

            _invoiceRepository.Setup(m => m.GetInvoice(invoiceDetail.InvoiceId)).Returns(invoice);
            _paymentRepository.Setup(m => m.GetPaymentsForInvoice(paymentDto.InvoiceId)).Returns(paymentsSoFar);
            _invoiceRepository.Setup(m => m.SetInvoiceStatus(paymentDto.InvoiceId, paidInFull));

            var val = _fixture.PostPayment(paymentDto);

            Assert.AreEqual(retVal, val);
            _invoiceRepository.VerifyAll();
            _contactRepository.VerifyAll();
            _paymentTypeRepository.VerifyAll();
            _paymentRepository.VerifyAll();
            _configWrapper.VerifyAll();
        }
Esempio n. 2
0
        public void testPostToCreateDonationAndDistributionAuthenticatedPayment()
        {
            var contactId = 999999;
            var payment   = new MpPaymentDetailReturn();

            payment.PaymentId = 46546;

            var charge = new StripeCharge()
            {
                Id = "ch_crdscharge86868",
                BalanceTransaction = new StripeBalanceTransaction()
                {
                    Fee = 987
                }
            };

            var createDonationDTO = new CreateDonationDTO
            {
                Amount          = 86868,
                DonorId         = 394256,
                EmailAddress    = "*****@*****.**",
                PaymentType     = "bank",
                TransactionType = "PAYMENT",
                InvoiceId       = 88
            };

            var donor = new MpContactDonor
            {
                ContactId       = contactId,
                DonorId         = 424242,
                SetupDate       = new DateTime(),
                StatementFreq   = "1",
                StatementMethod = "2",
                StatementType   = "3",
                ProcessorId     = "cus_test1234567",
                Email           = "moc.tset@tset"
            };

            contactRepositoryMock.Setup(mocked => mocked.GetContactId(authType + " " + authToken)).Returns(contactId);

            donorServiceMock.Setup(mocked => mocked.GetContactDonor(contactId))
            .Returns(donor);

            stripeServiceMock.Setup(
                mocked => mocked.ChargeCustomer(donor.ProcessorId, createDonationDTO.Amount, donor.DonorId, true))
            .Returns(charge);

            invoiceServiceMock.Setup(mocked => mocked.InvoiceExists(It.IsAny <int>()))
            .Returns(true);

            paymentServiceMock.Setup(mocked => mocked.PostPayment(It.IsAny <MpDonationAndDistributionRecord>()))
            .Returns(payment);

            IHttpActionResult result = fixture.Post(createDonationDTO);

            authenticationServiceMock.VerifyAll();
            donorServiceMock.VerifyAll();
            stripeServiceMock.VerifyAll();
            donorServiceMock.VerifyAll();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <DonationDTO>), result);
            var okResult = (OkNegotiatedContentResult <DonationDTO>)result;

            Assert.AreEqual(46546, payment.PaymentId);
        }