public async Task TestGetByIdAsync_CheckNullReferenceException() { // Arrange var mock = new Mock <ITodoItemAsyncRepository>(); int id = 1; mock.Setup(repo => repo.GetByIdAsync(id)).Returns(async() => { return(null); }); var service = new TodoItemService(mock.Object); // Act & Assert await Assert.ThrowsAsync <NullReferenceException>(async() => await service.GetByIdAsync(id)); }
public async Task TestGetByIdAsync_CheckTodoItem() { // Arrange var mock = new Mock <ITodoItemAsyncRepository>(); int id = 1; TodoItem item = new TodoItem { Id = 1, Text = "", Completed = true }; mock.Setup(repo => repo.GetByIdAsync(id)).Returns(async() => { return(item); }); var service = new TodoItemService(mock.Object); // Act var result = await service.GetByIdAsync(id); // Assert Assert.Equal(item.Id, result.Id); }