示例#1
0
        protected OrderAggregate CreateNewOrder()
        {
            DateTimeUtil.MockNow(createdOn);
            var sut = new OrderAggregate();

            sut.Create(orderId, customerId, senderId);
            return(sut);
        }
        public async Task Handle(PlaceOrderCommand message, IMessageHandlerContext context)
        {
            #region ThrowTransientException
            // Uncomment to test throwing transient exceptions
            //if (random.Next(0, 5) == 0)
            //{
            //    throw new Exception("Oops");
            //}
            #endregion

            #region ThrowFatalException
            // Uncomment to test throwing fatal exceptions
            throw new Exception("BOOM");
            #endregion
            // Create a new random order
            var order = OrderAggregate.Create();
            // Save order in database
            await _orderRepository.Create(order);

            // Send the order placed event
            await context.Publish(new OrderPlacedEvent(order.AggregateId, order.ItemCount, order.TotalAmount));
        }