public async Task UpdateTaskList_Success() { var dataGenerationResult = _trackingContext.AddTestData <Domain.Entities.TaskList>(5); var selectedId = dataGenerationResult.Item2[1]; var updatedModel = new Domain.Models.TaskList { Id = selectedId, Name = "NewTaskListName" }; var request = new UpdateTaskListRequest(selectedId, updatedModel); var handler = new UpdateTaskListRequestHandler(_trackingContext, Mapper.Instance); var result = await handler.Handle(request, default(CancellationToken)); Assert.AreEqual(Unit.Value, result); }
public async Task UpdateTaskList_Validation(int id, string taskListName, bool instantiateModel, bool isValid) { Domain.Models.TaskList model = null; if (instantiateModel) { model = new Domain.Models.TaskList { Name = taskListName }; } var request = new UpdateTaskListRequest(id, model); var validator = new UpdateTaskListValidator(); var validationResult = await validator.ValidateAsync(request); Assert.AreEqual(isValid, validationResult.IsValid); }
public async Task <ActionResult> UpdateTaskListAsync(int id, [FromBody] UpdateTaskListRequest request) { if (string.IsNullOrEmpty(request.Title)) { return(BadRequest("Title must not be empty.")); } var taskList = await dbContext.TaskLists.FindAsync(id); if (taskList == null) { return(NotFound()); } taskList.Title = request.Title; dbContext.TaskLists.Update(taskList); await dbContext.SaveChangesAsync(); return(NoContent()); }