public void Given_An_Order_Accepted_Event_When_Valid_Payment_Details_Have_Been_Recorded_Then_The_Process_Payment_Command_Is_Sent()
        {
            // Arrange
            const int      orderId        = 1;
            const int      customerId     = 2;
            const int      paymentId      = 3;
            PaymentDetails paymentDetails = new PaymentDetails {
                PaymentId = paymentId
            };
            Mock <IBus> mockBus = new Mock <IBus>(MockBehavior.Strict);

            mockBus.Setup(b => b.Send(It.Is <ProcessPaymentV1>(pc =>
                                                               pc.OrderId == orderId &&
                                                               pc.CustomerId == customerId)));
            Mock <IPaymentsDataStore> mockPaymentsDataStore = new Mock <IPaymentsDataStore>(MockBehavior.Strict);

            mockPaymentsDataStore
            .Setup(x => x.CheckExists(orderId))
            .Returns(true);
            Mock <IApplicationLogger>         mockLogger = new Mock <IApplicationLogger>(MockBehavior.Loose);
            IHandleMessage <IOrderAcceptedV1> handler    = new OrderAcceptedV1Handler(mockBus.Object, mockPaymentsDataStore.Object, mockLogger.Object);
            IOrderAcceptedV1 message = new OrderAcceptedV1(customerId, orderId);

            // Act
            handler.Handle(message);

            // Assert
            mockBus.VerifyAll();
            mockPaymentsDataStore.VerifyAll();
        }
示例#2
0
        public void ConfirmOrder(int orderId, int customerId)
        {
            // Guards against duplicate messages - check if this order has already been accepted.
            if (!this.orderAccepted)
            {
                // There could be additional validation here. For example, orders must be confirmed
                // within x time from being "placed". The actual content of the order was validated
                // when it was placed.
                if (!this.orderPlaced)
                {
                    throw new EventSourcingExampleAppException("Can't confirm an order that has not been placed.");
                }

                IOrderAcceptedV1 orderAcceptedV1 = new OrderAcceptedV1(customerId, orderId);
                this.Apply(orderAcceptedV1);
            }
        }
示例#3
0
 public void Handle(OrderAcceptedV1 message)
 {
     this.orderAccepted = true;
 }