public async Task Delete_ValidObject_CallsRepoWithCorrectArgsAndReturnsNoContent() { // Arrange Guid id = Guid.NewGuid(); var taskDto = new PutScheduledTaskDTO() { Start = DateTime.UtcNow, End = DateTime.UtcNow }; var task = new ScheduledTask() { Id = Guid.NewGuid(), Start = DateTime.UtcNow, End = DateTime.UtcNow }; _mockRepo.Setup(r => r.FindAsync(It.IsAny <Guid>())).ReturnsAsync(task); // Act var result = await _sut.Delete(id); // Assert _mockRepo.Verify(r => r.FindAsync(id)); _mockRepo.Verify(r => r.Delete(task)); _mockLUOW.Verify(u => u.CompleteAsync()); Assert.IsAssignableFrom <NoContentResult>(result); }
public async Task Put_ValidObject_CallsMapperAndRepoWithCorrectArgsAndReturnsOk() { // Arrange Guid id = Guid.NewGuid(); var taskDto = new PutScheduledTaskDTO() { Start = DateTime.UtcNow, End = DateTime.UtcNow }; var task = new ScheduledTask() { //Id = 1, Start = DateTime.UtcNow, End = DateTime.UtcNow }; _mockRepo.Setup(r => r.FindAsync(It.IsAny <Guid>())).ReturnsAsync(task); // Act var result = await _sut.Put(id, taskDto); // Assert _mockMapper.Verify(m => m.Map(taskDto, task)); _mockRepo.Verify(r => r.FindAsync(id)); _mockLUOW.Verify(u => u.CompleteAsync()); Assert.IsAssignableFrom <OkObjectResult>(result); }
public async Task Put_WhenCalled_CallsRepoAndMapperWithCorrectArgs() { // Arrange var tasks = new ScheduledTaskDataModel[] { new ScheduledTaskDataModel() { //Id = 1, Start = DateTime.UtcNow, End = DateTime.UtcNow } }; var taskDTOs = new PutScheduledTaskDTO[] { new PutScheduledTaskDTO() { //Id = 1, Start = DateTime.UtcNow, End = DateTime.UtcNow } }; _mockMapper.Setup(m => m.Map <IEnumerable <ScheduledTaskDataModel> >(It.IsAny <IEnumerable <PutScheduledTaskDTO> >())) .Returns(tasks); // Act var result = await _sut.Put(taskDTOs); // Assert _mockMapper.Verify(m => m.Map <IEnumerable <ScheduledTaskDataModel> >(taskDTOs)); _mockRepo.Verify(m => m.AddOrUpdateScheduledTasksAsync(tasks, _userId)); }
public async Task <IActionResult> Put(Guid id, [FromBody] PutScheduledTaskDTO taskDto) { if (ModelState.IsValid) { try { var task = await _scheduledTaskRepo.FindAsync(id); if (task == null) { var entity = _mapper.Map <ScheduledTask>(taskDto); entity.ApplicationUserId = User.GetUserId(); await CreateScheduledTaskAndNotifyAsync(entity); return(Ok(_mapper.Map <GetScheduledTaskDTO>(entity))); } _mapper.Map(taskDto, task); await _unitOfWork.CompleteAsync(); _ = _notificationService.NotifyAsync(User.GetUserId(), Request.Headers[Constants.DEVICE_ID_HEADER_NAME]); return(Ok(_mapper.Map <GetScheduledTaskDTO>(task))); } catch (Exception ex) { _logger.LogError("Threw exception while creating ScheduledTask: {@ex}", ex); } } return(BadRequest()); }
public async Task Put_WhenCalledWithValidArgs_ReturnsNoContent() { // Arrange var taskDTOs = new PutScheduledTaskDTO[] { new PutScheduledTaskDTO() { //Id = 1, Start = DateTime.UtcNow, End = DateTime.UtcNow } }; // Act var result = await _sut.Put(taskDTOs); // Assert Assert.IsAssignableFrom <NoContentResult>(result); }