コード例 #1
0
        public void PlaceAnOrderThatHitsAnErrorTest()
        {
            order_repository.Setup(x => x.save(It.IsAny<Order>())).Throws(new ArgumentException());

            var message = new OrderPlacingMessage()
            {
                customer_email = "*****@*****.**",
                customer_name = "Adam Aldrich",
                item_ids = new List<long>() { 1, 2 }
            };

            Order order = null;

            try
            {
                order = order_placing_task.place_order(message);
            }
            catch (Exception exception)
            {
                Assert.IsInstanceOf(typeof(DomainException),exception);
            }

            order_repository.Verify(x => x.save(It.IsAny<Order>()));
            Assert.IsNull(order);
            shipping_task.Verify(x => x.ship(order),Times.Never());
            emailing_task.Verify(x => x.send(order),Times.Never());
        }
コード例 #2
0
        public void PlaceAnOrderTest()
        {
            var message = new OrderPlacingMessage()
                              {
                                  customer_email = "*****@*****.**",
                                  customer_name = "Adam Aldrich",
                                  item_ids = new List<long>(){1,2}
                              };

            var order = order_placing_task.place_order(message);

            order_repository.Verify(x=>x.save(It.IsAny<Order>()));
            Assert.IsNotNull(order);
            shipping_task.Verify(x=>x.ship(order));
            emailing_task.Verify(x=>x.send(order));
        }
コード例 #3
0
        public Order place_order(OrderPlacingMessage message)
        {
            var order = new Order(message.customer_name, message.customer_email, get_items(message.item_ids));

            try
            {
                order_repository.save(order);
            }
            catch (Exception)
            {
                throw new DomainException(String.Format("Order for customer {0} could not be completed.",message.customer_name));
            }

            shipping_task.ship(order);
            emailing_task.send(order);
            return order;
        }