예제 #1
0
        public async Task No_discount_is_applied()
        {
            var saga = new OrderDiscountPolicy()
            {
                Data = new OrderDiscountPolicy.OrderDiscountData()
                {
                    CustomerId = 123
                }
            };
            var context = new TestableMessageHandlerContext();

            var orderPlaced = new OrderPlacedEvent()
            {
                CustomerId       = 123,
                OrderId          = 789,
                OrderTotalAmount = 100
            };

            await saga.Handle(orderPlaced, context);

            var processOrderMessage = context.SentMessages.SingleOrDefault(m => m.Message.GetType() == typeof(ProcessOrder));

            Assert.IsNotNull(processOrderMessage);
            Assert.AreEqual(0, processOrderMessage.Message <ProcessOrder>().Discount);
        }
예제 #2
0
        public async Task DeductFromRunningTotal_timeout_is_requested()
        {
            var saga = new OrderDiscountPolicy()
            {
                Data = new OrderDiscountPolicy.OrderDiscountData()
                {
                    CustomerId = 123
                }
            };
            var context = new TestableMessageHandlerContext();

            int expectedOrderTotalAmount = 100;
            var orderPlaced = new OrderPlacedEvent()
            {
                CustomerId       = 123,
                OrderId          = 789,
                OrderTotalAmount = expectedOrderTotalAmount
            };

            await saga.Handle(orderPlaced, context);

            var deductFromRunningTotalTimeout = context.SentMessages.SingleOrDefault(m => m.Message.GetType() == typeof(OrderDiscountPolicy.DeductFromRunningTotal));

            Assert.IsNotNull(deductFromRunningTotalTimeout);
            Assert.AreEqual(expectedOrderTotalAmount, deductFromRunningTotalTimeout.Message <OrderDiscountPolicy.DeductFromRunningTotal>().OrderTotalAmount);
        }