Ejemplo n.º 1
0
        public IHttpActionResult Post(PlaceOrderCommand cmd)
        {
            if (Guid.Empty.Equals(cmd.Id))
            {
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden) {
                    Content = new StringContent("order information must be supplied in the POST body"),
                    ReasonPhrase = "Missing Order Id"
                };
                throw new HttpResponseException(response);
            }

            var command = new StartNewOrder(cmd.Id, cmd.ProductId, cmd.Quantity);

            try
            {
                ServiceLocator.OrderCommands.Handle(command);

                var link = new Uri(string.Format("http://localhost:8182/api/orders/{0}", command.Id));
                return Created(link, command);
            }
            catch (ArgumentException argEx)
            {
                return BadRequest(argEx.Message);
            }
        }
Ejemplo n.º 2
0
        public void Should_succeed_when_starting_a_new_order_with_a_valid_product_and_quantity()
        {
            var id = Guid.NewGuid();
            var adminProducts = new FakeAdminProductView();
            var productId = adminProducts.GetProducts().First().Id;

            var command = new StartNewOrder(id, productId, 1);
            var handler = new OrderCommandHandlers(repository, adminProducts);
            handler.Handle(command);

            var order = repository.GetById<Order>(id);
            Assert.Equal(1, order.Quantity);
        }
Ejemplo n.º 3
0
 public void Should_fail_when_starting_a_new_order_and_product_quantity_is_zero()
 {
     var command = new StartNewOrder(Guid.NewGuid(), Guid.NewGuid(), 0);
     var handler = new OrderCommandHandlers(null, new FakeAdminProductView());
     Assert.Throws<ArgumentOutOfRangeException>(() => handler.Handle(command));
 }
Ejemplo n.º 4
0
 public void Should_fail_when_no_product_is_provided_and_a_new_order_is_started()
 {
     var command = new StartNewOrder(Guid.NewGuid(), Guid.Empty, 1);
     var handler = new OrderCommandHandlers(null, new FakeAdminProductView());
     Assert.Throws<ArgumentNullException>(() => handler.Handle(command));
 }