public void IfItemHasQuantity0_ThenReturnInvalidMessage()
 {
     var order = new Order();
       order.AddItem(new OrderItem {Quantity = 0});
       order.GetErrorMessages()
     .Should().Contain("Item 0: Quantity should be greater than 0.");
 }
        public void WhenOrderIsCancelled_ThenReturnItsContent()
        {
            // Arrange
              var order = new Order {Id = 123, Location = Location.TakeAway};
              order.AddItem(new OrderItem(latte, 1, 1, new Dictionary<string, string>()));
              order.Status = OrderStatus.Canceled;
              var orderRepo = new RepositoryStub<Order>(order);

              var app = CreateAppProxy(orderRepo);

              //Act
              var response = app.Get("/trash/order/123/",
                             with =>
                             {
                               with.HttpRequest();
                               with.Header("Accept", "application/xml");
                             });

              // Assert
              response.StatusCode.Should().Be.EqualTo(HttpStatusCode.OK);
              var body = response.BodyAsXml();
              body.Descendants()
            .Single(e => e.Name.LocalName == "location")
            .Value.Should().Be.EqualTo("takeAway");
        }
        public void SetUp()
        {
            order = new Order();
              order.Pay("123", "jose");
              order.Finish();

              representation = OrderRepresentationMapper.Map(order, "http://restbuckson.net/");
        }
        public void WhenOrderExist_ThenCancelAndReturn204()
        {
            // Arrange
              var order = new Order { Id = 123 };
              var app = CreateAppProxy(new RepositoryStub<Order>(order));

              // Act
              var response = app.Delete("/order/123/");

              // Assert
              response.StatusCode.Should().Be.EqualTo(HttpStatusCode.NoContent);
        }
        public void WhenOrderExist_ThenCancel()
        {
            // Arrange
              var order = new Order { Id = 123 };
              var app = CreateAppProxy(new RepositoryStub<Order>(order));

              // Act
              app.Delete("/order/123/");

              // Assert
              order.Status.Should().Be.EqualTo(OrderStatus.Canceled);
        }
        private static void SaveOrder(Order order)
        {
            var dataDirectory = new DirectoryInfo("Data");
            if (!dataDirectory.Exists)
                dataDirectory.Create();

            var fileInfo = new FileInfo(Path.Combine("Data", string.Format("order_{0}_{1}.xml", DateTime.Now.ToFileTime(), order.Id)));

            using (var writer = fileInfo.OpenWrite())
            {
                var xmlSerializer = new XmlSerializer(typeof (Order));
                xmlSerializer.Serialize(writer, order);
            }
        }
        public void ACallToGet_ShouldReturnMovedPermanentlyAndNewLocation()
        {
            // Arrange
              var order = new Order { Id = 123 };
              var app = CreateAppProxy(new RepositoryStub<Order>(order));

              // Act
              var response = app.Delete("/order/123/");
              var responseToGet = app.Get("/order/123/");

              var expected = "http://bogus/trash/order/123";
              responseToGet.StatusCode.Should().Be.EqualTo(HttpStatusCode.MovedPermanently);
              responseToGet.Headers.ContainsKey("Location").Should().Be.True();
              responseToGet.Headers["Location"].Should().Be.EqualTo(expected);
        }
        public void ACallToGetCanceled_ShouldReturnTheOrder()
        {
            // Arrange
              var order = new Order { Id = 123, Status = OrderStatus.Canceled };
              var expectedBody = OrderRepresentationMapper.Map(order, "http://bogus/").ToXmlString();
              order.Status = OrderStatus.Unpaid;
              var app = CreateAppProxy(new RepositoryStub<Order>(order));

              // Act
              var response = app.Delete("/order/123/");
              var responseToGet = app.Get("/trash/order/123/",
              with => with.Header("Accept", "application/xml"));

              responseToGet.StatusCode.Should().Be.EqualTo(HttpStatusCode.OK);
              responseToGet.Body.AsString().Should().Be.EqualTo(expectedBody);
        }
        public void IfTheProductDoesNotAllowCustomization_ThenReturnInvalidMessage()
        {
            var product = new Product
                    {
                      Name = "latte",
                      Customizations = {new Customization {Name = "size", PossibleValues = {"medium", "large"}}}
                    };

              var order = new Order();
              order.AddItem(new OrderItem
                    {
                      Quantity = 1,
                      Product = product,
                      Preferences = {{"milk", "lot"}}
                    });
              order.GetErrorMessages()
            .Should().Contain("Item 0: The product latte does not have a customization: milk/lot.");
        }
        public void WhenOrderExist_ThenUpdateLocation()
        {
            // Arrange
              var order = new Order {Id = 123, Location = Location.InShop};
              var app = CreateAppProxy(new RepositoryStub<Order>(order));

              // Act
              var response = app.Put("/order/123/",
                              with =>
                              {
                                with.HttpRequest();
                                with.Body(new OrderRepresentation() {Location = Location.TakeAway}.ToXmlString());
                              });

              // Assert
              response.StatusCode.Should().Be.EqualTo(HttpStatusCode.NoContent);
              order.Location.Should().Be.EqualTo(Location.TakeAway);
        }
        public void WhenOrderExist_ThenCancel()
        {
            //Arrange
              var order = new Order {Id = 123};
              var app = CreateAppProxy(new RepositoryStub<Order>(order));

              // Act
              var response = app.Post("/order/123/payment/",
                              with =>
                              {
                                with.HttpRequest();
                                var xmlString = new PaymentRepresentation {CardNumber = "321", CardOwner = "Jose"}.ToXmlString();
                                with.Body(xmlString);
                              });

              order.Status.Should().Be.EqualTo(OrderStatus.Paid);
              order.Payment.CardOwner.Should().Be.EqualTo("Jose");
              order.Payment.CreditCardNumber.Should().Be.EqualTo("321");
        }
 public void SetUp()
 {
     order = new Order();
       order.Cancel("You are too slow.");
       representation = OrderRepresentationMapper.Map(order, "http://baseaddress/");
 }
        public void WithTextHtmlDefaultToReturningRestbucksXmlRepresentation()
        {
            // Arrange
              var order = new Order { Id = 123, Location = Location.TakeAway };
              order.AddItem(new OrderItem(latte, 1, 1, new Dictionary<string, string>()));
              var orderRepo = new RepositoryStub<Order>(order);

              var app = CreateAppProxy(orderRepo);

              // Act
              var result = app.Get("/order/123/");

              // Assert
              Assert.That(result.Context.Response.ContentType, Is.EqualTo("application/vnd.restbucks+xml"));
        }
        public void WithRestbuckJsonAcceptHeaderResponseIsJson()
        {
            // Arrange
              var order = new Order { Id = 123, Location = Location.TakeAway };
              order.AddItem(new OrderItem(latte, 1, 1, new Dictionary<string, string>()));
              var orderRepo = new RepositoryStub<Order>(order);

              var app = CreateAppProxy(orderRepo);

              // Act
              var result = app.Get("/order/123/",
                           with =>
                           {
                             with.HttpRequest();
                             with.Header("Accept", "application/vnd.restbucks+json");
                           });

              // Assert
              Assert.That(result.Context.Response.ContentType, Contains.Substring("application/json"));
        }
 public void IfTheOrderDoesNotHaveItems_ThenReturnInvalidMessage()
 {
     var order = new Order();
       order.GetErrorMessages()
     .Should().Contain("The order must include at least one item.");
 }
 public void SetUp()
 {
     order = new Order();
       representation = OrderRepresentationMapper.Map(order, "http://restbuckson.net/");
 }