public void GetAllTodoLists() { Mock <ITodoListRepository> repository = new Mock <ITodoListRepository>(); ITodoListService subject = new TodoApi.Services.TodoListService(repository.Object); TodoList todoList1 = new TodoList(); todoList1.Name = "TestList"; todoList1.TodoListId = 1; TodoList todoList2 = new TodoList(); todoList2.Name = "ListSecond"; todoList2.TodoListId = 2; TodoList todoList3 = new TodoList(); todoList3.Name = "BillyBoBobTest"; todoList3.TodoListId = 3; repository.Setup(repo => repo.GetEntities()).Returns(new List <TodoList>() { todoList1, todoList2, todoList3 }.AsQueryable()); var result = subject.GetAllTodoLists(); Assert.IsAssignableFrom <IEnumerable <TodoList> >(result); Assert.Equal(3, result.Count()); Assert.Contains(todoList1, result); Assert.Contains(todoList2, result); Assert.Contains(todoList3, result); }
public void FindTodoListById() { Mock <ITodoListRepository> repository = new Mock <ITodoListRepository>(); ITodoListService subject = new TodoApi.Services.TodoListService(repository.Object); User user = new User(); user.Name = "TestUser"; user.UserId = 4; TodoList todoList = new TodoList(); todoList.Name = "TestList"; todoList.TodoListId = 1; todoList.UserId = 4; todoList.User = user; repository.Setup(repo => repo.GetById(It.IsAny <long>())).Returns(todoList); var result = subject.FindTodoListById(1); Assert.Equal("TestList", result.Name); Assert.Equal(1, result.TodoListId); Assert.Equal(4, result.UserId); Assert.Equal(user, result.User); }
public void CannotFindTodoListWithIdReturnsNull() { Mock <ITodoListRepository> repository = new Mock <ITodoListRepository>(); ITodoListService subject = new TodoApi.Services.TodoListService(repository.Object); repository.Setup(repo => repo.GetById(It.IsAny <long>())); var result = subject.FindTodoListById(1); Assert.Null(result); }