public void If_given_payment_value_is_less_than_or_equal_to_zero_should_throw_exception() { //Given var customer = new Customer { Id = 1 }; var priceToCharge = 0.0m; var paymentMethod = new InHands(false, GetMockPaymentProcessor()); //When... Then Assert.Throws <DomainException>(() => Payment.Create(paymentMethod, customer, priceToCharge, priceToCharge)); }
public async Task If_given_payment_has_less_received_value_than_needed_Then_it_should_return_zero_payment_result() { //Given var method = new InHands(false, null); var customer = new Core.Entities.User.Customer { Id = 1 }; var payment = Payment.Create(method, customer, 9.99m, 12.99m); var inhandsProcessor = new InHandsProcessor(); //When var result = await inhandsProcessor.ProcessAsync(new InHandsChargeRequest(payment)); //Then Assert.Equal(PaymentStatus.PartiallyPaid, result.PaymentStatus); }
public async Task Given_payment_When_try_to_process_it_with_specific_payment_method_Then_expect_payment_object_status_to_change() { //Given var method = new InHands(false, null); var customer = new Core.Entities.User.Customer { Id = 1 }; var payment = Payment.Create(method, customer, 12.99m, 12.99m); var inhandsProcessor = new InHandsProcessor(); //When var result = await inhandsProcessor.ProcessAsync(new InHandsChargeRequest(payment)); //Then Assert.Equal(PaymentStatus.Paid, result.PaymentStatus); }
public async Task When_process_payment_after_validation_should_return_processing_result() { //Given var customer = new Customer { Id = 1 }; var priceToCharge = 12.00m; var expectedPayment = Payment.Create(new InHands(acceptsPartialPayment: false, null), customer, priceToCharge, priceToCharge); var mockPaymentProcessor = GetMockPaymentProcessor(); var paymentMethod = new InHands(acceptsPartialPayment: false, mockPaymentProcessor); var payment = Payment.Create(paymentMethod, customer, priceToCharge, priceToCharge); // When await payment.IssueAsync(); //Then Assert.Equal(PaymentStatus.Paid, payment.Status); }
public async Task Given_payment_value_bigger_than_order_total_When_is_in_hands_method_Then_should_set_change() { //Given var posOrder = GetBasicPOSOrder(); var customer = new Customer { Id = 1 }; var valueToPay = posOrder.OrderTotal * 2; var expectedChange = posOrder.OrderTotal; var paymentService = MockPaymentProcessor(mock => DefineSuccessfulPayment(valueToPay, customer, mock)); var paymentMethod = new InHands(acceptsPartialPayment: false, paymentService); posOrder.DefinePaymentMethod(paymentMethod); //When await posOrder.PayAsync(valueToPay, customer); //Then Assert.Equal(expectedChange, posOrder.Change); }
public async Task On_paying_order_when_payment_is_less_than_remaining_value_to_pay_should_return_failed_status_if_disallowed_to_receive_partial_payments() { //Given var posOrder = GetBasicPOSOrder(); var customer = new Entities.User.Customer { Id = 1 }; var valueToPay = posOrder.OrderTotal / 4.0m; var paymentService = MockPaymentProcessor(mock => DefineSuccessfulPayment(valueToPay, customer, mock)); var paymentMethod = new InHands(acceptsPartialPayment: false, paymentService); // var payment = Payment.Create(paymentMethod, customer, valueToPay); //When posOrder.DefinePaymentMethod(paymentMethod); await posOrder.PayAsync(valueToPay, customer); //Then Assert.Equal(OrderState.Failed, posOrder.State); }
public async Task When_try_to_pay_order_if_is_cancelled_return_failure() { // Given var posOrder = GetBasicPOSOrder(); var customer = new Entities.User.Customer { Id = 1 }; var valueToPay = 12.00m; var paymentMethod = new InHands(acceptsPartialPayment: false, null); //When posOrder.Cancel(); await posOrder.PayAsync(valueToPay, customer); //Then Assert.False(posOrder.PaidOut); Assert.Equal(valueToPay, posOrder.RemainingValueToPay); Assert.Empty(posOrder.Payments); }
public async Task When_pay_whole_remaining_value_on_order_should_add_payment_to_list_change_remaining_value_to_pay_and_change_status_to_paid_out() { //Given var posOrder = GetBasicPOSOrder(); var customer = new Entities.User.Customer { Id = 1 }; var valueToPay = posOrder.OrderTotal; var paymentService = MockPaymentProcessor(mock => mock.Setup(m => m.ProcessAsync(It.IsAny <IPaymentRequest>())) .ReturnsAsync(PaymentResult.Paid(Payment.Create(null, null, valueToPay, valueToPay)))); var paymentMethod = new InHands(acceptsPartialPayment: false, paymentService); //When posOrder.DefinePaymentMethod(paymentMethod); await posOrder.PayAsync(valueToPay, customer); //Then Assert.True(posOrder.PaidOut); Assert.Equal(0, posOrder.RemainingValueToPay); Assert.Single(posOrder.Payments); }