示例#1
0
        public async Task UpdateCoffeeIntegrationTests_Put_Coffee_Returns_Expected_All_Validation_Errors()
        {
            // Arrange
            var client = this.fixture.factory.CreateClient();

            // Act
            var coffeeItem = new CoffeeItemUpdate()
            {
                Id              = 2,
                Name            = "",
                Description     = "",
                CaffeineContent = 9999
            };

            var payload    = JsonConvert.SerializeObject(coffeeItem);
            var putContent = new StringContent(payload, Encoding.UTF8, "application/json");

            var response = await client.PutAsync("/api/coffee/3", putContent);

            var json = await response.Content.ReadAsStringAsync();

            var content = JsonConvert.DeserializeObject <ValidationErrorsDto>(json);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.NotNull(content);
            Assert.Equal(6, content.ValidationErrors.Count());
        }
示例#2
0
        public async Task UpdateCoffeeIntegrationTests_Put_Coffee_Returns_Expected_Caffeine_Content_Validation_Errors()
        {
            // Arrange
            var client = this.fixture.factory.CreateClient();

            // Act
            var coffeeItem = new CoffeeItemUpdate()
            {
                Id              = 2,
                Name            = "Valid name",
                Description     = "Valid description",
                CaffeineContent = 99999
            };

            var payload    = JsonConvert.SerializeObject(coffeeItem);
            var putContent = new StringContent(payload, Encoding.UTF8, "application/json");

            var response = await client.PutAsync("/api/coffee/2", putContent);

            var json = await response.Content.ReadAsStringAsync();

            var content = JsonConvert.DeserializeObject <ValidationErrorsDto>(json);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            Assert.NotNull(content);
            Assert.Equal(1, content.ValidationErrors.Count());

            var firstValidationError = content.ValidationErrors.ElementAt(0);

            Assert.Equal("CaffeineContent", firstValidationError.Field);
            Assert.Equal("Caffeine Content should be between 5 and 400.", firstValidationError.Message);
        }
示例#3
0
        public async Task UpdateCoffeeIntegrationTests_Put_Coffee_Returns_Not_Found_If_Entity_Does_Not_Exist()
        {
            // Arrange
            var client = this.fixture.factory.CreateClient();

            // Act
            var coffeeItem = new CoffeeItemUpdate()
            {
                Id              = 99,
                Name            = "Updated Name",
                Description     = "I updated this description",
                CaffeineContent = 55
            };

            var payload    = JsonConvert.SerializeObject(coffeeItem);
            var putContent = new StringContent(payload, Encoding.UTF8, "application/json");

            var response = await client.PutAsync("/api/coffee/99", putContent);

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
示例#4
0
        public async Task UpdateCoffeeIntegrationTests_Put_Coffee_Returns_Correct_Data()
        {
            // Arrange
            var client = this.fixture.factory.CreateClient();

            // Act
            var coffeeItem = new CoffeeItemUpdate()
            {
                Id              = 2,
                Name            = "Updated Name",
                Description     = "I updated this description",
                CaffeineContent = 55
            };

            var payload    = JsonConvert.SerializeObject(coffeeItem);
            var putContent = new StringContent(payload, Encoding.UTF8, "application/json");

            var response = await client.PutAsync("/api/coffee/2", putContent);

            // Assert
            response.EnsureSuccessStatusCode();

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }