public void Handle(StartNewOrder message)
        {
            ValidateProduct(message.ProductId);
            var order = new Domain.Order(message.Id, message.ProductId, message.Quantity);

            repository.Save(order);
        }
Example #2
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));
            }
        }
        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 FakeProductsProductView());

            Assert.Throws <ArgumentOutOfRangeException>(() => handler.Handle(command));
        }
        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 FakeProductsProductView());

            Assert.Throws <ArgumentNullException>(() => handler.Handle(command));
        }
Example #5
0
        public ActionResult Post(PlaceOrderCommand cmd)
        {
            if (Guid.Empty.Equals(cmd.Id))
            {
                return(Problem(
                           title: "Missing Order Id",
                           detail: "order information must be supplied in the POST body",
                           statusCode: StatusCodes.Status400BadRequest
                           ));
            }

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

            try
            {
                ServiceLocator.OrderCommands.Handle(command);

                var link = new Uri(string.Format("https://localhost:44359/api/orders/{0}", command.Id));
                return(Created(link, command));
            }
            catch (ArgumentException argEx)
            {
                return(BadRequest(argEx.Message));
            }
        }
        public void Should_succeed_when_starting_a_new_order_with_a_valid_product_and_quantity()
        {
            var id = Guid.NewGuid();
            var ProductsProducts = new FakeProductsProductView();
            var productId        = ProductsProducts.GetProducts().First().Id;

            var command = new StartNewOrder(id, productId, 1);
            var handler = new OrderCommandHandlers(repository, ProductsProducts);

            handler.Handle(command);

            var order = repository.GetById <Order>(id);

            Assert.Equal(1, order.Quantity);
        }