public async Task <ActionResult <TodoItemDto> > PutTodoItem(long id, TodoItemDto todoItemDto) { if (id != todoItemDto.Id || !ModelState.IsValid) { return(BadRequest()); } var todoItem = _mapper.Map <TodoItem>(todoItemDto); _repo.Update(todoItem); try { await _repo.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!_repo.TodoItemExists(id)) { return(NotFound()); } return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); throw; } return(NoContent()); }
public async Task GetNextSortOrder_ShouldReturnMaximumSortOrderPlusOne_WhenThereAreExistingTodoItems() { // Given: A database with multiple todo items TodoItemRepository todoItemRepository = new TodoItemRepository(this.DbContext); todoItemRepository.Add(new TodoItem() { ApplicationUser = this.CurrentUser, SortOrder = 1 }); todoItemRepository.Add(new TodoItem() { ApplicationUser = this.CurrentUser, SortOrder = 2 }); await todoItemRepository.SaveChangesAsync(); // When: We call GetNextSortOrder int nextSortOrder = todoItemRepository.GetNextSortOrder(); // Then: The sortorder should be three Assert.Equal(3, nextSortOrder); }