예제 #1
0
        public IActionResult Add(NoteForAddingDto noteDto)
        {
            var noteToAdd = _mapper.Map <Note>(noteDto);

            _repo.Add(noteToAdd);

            return(Ok());
        }
예제 #2
0
        public async Task Add_AddsToDbAndReturnsOk_ForProperNote()
        {
            // Arrange
            var client  = _factory.CreateClient();
            var newNote = new NoteForAddingDto()
            {
                Title = "title X", Content = "content X"
            };
            var newNoteJson = JsonSerializer.Serialize(newNote);
            var httpContent = new StringContent(newNoteJson, Encoding.UTF8);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            // Act
            var response = await client.PostAsync(Consts.postUrl, httpContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(_dbContext.Set <Note>().Find(Consts.newNoteId) != null);
        }
예제 #3
0
        public async Task Add_ReturnsBadRequestAndProperContentTypeAndDoesntAddToDb_ForMissingTitle()
        {
            // Arrange
            var client  = _factory.CreateClient();
            var newNote = new NoteForAddingDto()
            {
                Content = "content"
            };
            var newNoteJson = JsonSerializer.Serialize(newNote);
            var httpContent = new StringContent(newNoteJson, Encoding.UTF8);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            // Act
            var response = await client.PostAsync(Consts.postUrl, httpContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.Equal("application/problem+json; charset=utf-8", response.Content.Headers.ContentType.ToString());
            Assert.True(_dbContext.Set <Note>().Find(Consts.newNoteId) == null);
        }