Esempio n. 1
0
        public void ShouldCreateNewProductShort()
        {
            var product = new Product { Name = "Canoli", Category = "Italian Treats" };

            var success = client.Post(product, "products").Is(HttpStatusCode.Created);

            Assert.That(success);
        }
Esempio n. 2
0
        public void ShouldCreateNewProductWithErrors()
        {
            var product = new Product { Name = "Canoli", Category = "" };

            var response = client.Post(product, "products");

            Assert.Throws<ValidationException>(() =>
                response
                    .On(HttpStatusCode.BadRequest, (ValidationError e) => { throw new ValidationException(); })
                    .OnOk(() => { throw new Exception("Expected error"); }));
        }
Esempio n. 3
0
        public void ShouldCreateNewProductShortWithtErrorHandling()
        {
            var product = new Product { Name = "Canoli", Category = "Italian Treats" };

            var response = client.Post(product, "products");

            response.On(HttpStatusCode.BadRequest, (ValidationError e) => { throw new ValidationException(); });
            var success = response.Is(HttpStatusCode.Created);

            Assert.That(success);
        }
Esempio n. 4
0
        public HttpResponseMessage Post(Product product)
        {
            if (string.IsNullOrEmpty(product.Name))
            {
                return new HttpResponseMessage<ValidationError>(
                    new ValidationError("Name required"), HttpStatusCode.BadRequest);
            }

            if (string.IsNullOrEmpty(product.Category))
            {
                return new HttpResponseMessage<ValidationError>(
                    new ValidationError("Category required"), HttpStatusCode.BadRequest);
            }

            return new HttpResponseMessage(HttpStatusCode.Created);
        }
        public HttpResponseMessage Patch(int id, Product product)
        {
            if (string.IsNullOrEmpty(product.Name))
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, new ValidationError("Name required"));
            }

            if (string.IsNullOrEmpty(product.Category))
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, new ValidationError("Category required"));
            }

            var existingProduct = products.FirstOrDefault(p => p.Id == id);

            return existingProduct == null
                ? new HttpResponseMessage(HttpStatusCode.NotFound)
                : new HttpResponseMessage(HttpStatusCode.OK);
        }
Esempio n. 6
0
        public void ShouldUpdateProductsWithPatch()
        {
            var product = new Product { Id = 1, Name = "Vanilla Cake", Category = "Cakes" };

            var success = client.Patch(product, "products/:id").IsOk();

            Assert.That(success);
        }
Esempio n. 7
0
        public void ShouldUpdatePersonWithErrors()
        {
            var product = new Product { Id = 1, Name = "", Category = "Cakes" };

            Assert.Throws<ValidationException>(() =>
                client.Put(product, "products/:id", new { id = 1 })
                    .On(HttpStatusCode.BadRequest, (ValidationError e) => { throw new ValidationException(); }));
        }
Esempio n. 8
0
        public void ShouldUpdatePersonUsingBodyAsSegmentProvider()
        {
            var product = new Product { Id = 1, Name = "Vanilla Cake", Category = "Cakes" };

            var success = client.Put(product, "products/:id").IsOk();

            Assert.That(success);
        }
Esempio n. 9
0
        public void ShouldUpdatePerson()
        {
            var product = new Product { Id = 1, Name = "Vanilla Cake", Category = "Cakes" };

            var success = client.Put(product, "products/:id", new { id = 1 }).IsOk();

            Assert.That(success);
        }