public async Task ShouldProperlyValidatePatchModel()
        {
            var model = new ValuePatchViewModel()
            {
                Id       = 10,
                Capacity = null,
                Name     = ""
            };
            var id      = 10;
            var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, mediaType);

            HttpResponseMessage response = await PatchAsync(_client, $"{route}/{id}", content);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            string responseText = await response.Content.ReadAsStringAsync();

            Assert.Equal(id.ToString(), responseText);
        }
        public async Task ShouldProperlyValidateEmptyPatchModel()
        {
            var model = new ValuePatchViewModel()
            {
                Id       = null,
                Capacity = null,
                Name     = null
            };
            var id      = 10;
            var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, mediaType);

            HttpResponseMessage response = await PatchAsync(_client, $"{route}/{id}", content);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            string responseText = await response.Content.ReadAsStringAsync();

            Assert.Contains("Все поля в модели данных пустые.", responseText);
        }
Exemple #3
0
 public IActionResult Patch(int id, [FromBody] ValuePatchViewModel value)
 {
     return(Ok(id));
 }