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")); }
public async Task HandleAsync(ICommandContext context, AssignRegistrantDetails command) { var order = await context.GetAsync <Order>(command.AggregateRootId); order.AssignRegistrant(command.FirstName, command.LastName, command.Email); }
public ActionResult SpecifyRegistrantDetails(string conferenceCode, Guid orderId, AssignRegistrantDetails command) { if (!ModelState.IsValid) { return(SpecifyRegistrantDetails(conferenceCode, orderId)); } this.commandBus.Send(command); return(RedirectToAction("SpecifyPaymentDetails", new { conferenceCode = conferenceCode, orderId = orderId })); }
public void Handle(ICommandContext context, AssignRegistrantDetails command) { context.Get <Order>(command.AggregateRootId).AssignRegistrant(command.FirstName, command.LastName, command.Email); }