public async Task <ActionResult> PostAsync(TaskListRequest taskListRequest) { if (taskListRequest == null) { return(new BadRequestResult()); } var taskLisst = await _taskListService.AddAsync(taskListRequest.MapToTaskList(GetCurrentUserId())); return(new JsonResult(taskLisst)); }
public async Task <ActionResult <TaskListDto> > CreateAsync([FromBody][Required] TaskListUpdateDto taskListUpdateDto, CancellationToken token) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string userId = User.FindFirst(JwtRegisteredClaimNames.Sub).Value; TaskList addedList = await _taskListService.AddAsync(new TaskList { Name = taskListUpdateDto.Name, UserId = userId }, token); TaskListDto addedListDto = _mapper.MapToDto(addedList); return(CreatedAtAction(nameof(GetByIdAsync), new { id = addedListDto.Id }, addedListDto)); }
public async System.Threading.Tasks.Task AddAsync_TaskList_ValidRequest_DelegatesToRepo() { var taskList = new TaskList { Title = "New List", OwnerId = Guid.NewGuid().ToString(), CreatedDate = DateTimeOffset.Now }; var newId = Guid.NewGuid(); var returnList = new TaskList { Id = newId, Title = taskList.Title, OwnerId = taskList.OwnerId, CreatedDate = taskList.CreatedDate }; _taskListRepo.Setup(x => x.AddAsync(taskList)).Verifiable(); var createdList = await _classInTest.AddAsync(taskList); _taskListRepo.Verify(m => m.AddAsync(It.IsAny <TaskList>()), Times.Once()); }