示例#1
0
 public async Task<IActionResult> CreateCats([FromBody] CreateCatDto catDto)
 {
     var cat = new Cat
     {
         Hisses = catDto.Hisses,
         Name = catDto.Name
     };
     await _animalService.InsertCatAsync(cat);
     _memoryCache.Remove(CacheKeys.AllCats);
     var returningCat = (await GetAllCatsFromCacheAsync()).FirstOrDefault(x => x.Id == cat.Id);
     return base.CreatedAtRoute(nameof(GetCat), new { id = cat.Id }, returningCat);
 }
示例#2
0
        public async Task PersistCat_EmptyNameThrowsError()
        {
            var toInsert = new CreateCatDto();

            var buffer      = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(toInsert));
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            var client = Factory.CreateClient();

            // Act
            var responsePost = await client.PostAsync("cats", byteContent);

            responsePost.StatusCode.Should().Be(400);
        }