public async Task Post_ValidObject_CallsMapperAndRepoWithCorrectArgsAndReturnsOk() { // Arrange var taskDto = new PostScheduledTaskDTO() { Start = DateTime.UtcNow, End = DateTime.UtcNow }; var task = new ScheduledTask() { //Id = 1, Start = DateTime.UtcNow, End = DateTime.UtcNow }; _mockMapper.Setup(m => m.Map <ScheduledTask>(It.IsAny <PostScheduledTaskDTO>())).Returns(task); // Act var result = await _sut.Post(taskDto); // Assert _mockMapper.Verify(m => m.Map <ScheduledTask>(taskDto)); _mockRepo.Verify(r => r.AddAsync(task)); _mockLUOW.Verify(u => u.CompleteAsync()); Assert.IsAssignableFrom <CreatedResult>(result); }
public async Task <IActionResult> Post([FromBody] PostScheduledTaskDTO task) { if (ModelState.IsValid) { try { var entity = _mapper.Map <ScheduledTask>(task); await CreateScheduledTaskAndNotifyAsync(entity); var uri = Url.Link("TaskGet", new { entity.Id }); return(Created(uri, _mapper.Map <GetScheduledTaskDTO>(entity))); } catch (Exception ex) { _logger.LogError("Threw exception while creating ScheduledTask: {@ex}", ex); } } return(BadRequest()); }