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); } }
public async Task GetProductById_ReturnsSuccess_GivenValidInput() { using (var client = new TestServerFixture().Client) { var validProduct = new ProductCreateRequestBuilder() .WithDefaultValues() .WithDescription("Integration testing Get ProductById") .WithName("Integration Testing Product") .Build(); HttpContent content = new StringContent(JsonConvert.SerializeObject(validProduct), Encoding.UTF8, "application/json"); var addProductResponse = await client.PostAsync($"/v1/products", content); addProductResponse.EnsureSuccessStatusCode(); Guid.TryParse(JsonConvert.DeserializeObject(await addProductResponse.Content.ReadAsStringAsync()).ToString(), out var validProductId); var response = await client.GetAsync($"/v1/products/{validProductId}"); response.EnsureSuccessStatusCode(); var result = JsonConvert.DeserializeObject <ProductResponseDto>(await response.Content.ReadAsStringAsync()); result.Should().NotBeNull(); result.Id.Should().Be(validProductId); } }
public async Task AddProduct_ReturnsBadRequest_GivenInvalidPayload() { using (var client = new TestServerFixture().Client) { var validProduct = new ProductCreateRequestBuilder() .WithDefaultValues() .WithEmptyName() .Build(); HttpContent content = new StringContent(JsonConvert.SerializeObject(validProduct), Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/v1/products", content); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); } }
public async Task AddProductOption_ReturnsCreatedResponse_GivenValidPayload() { using (var client = new TestServerFixture().Client) { //Arrange var validProductId = await GenerateValidProductId(client); var validProductOption = new ProductOptionCreateRequestBuilder() .WithDefaultValues() .WithProductId(validProductId) .Build(); HttpContent content = new StringContent(JsonConvert.SerializeObject(validProductOption), Encoding.UTF8, "application/json"); //Act var response = await client.PostAsync($"/v1/productoptions", content); //Assert response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(HttpStatusCode.Created); } }