Ejemplo n.º 1
0
        public async Task should_handle_same_cc_same_amount()
        {
            // do nothing, payment doesn't need updating

            // Arrange
            var mockedCreditCardTotal = 50;
            var existing = PaymentMocks.PaymentList(PaymentMocks.CCPayment(creditcard1, 50, mockCCPaymentID));

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.CCPayment(creditcard1));

            _orderCalc.GetCreditCardTotal(Arg.Any <HSOrderWorksheet>())
            .Returns(mockedCreditCardTotal);

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.DidNotReceive().DeleteAsync(OrderDirection.Incoming, mockOrderID, Arg.Any <string>());

            await _ccCommand.DidNotReceive().VoidTransactionAsync(Arg.Any <HSPayment>(), Arg.Any <HSOrder>(), mockUserToken);

            await _oc.Payments.DidNotReceive().CreateAsync <HSPayment>(Arg.Any <OrderDirection>(), mockOrderID, Arg.Any <HSPayment>(), mockUserToken);

            await _oc.Payments.DidNotReceive().PatchAsync <HSPayment>(Arg.Any <OrderDirection>(), mockOrderID, Arg.Any <string>(), Arg.Any <PartialPayment>());
        }
Ejemplo n.º 2
0
        public async Task should_handle_different_cc_different_amount()
        {
            // if the credit card has changed we need to delete the payment
            // but should void the existing authorization before that

            // Arrange
            var mockedCreditCardTotal = 50;
            var existing = PaymentMocks.PaymentList(PaymentMocks.CCPayment(creditcard1, 40, mockCCPaymentID));

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.CCPayment(creditcard2));

            _orderCalc.GetCreditCardTotal(Arg.Any <HSOrderWorksheet>())
            .Returns(mockedCreditCardTotal);

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.Received().DeleteAsync(OrderDirection.Incoming, mockOrderID, mockCCPaymentID);

            await _ccCommand.Received().VoidTransactionAsync(Arg.Is <HSPayment>(p => p.ID == mockCCPaymentID), Arg.Is <HSOrder>(o => o.ID == mockOrderID), mockUserToken);

            await _oc.Payments.Received().CreateAsync <HSPayment>(OrderDirection.Outgoing, mockOrderID, Arg.Is <HSPayment>(p => p.CreditCardID == creditcard2 && p.Amount == mockedCreditCardTotal && p.Accepted == false), mockUserToken);
        }
Ejemplo n.º 3
0
        public async Task should_handle_same_cc_different_amount()
        {
            // if the credit card hasn't changed but the amount has
            // then we should void any existing transactions if necessary and update the payment

            // Arrange
            var mockedCreditCardTotal = 30;
            var existing = PaymentMocks.PaymentList(PaymentMocks.CCPayment(creditcard1, 20));

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.CCPayment(creditcard1));

            _orderCalc.GetCreditCardTotal(Arg.Any <HSOrderWorksheet>())
            .Returns(mockedCreditCardTotal);

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.DidNotReceive().DeleteAsync(OrderDirection.Incoming, mockOrderID, Arg.Any <string>());

            await _ccCommand.Received().VoidTransactionAsync(Arg.Is <HSPayment>(p => p.ID == mockCCPaymentID), Arg.Is <HSOrder>(o => o.ID == mockOrderID), mockUserToken);

            await _oc.Payments.Received().PatchAsync <HSPayment>(OrderDirection.Incoming, mockOrderID, mockCCPaymentID, Arg.Is <PartialPayment>(p => p.Amount == mockedCreditCardTotal && p.Accepted == false));
        }
Ejemplo n.º 4
0
        public async Task should_handle_existing_po_payment()
        {
            // Arrange
            var mockedPOTotal = 20;
            var existing      = PaymentMocks.PaymentList(PaymentMocks.POPayment(40));

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.POPayment());

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.Received().PatchAsync <HSPayment>(OrderDirection.Incoming, mockOrderID, mockPoPaymentID, Arg.Is <PartialPayment>(p => p.Amount == mockedPOTotal));
        }
Ejemplo n.º 5
0
        [Test] public async Task should_handle_new_cc_payment()
        {
            // Arrange
            var mockedCreditCardTotal = 20;
            var existing = PaymentMocks.EmptyPaymentsList();

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.CCPayment(creditcard1));

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.DidNotReceive().DeleteAsync(OrderDirection.Incoming, mockOrderID, Arg.Any <string>());

            await _oc.Payments.Received().CreateAsync <HSPayment>(OrderDirection.Outgoing, mockOrderID, Arg.Is <HSPayment>(p => p.ID == mockCCPaymentID && p.Type == PaymentType.CreditCard && p.Amount == mockedCreditCardTotal && p.Accepted == false), mockUserToken);
        }
Ejemplo n.º 6
0
        public async Task should_delete_stale_payments()
        {
            // Arrange
            var mockedCreditCardTotal = 20;
            var existing = PaymentMocks.PaymentList(PaymentMocks.SpendingAccountPayment(20));

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.CCPayment(creditcard1));

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.Received().DeleteAsync(OrderDirection.Incoming, mockOrderID, mockSpendingAccountID);

            await _oc.Payments.Received().CreateAsync <HSPayment>(OrderDirection.Outgoing, mockOrderID, Arg.Is <HSPayment>(p => p.ID == mockCCPaymentID && p.Type == PaymentType.CreditCard && p.Amount == mockedCreditCardTotal), mockUserToken);
        }
Ejemplo n.º 7
0
        public async Task should_handle_new_po_payment()
        {
            // Arrange
            var mockedPOTotal = 50;
            var existing      = PaymentMocks.EmptyPaymentsList();

            _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, mockOrderID)
            .Returns(Task.FromResult(existing));
            var requested = PaymentMocks.Payments(PaymentMocks.POPayment());

            _orderCalc.GetPurchaseOrderTotal(Arg.Any <HSOrderWorksheet>())
            .Returns(mockedPOTotal);

            // Act
            var result = await _sut.SavePayments(mockOrderID, requested, mockUserToken);

            // Assert
            await _oc.Payments.Received().CreateAsync <HSPayment>(OrderDirection.Incoming, mockOrderID, Arg.Is <HSPayment>(p => p.ID == mockPoPaymentID && p.Amount == mockedPOTotal));
        }