Beispiel #1
0
        public async Task Update_ReturnsOkUpdatesAndAddsToDb_ForProperNote()
        {
            // Arrange
            var client = _factory.CreateClient();
            var note   = new NoteForUpdatingDto()
            {
                Title = "title Y", Content = "content Y"
            };
            var noteJson    = JsonSerializer.Serialize(note);
            var httpContent = new StringContent(noteJson, Encoding.UTF8);

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

            // Act
            var response = await client.PutAsync(Consts.properIdUrl, httpContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var newNote = await _dbContext.FindAsync <Note>(Consts.newNoteId);

            Assert.True(newNote != null);
            Assert.Equal(3, newNote.Version); // The highest version of this note in test db is 2
            var updatedNote = await _dbContext.FindAsync <Note>(1);

            Assert.Equal(updatedNote.Modified.GetDateTimeFormats('G').FirstOrDefault(), newNote.Created.GetDateTimeFormats('G').FirstOrDefault()); // G format = 15/06/2009 13:45:30
        }