コード例 #1
0
        public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_PartialPaymentExistsAndAmountPaidIsLessThanAmountDue( )
        {
            var invoice = new Invoice( )
            {
                Amount     = 10,
                AmountPaid = 5,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 5
                    }
                }
            };
            var repo             = new InvoiceRepository(invoice);
            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 1
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("another partial payment received, still not fully paid", result);
        }
コード例 #2
0
        public void ProcessPayment_Should_ReturnFailureMessage_When_PartialPaymentExistsAndAmountPaidExceedsAmountDue( )
        {
            var invoice = new Invoice( )
            {
                Amount     = 10,
                AmountPaid = 5,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 5
                    }
                }
            };
            var repo             = new InvoiceRepository(invoice);
            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 6
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("the payment is greater than the partial amount remaining", result);
        }
コード例 #3
0
        public void ProcessPayment_Should_ReturnFullyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidEqualsInvoiceAmount( )
        {
            var invoice = new Invoice( )
            {
                Amount     = 10,
                AmountPaid = 0,
                Payments   = new List <Payment>( )
                {
                    new Payment( )
                    {
                        Amount = 10
                    }
                }
            };
            var repo             = new InvoiceRepository(invoice);
            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 10
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("invoice was already fully paid", result);
        }
        public void ProcessPayment_Should_ReturnFailureMessage_When_InvoiceAlreadyFullyPaid( )
        {
            var repo = new InvoiceRepository( );

            var invoice = new Invoice(repo)
            {
                Amount     = 10,
                AmountPaid = 10,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 10
                    }
                }
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( );

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("invoice was already fully paid", result);
        }
        public void ProcessPayment_Should_ReturnFullyPaidMessage_When_PartialPaymentExistsAndAmountPaidEqualsAmountDue( )
        {
            var repo    = new InvoiceRepository( );
            var invoice = new Invoice(repo)
            {
                Amount     = 10,
                AmountPaid = 5,
                Payments   = new List <Payment>
                {
                    new Payment
                    {
                        Amount = 5
                    }
                }
            };

            repo.Add(invoice);

            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 5
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("final partial payment received, invoice is now fully paid", result);
        }
コード例 #6
0
        public void ProcessPayment_Should_ReturnFailureMessage_When_NoPaymentNeeded( )
        {
            var invoice = new Invoice( )
            {
                Amount     = 0,
                AmountPaid = 0,
                Payments   = null
            };
            var repo             = new InvoiceRepository(invoice);
            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( );

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("no payment needed", result);
        }
コード例 #7
0
        public void ProcessPayment_Should_ReturnPartiallyPaidMessage_When_NoPartialPaymentExistsAndAmountPaidIsLessThanInvoiceAmount( )
        {
            var invoice = new Invoice( )
            {
                Amount     = 10,
                AmountPaid = 0,
                Payments   = new List <Payment>( )
            };
            var repo             = new InvoiceRepository(invoice);
            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 1
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("invoice is now partially paid", result);
        }
コード例 #8
0
        public void ProcessPayment_Should_ThrowException_When_NoInoiceFoundForPaymentReference( )
        {
            Invoice invoice          = null;
            var     repo             = new InvoiceRepository(invoice);
            var     paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment        = new Payment( );
            var failureMessage = "";

            try
            {
                var result = paymentProcessor.ProcessPayment(payment);
            }
            catch (InvalidOperationException e)
            {
                failureMessage = e.Message;
            }

            Assert.AreEqual("There is no invoice matching this payment", failureMessage);
        }
コード例 #9
0
        public void ProcessPayment_Should_ReturnFailureMessage_When_NoPartialPaymentExistsAndAmountPaidExceedsInvoiceAmount( )
        {
            var invoice = new Invoice( )
            {
                Amount     = 5,
                AmountPaid = 0,
                Payments   = new List <Payment>( )
            };
            var repo             = new InvoiceRepository(invoice);
            var paymentProcessor = new InvoicePaymentProcessor(repo);

            var payment = new Payment( )
            {
                Amount = 6
            };

            var result = paymentProcessor.ProcessPayment(payment);

            Assert.AreEqual("the payment is greater than the invoice amount", result);
        }