public async Task GetItem_WhenIdNotExist_ReturnsNotFound() { var repoStub = new Mock <IRepository>(); repoStub.Setup(repo => repo.Get <ToDoItem>(It.IsAny <int>())).ReturnsAsync(null as ToDoItem); var controller = new ToDoController(repoStub.Object); var res = await controller.GetItem(0); Assert.IsType <NotFoundResult>(res.Result); }
public async Task GetItem_WithAnId_ReturnsAToDoItem(int id) { var repoStub = new Mock <IRepository>(); repoStub.Setup(repo => repo.Get <ToDoItem>(It.IsAny <int>())).ReturnsAsync(GetTestTodos().Find(item => item.Id == id)); var controller = new ToDoController(repoStub.Object); var res = await controller.GetItem(id); var item = Assert.IsType <ToDoItem>(res.Value); Assert.Equal(id, item.Id); }