Exemple #1
0
        public void WhenOrderIsOk_ThenResponseHasStatus201AndLocation()
        {
            var orderRepository = new Mock <IRepository <Order> >();

            orderRepository
            .Setup(or => or.MakePersistent(It.IsAny <Order[]>()))
            .Callback <Order[]>(o => o.First().Id = 123);

            var expectedUriToTheNewOrder =
                resourceLinker.BuildUriString("/order/", OrderResourceHandler.SlashOrderId, new { orderId = "123" });

            var appProxy            = CreateAppProxy(orderRepository.Object);
            var orderRepresentation = new OrderRepresentation()
            {
                Items = { new OrderItemRepresentation()
                          {
                              Name = "latte", Quantity = 1
                          } }
            };
            // act
            var result = appProxy.Post("/orders/",
                                       with =>
            {
                with.Header("Content-Type", "application/xml");
                with.Body(orderRepresentation.ToXmlString());
            });


            result.StatusCode.Should().Be.EqualTo(HttpStatusCode.Created);
            result.Headers["Location"].Should().Be.EqualTo(expectedUriToTheNewOrder);
        }
Exemple #2
0
        public void WhenOrderIsOk_ThenInsertANewOrderWithTheLocationInfo()
        {
            var orderRepository     = new RepositoryStub <Order>();
            var appProxy            = CreateAppProxy(orderRepository);
            var orderRepresentation = new OrderRepresentation()
            {
                Location = Location.InShop,
                Items    = { new OrderItemRepresentation()
                             {
                                 Name = "latte", Quantity = 1
                             } }
            };

            //act
            var result = appProxy.Post("/orders/",
                                       with =>
            {
                with.Header("Content-Type", "application/xml");
                with.Body(orderRepresentation.ToXmlString());
            });

            var order = orderRepository.RetrieveAll().First();

            order.Location.Should().Be.EqualTo(Location.InShop);
        }
Exemple #3
0
        public void WhenItemHasQuantity0_ThenReturn400AndTheProperREasonPhrase()
        {
            var appProxy            = CreateAppProxy();
            var orderRepresentation = new OrderRepresentation()
            {
                Items = { new OrderItemRepresentation()
                          {
                              Name = "latte", Quantity = 0
                          } }
            };

            // act
            var result =
                appProxy.Post("/orders/",
                              with =>
            {
                with.Header("Content-Type", "application/xml");
                with.Body(orderRepresentation.ToXmlString());
            });

            // assert
            result.StatusCode.Should().Be.EqualTo(HttpStatusCode.BadRequest);
            result.Headers["ReasonPhrase"].Should().Be.EqualTo("Invalid entities values");
            result.Body.AsString().Should().Be.EqualTo("Item 0: Quantity should be greater than 0.");
        }
Exemple #4
0
        public void WhenOrderIsOk_ThenInsertANewOrderWithTheProductsAndPrice()
        {
            var orderRepository     = new RepositoryStub <Order>();
            var appProxy            = CreateAppProxy(orderRepository);
            var orderRepresentation = new OrderRepresentation()
            {
                Items = { new OrderItemRepresentation()
                          {
                              Name = "latte", Quantity = 1
                          } }
            };

            //act
            appProxy.Post("/orders/",
                          with =>
            {
                with.Header("Content-Type", "application/xml");
                with.Body(orderRepresentation.ToXmlString());
            });

            // assert
            var order = orderRepository.RetrieveAll().First();

            order.Satisfy(_ => _.Items.Any(i => i.Product == latte && i.UnitPrice == 2.5m && i.Quantity == 1));
        }
Exemple #5
0
        public async Task <ActionResult <IEnumerable <OrderRepresentation> > > FindOrders([FromRoute] string customerId)
        {
            var customer = await this._customers.GetByIdAsync(customerId);

            var orders = customer.Orders;

            return(this.Ok(orders.Select(d => OrderRepresentation.FromEntity(d))));
        }
Exemple #6
0
        public void SetUp()
        {
            order = new Order();
            order.Pay("123", "jose");
            order.Finish();

            representation = OrderRepresentationMapper.Map(order, "http://restbuckson.net/");
        }
Exemple #7
0
        public void SetUp()
        {
            var appHelper = new ResourceHandlerTestBase();
            var app       = appHelper.CreateAppProxy();

            order          = new Order();
            representation = OrderRepresentationMapper.Map(order, appHelper.Container.Resolve <ResourceLinker>(), app.Get("/order").Context);
        }
        public void SetUp()
        {
            order = new Order();
              order.Pay("123", "jose");
              order.Finish();

              representation = OrderRepresentationMapper.Map(order, "http://restbuckson.net/");
        }
        private Order TryBuildOrder(OrderRepresentation orderRepresentation)
        {
            var order = new Order { Date = DateTime.Today, Location = orderRepresentation.Location };
              foreach (var requestedItem in orderRepresentation.Items)
            if (!TryAddOrderItem(order, requestedItem))
              break;

              return order;
        }
        public void SetUp()
        {
            var appHelper = new ResourceHandlerTestBase();
              var app = appHelper.CreateAppProxy();

              order = new Order();
              order.Cancel("You are too slow.");
              representation = OrderRepresentationMapper.Map(order, appHelper.Container.Resolve<ResourceLinker>(), app.Get("/order").Context);
        }
        private Response HandlePost(OrderRepresentation orderRepresentation)
        {
            var order = TryBuildOrder(orderRepresentation);
              if (!order.IsValid())
            return InvalidOrderResponse(order);

              orderRepository.MakePersistent(order);
              return Created(order);
        }
Exemple #12
0
        public OrderRepresentation CreateOrder(OrderRepresentation order)
        {
            var httpClient = GetHttpClient();
            var content    = new ObjectContent <OrderRepresentation>(order, new [] { new RestbucksMediaTypeFormatter() });

            content.Headers.ContentType = new MediaTypeHeaderValue(RepresentationBase.RestbucksMediaType);
            var responseMessage = httpClient.Post(_baseUri + "/order", content);
            var responseContent = responseMessage.Content.ReadAs <OrderRepresentation>(new [] { new RestbucksMediaTypeFormatter() });

            return(responseContent);
        }
        private Response HandlePost(OrderRepresentation orderRepresentation)
        {
            var order = TryBuildOrder(orderRepresentation);

            if (!order.IsValid())
            {
                return(InvalidOrderResponse(order));
            }

            orderRepository.MakePersistent(order);
            return(Created(order));
        }
Exemple #14
0
        public Response Update(int orderId, OrderRepresentation orderRepresentation)
        {
            var order = orderRepository.GetById(orderId);

            if (order == null)
            {
                return(HttpStatusCode.NotFound);
            }

            order.Location = orderRepresentation.Location;
            return(HttpStatusCode.NoContent);
        }
Exemple #15
0
        public async Task <ActionResult <OrderRepresentation> > CreateOrder([FromRoute] string customerId, [FromBody] OrderSpecification spec)
        {
            var customer = await this._customers.GetByIdAsync(customerId);

            var order = await this._orders.AddAsync(customer, spec.Description, spec.Date);

            foreach (OrderLineSpecification line in spec.Lines)
            {
                Product product = await this._products.GetByIdAsync(line.ProductId);

                this._orders.AddLine(order, product, line.Amount);
            }
            return(this.Ok(OrderRepresentation.FromEntity(order)));
        }
Exemple #16
0
        public OrderRepresentation Create(OrderRepresentation orderRepresentation, Uri requestUri)
        {
            var newOrder = _orderRepresentationMapper.GetDomainObject(orderRepresentation);
            var orderId  = _repository.Store(newOrder);

            var orderUri   = RestbucksResources.GetResourceUri <OrderResource>(requestUri, orderId.ToString());
            var paymentUri = RestbucksResources.GetResourceUri <PaymentResource>(requestUri, orderId.ToString());

            var result = _orderRepresentationMapper.GetRepresentation(newOrder);

            result.UpdateLink  = orderUri;
            result.SelfLink    = orderUri;
            result.CancelLink  = orderUri;
            result.PaymentLink = paymentUri;
            return(result);
        }
        private Order TryBuildOrder(OrderRepresentation orderRepresentation)
        {
            var order = new Order {
                Date = DateTime.Today, Location = orderRepresentation.Location
            };

            foreach (var requestedItem in orderRepresentation.Items)
            {
                if (!TryAddOrderItem(order, requestedItem))
                {
                    break;
                }
            }

            return(order);
        }
        public void WhenOrderIsOk_ThenInsertANewOrderWithTheDateTime()
        {
            var orderRepository = new RepositoryStub<Order>();
              var appProxy = CreateAppProxy(orderRepository);
              var orderRepresentation = new OrderRepresentation() {Items = {new OrderItemRepresentation() {Name = "latte", Quantity = 1}}};

              //act
              var result = appProxy.Post("/orders/",
                                 with =>
                                 {
                                   with.Header("Content-Type", "application/xml");
                                   with.Body(orderRepresentation.ToXmlString());
                                 });

              var order = orderRepository.RetrieveAll().First();
              order.Date.Should().Be.EqualTo(DateTime.Today);
        }
        public void WhenAProductDoesNotExist_ThenReturn400AndTheProperREasonPhrase()
        {
            var appProxy = CreateAppProxy();
              var orderRepresentation = new OrderRepresentation()
                                {
                                  Items = {new OrderItemRepresentation() {Name = "beer"}}
                                };

              var result =
            appProxy.Post("/orders/",
                      with =>
                      {
                        with.Header("Content-Type", "application/xml");
                        with.Body(orderRepresentation.ToXmlString());
                      });

              result.StatusCode.Should().Be.EqualTo(HttpStatusCode.BadRequest);
              result.Headers["ReasonPhrase"].Should().Be.EqualTo("We don't offer beer");
        }
        public void WhenItemHasQuantity0_ThenReturn400AndTheProperREasonPhrase()
        {
            var appProxy = CreateAppProxy();
              var orderRepresentation = new OrderRepresentation()
                                {
                                  Items = {new OrderItemRepresentation() {Name = "latte", Quantity = 0}}
                                };

              // act
              var result =
            appProxy.Post("/orders/",
                      with =>
                      {
                        with.Header("Content-Type", "application/xml");
                        with.Body(orderRepresentation.ToXmlString());
                      });

              // assert
              result.StatusCode.Should().Be.EqualTo(HttpStatusCode.BadRequest);
              result.Headers["ReasonPhrase"].Should().Be.EqualTo("Invalid entities values");
              result.Body.AsString().Should().Be.EqualTo("Item 0: Quantity should be greater than 0.");
        }
        public void SerializeOrder()
        {
            var orderRepresentation = new OrderRepresentation
                                {
                                  Cost = 100.4m,
                                  Location = Location.InShop,
                                  Items =
                                    {
                                      new OrderItemRepresentation
                                      {
                                        Name = "latte",
                                        Preferences =
                                          {
                                            {"size", "large"},
                                            {"milk", "skim"}
                                          }
                                      }
                                    }
                                };

              Assert.DoesNotThrow((() => orderRepresentation.ToXmlString()));
        }
        public void WhenAProductDoesNotExist_ThenReturn400AndTheProperREasonPhrase()
        {
            var appProxy            = CreateAppProxy();
            var orderRepresentation = new OrderRepresentation
            {
                Items = { new OrderItemRepresentation {
                              Name = "beer"
                          } }
            };

            var result =
                appProxy.Post("/orders/",
                              with =>
            {
                with.Header("Content-Type", "application/xml");
                with.Body(orderRepresentation.ToXmlString());
            });


            result.StatusCode.Should().Be.EqualTo(HttpStatusCode.BadRequest);
            result.Headers["ReasonPhrase"].Should().Be.EqualTo("We don't offer beer");
        }
        public void SerializeOrder()
        {
            var orderRepresentation = new OrderRepresentation
            {
                Cost     = 100.4m,
                Location = Location.InShop,
                Items    =
                {
                    new OrderItemRepresentation
                    {
                        Name        = "latte",
                        Preferences =
                        {
                            { "size", "large" },
                            { "milk", "skim"  }
                        }
                    }
                }
            };

            Assert.DoesNotThrow((() => orderRepresentation.ToXmlString()));
        }
 public void SetUp()
 {
     order = new Order();
       representation = OrderRepresentationMapper.Map(order, "http://restbuckson.net/");
 }
        public void WhenOrderIsOk_ThenResponseHasStatus201AndLocation()
        {
            var orderRepository = new Mock<IRepository<Order>>();
              orderRepository
            .Setup(or => or.MakePersistent(It.IsAny<Order[]>()))
            .Callback<Order[]>(o => o.First().Id = 123);

              var expectedUriToTheNewOrder =
            resourceLinker.BuildUriString("/order/", OrderResourceModule.SlashOrderId,new { orderId = "123" });

              var appProxy = CreateAppProxy(orderRepository.Object);
              var orderRepresentation = new OrderRepresentation()
                                {
                                  Items = {new OrderItemRepresentation() {Name = "latte", Quantity = 1}}
                                };
              // act
              var result = appProxy.Post("/orders/",
                      with =>
                      {
                        with.Header("Content-Type", "application/xml");
                        with.Body(orderRepresentation.ToXmlString());
                      });

              result.StatusCode.Should().Be.EqualTo(HttpStatusCode.Created);
              result.Headers["Location"].Should().Be.EqualTo(expectedUriToTheNewOrder);
        }
        public void WhenOrderIsOk_ThenInsertANewOrderWithTheProductsAndPrice()
        {
            var orderRepository = new RepositoryStub<Order>();
              var appProxy = CreateAppProxy(orderRepository);
              var orderRepresentation = new OrderRepresentation() {Items = {new OrderItemRepresentation() {Name = "latte", Quantity = 1}}};

              //act
              appProxy.Post("/orders/",
                      with =>
                      {
                        with.Header("Content-Type", "application/xml");
                        with.Body(orderRepresentation.ToXmlString());
                      });

              // assert
              var order = orderRepository.RetrieveAll().First();
              order.Satisfy(_ => _.Items.Any(i => i.Product == latte && i.UnitPrice == 2.5m && i.Quantity == 1));
        }
Exemple #27
0
 public void SetUp()
 {
     order = new Order();
     order.Cancel("You are too slow.");
     representation = OrderRepresentationMapper.Map(order, "http://baseaddress/");
 }
 public Order GetDomainObject(OrderRepresentation orderRepresentation)
 {
     return(new Order(orderRepresentation.Location, orderRepresentation.Items.Select(_itemMapper.GetDomainObject)));
 }
Exemple #29
0
 public void SetUp()
 {
     order          = new Order();
     representation = OrderRepresentationMapper.Map(order, "http://restbuckson.net/");
 }
 public void SetUp()
 {
     order = new Order();
       order.Cancel("You are too slow.");
       representation = OrderRepresentationMapper.Map(order, "http://baseaddress/");
 }