Ejemplo n.º 1
0
        public async Task UpdateProductOption_ReturnsCreatedResponse_GivenValidPayload()
        {
            using (var client = new TestServerFixture().Client)
            {
                //Arrange
                var validProductId = await GenerateValidProductId(client);

                var validProductOptionId = await GenerateValidProductOptionId(client, validProductId);

                var validUpdateProductOption = new ProductOptionUpdateRequestBuilder()
                                               .WithDefaultValues()
                                               .WithId(validProductOptionId)
                                               .WithProductId(validProductId)
                                               .WithDescription("Update Product Option Integration testing")
                                               .WithName("Integration Testing Update Product Option")
                                               .Build();

                HttpContent updateProductOptionPayload = new StringContent(JsonConvert.SerializeObject(validUpdateProductOption),
                                                                           Encoding.UTF8, "application/json");

                //Act
                var response = await client.PutAsync($"/v1/productoptions/{validProductOptionId}", updateProductOptionPayload);

                //Assert
                response.EnsureSuccessStatusCode();
                response.StatusCode.Should().Be(HttpStatusCode.Created);
            }
        }
Ejemplo n.º 2
0
        public async Task UpdateProduct_ReturnsCreatedResponse_GivenValidPayload()
        {
            using (var client = new TestServerFixture().Client)
            {
                var validAddProduct = new ProductCreateRequestBuilder()
                                      .WithDefaultValues()
                                      .WithDescription("Integration testing Add Product")
                                      .WithName("Integration Testing Add Product")
                                      .Build();

                HttpContent addProductPayload = new StringContent(JsonConvert.SerializeObject(validAddProduct),
                                                                  Encoding.UTF8, "application/json");
                var addProductResponse = await client.PostAsync($"/v1/products", addProductPayload);

                addProductResponse.EnsureSuccessStatusCode();

                Guid.TryParse(JsonConvert.DeserializeObject(await addProductResponse.Content.ReadAsStringAsync()).ToString(),
                              out var validProductId);
                var validUpdateProduct = new ProductUpdateRequestBuilder()
                                         .WithDefaultValues()
                                         .WithId(validProductId)
                                         .WithDescription("UpdateProduct Integration testing")
                                         .WithName("Integration Testing UpdateProduct")
                                         .Build();

                HttpContent updateProductPayload = new StringContent(JsonConvert.SerializeObject(validUpdateProduct),
                                                                     Encoding.UTF8, "application/json");
                var response = await client.PutAsync($"/v1/products/{validProductId}", updateProductPayload);

                response.EnsureSuccessStatusCode();
                response.StatusCode.Should().Be(HttpStatusCode.Created);
            }
        }
Ejemplo n.º 3
0
        public async Task UpdateProduct_ReturnsNotFound_GivenNonExistentPayload()
        {
            using (var client = new TestServerFixture().Client)
            {
                var nonExistentProduct = new ProductUpdateRequestBuilder()
                                         .WithDefaultValues()
                                         .Build();

                HttpContent content = new StringContent(JsonConvert.SerializeObject(nonExistentProduct),
                                                        Encoding.UTF8, "application/json");
                var response = await client.PutAsync($"/v1/products/{nonExistentProduct.Id}", content);

                response.StatusCode.Should().Be(HttpStatusCode.NotFound);
            }
        }
Ejemplo n.º 4
0
        public async Task UpdateProduct_ReturnsBadRequest_GivenInvalidPayload()
        {
            using (var client = new TestServerFixture().Client)
            {
                var validProduct = new ProductUpdateRequestBuilder()
                                   .WithId(Guid.NewGuid())
                                   .Build();

                HttpContent content = new StringContent(JsonConvert.SerializeObject(validProduct),
                                                        Encoding.UTF8, "application/json");
                var response = await client.PutAsync($"/v1/products/{validProduct.Id}", content);

                response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 5
0
        public async Task UpdateProductOption_ReturnsBadRequest_GivenMismatchOfProductOptionIdBetweenRouteAndPayload()
        {
            using (var client = new TestServerFixture().Client)
            {
                var validProductOption = new ProductOptionUpdateRequestBuilder().
                                         WithDefaultValues()
                                         .Build();
                var mismatchedProductOptionId = Guid.NewGuid();

                HttpContent content = new StringContent(JsonConvert.SerializeObject(validProductOption),
                                                        Encoding.UTF8, "application/json");
                var response = await client.PutAsync($"/v1/products/{mismatchedProductOptionId}", content);

                response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            }
        }