private InitiateThirdPartyProcessorPayment CreatePaymentCommand(PricedOrder order)
        {
            var description = "Registration for " + this.ConferenceAlias.Name;
            var totalAmount = order.Total;

            var paymentCommand = new InitiateThirdPartyProcessorPayment()
            {
                PaymentId       = GuidUtil.NewSequentialId(),
                ConferenceId    = this.ConferenceAlias.Id,
                PaymentSourceId = order.OrderId,
                Description     = description,
                TotalAmount     = totalAmount
            };

            return(paymentCommand);
        }
示例#2
0
        public void WhenTheComandForInitiateThePaymentIsSent()
        {
            var paymentCommand =
                new InitiateThirdPartyProcessorPayment
            {
                PaymentId       = Guid.NewGuid(),
                ConferenceId    = registerToConference.ConferenceId,
                PaymentSourceId = orderId,
                Description     = "test",
                TotalAmount     = 249
            };

            paymentId = paymentCommand.PaymentId;

            commandBus.Send(paymentCommand);
        }
        public void when_specifying_registrant_and_credit_card_payment_details_for_a_valid_registration_then_sends_commands_and_redirects_to_payment_action()
        {
            var orderId = Guid.NewGuid();
            var command = new AssignRegistrantDetails
            {
                OrderId   = orderId,
                Email     = "*****@*****.**",
                FirstName = "First Name",
                LastName  = "Last Name",
            };
            InitiateThirdPartyProcessorPayment paymentCommand = null;

            // Arrange
            var seatId = Guid.NewGuid();

            var order = new DraftOrder(orderId, conferenceAlias.Id, DraftOrder.States.ReservationCompleted, 10);

            order.Lines.Add(new DraftOrderItem(seatId, 5)
            {
                ReservedSeats = 5
            });
            Mock.Get <IOrderDao>(this.orderDao)
            .Setup(d => d.FindDraftOrder(orderId))
            .Returns(order);
            Mock.Get <IOrderDao>(this.orderDao)
            .Setup(d => d.FindPricedOrder(orderId))
            .Returns(new PricedOrder {
                OrderId = orderId, Total = 100, OrderVersion = 10
            });

            Mock.Get <ICommandBus>(this.bus)
            .Setup(b => b.Send(It.IsAny <Envelope <ICommand> >()))
            .Callback <Envelope <ICommand> >(
                es => { if (es.Body is InitiateThirdPartyProcessorPayment)
                        {
                            paymentCommand = (InitiateThirdPartyProcessorPayment)es.Body;
                        }
                });

            this.routes.MapRoute("ThankYou", "thankyou", new { controller = "Registration", action = "ThankYou" });
            this.routes.MapRoute("SpecifyRegistrantAndPaymentDetails", "checkout", new { controller = "Registration", action = "SpecifyRegistrantAndPaymentDetails" });

            // Act
            var result =
                (RedirectToRouteResult)this.sut.SpecifyRegistrantAndPaymentDetails(command, RegistrationController.ThirdPartyProcessorPayment, 0).Result;

            // Assert
            Mock.Get <ICommandBus>(this.bus)
            .Verify(b => b.Send(It.Is <Envelope <ICommand> >(es => es.Body == command)), Times.Once());

            Assert.NotNull(paymentCommand);
            Assert.Equal(conferenceAlias.Id, paymentCommand.ConferenceId);
            Assert.Equal(orderId, paymentCommand.PaymentSourceId);
            Assert.InRange(paymentCommand.TotalAmount, 99.9m, 100.1m);

            Assert.Equal("Payment", result.RouteValues["controller"]);
            Assert.Equal("ThirdPartyProcessorPayment", result.RouteValues["action"]);
            Assert.Equal(this.conferenceAlias.Code, result.RouteValues["conferenceCode"]);
            Assert.Equal(paymentCommand.PaymentId, result.RouteValues["paymentId"]);
            Assert.True(((string)result.RouteValues["paymentAcceptedUrl"]).StartsWith("/thankyou"));
            Assert.True(((string)result.RouteValues["paymentRejectedUrl"]).StartsWith("/checkout"));
        }