public void Test_ToDoExists_False() { MockTodoRepository mockToDoObj = new MockTodoRepository(); ToDoController tc = new ToDoController(mockToDoObj); bool apiResponse = ValidateUtility.ToDoIdExists(TodoTestData.GetMockAllToDo(), 50); Assert.IsFalse(apiResponse); }
/// <summary> /// Constructor method to Initialize the data and Mock the db functions: Testing Using moq /// </summary> public ToDoControllerTest() { List <ToDo> testToDo = TodoTestData.GetMockAllToDo(); Mock <ITodoRepository> mockRepository = new Mock <ITodoRepository>(); //Mocking the Respone //Return all To Do items mockRepository.Setup(mr => mr.getAllTodo()).Returns(testToDo); //Return To Do item by Id mockRepository.Setup(mr => mr.getTodoById(It.IsAny <int>())).Returns((int i) => testToDo.Where(x => x.SlNo == i).Single()); // Complete the setup and save our Mock To Do Repository this.MockRepository = mockRepository.Object; }
public void Test_ToDoExists_True() { bool apiResponse = ValidateUtility.ToDoIdExists(TodoTestData.GetMockAllToDo(), 2); Assert.IsTrue(apiResponse); }