public async Task UpdateTodoAsync_MakesCorrectCalls() { // Arrange var todoDTO = new UpdatedTodoDTO() { Id = 1, Name = "Updated Todo", IsComplete = true }; var todo = new Todo() { Id = 1, Name = "Updated Todo", IsComplete = true }; var mockedMapper = new Mock <IMapper>(); var mockedRepository = new Mock <ITodosRepository>(); mockedMapper.Setup(m => m.Map <UpdatedTodoDTO, Todo>(todoDTO)).Returns(todo); mockedRepository.Setup(r => r.UpdateTodoAsync(todo)); var service = new TodosService(mockedMapper.Object, mockedRepository.Object); // Action await service.UpdateTodoAsync(todoDTO); // Assert mockedMapper.Verify(m => m.Map <UpdatedTodoDTO, Todo>(todoDTO), Times.Once()); mockedRepository.Verify(r => r.UpdateTodoAsync(todo), Times.Once()); }
public async Task UpdateTodoAsync_RecordNotFoundExceptionThrown_ThrowsTodoNotFoundException() { // Arrange var todoDTO = new UpdatedTodoDTO(); var mockedMapper = new Mock <IMapper>(); var mockedRepository = new Mock <ITodosRepository>(); mockedRepository.Setup(r => r.UpdateTodoAsync(It.IsAny <Todo>())).Throws <RecordNotFoundException>(); var service = new TodosService(mockedMapper.Object, mockedRepository.Object); // Action and Assert await Assert.ThrowsAsync <TodoNotFoundException>(async() => { await service.UpdateTodoAsync(todoDTO); }); }
public async Task UpdateTodoAsync_ConcurrentAccessExceptionAndItemDoesNotExist_ThrowsTodoNotFoundException() { // Arrange var todoDTO = new UpdatedTodoDTO() { Id = 1 }; var mockedMapper = new Mock <IMapper>(); var mockedRepository = new Mock <ITodosRepository>(); mockedRepository.Setup(r => r.UpdateTodoAsync(It.IsAny <Todo>())).Throws <ConcurrentAccessException>(); mockedRepository.Setup(r => r.Exists(It.IsAny <long>())).ReturnsAsync(false); var service = new TodosService(mockedMapper.Object, mockedRepository.Object); // Action and Assert await Assert.ThrowsAsync <TodoNotFoundException>(async() => { await service.UpdateTodoAsync(todoDTO); }); }