public void ToIdExists_False() { MockTodoRepository mockObj = new MockTodoRepository(); List <ToDo> getAllTodo = mockObj.getAllTodo(); bool isExist = ValidateUtility.ToDoIdExists(getAllTodo, 12); Assert.AreEqual(false, isExist); }
public void ToDoExists_True() { ToDo toDoITem = new ToDo { SlNo = 1, Item = "Item1", Description = "Desc Item1" }; MockTodoRepository mockObj = new MockTodoRepository(); List <ToDo> getAllTodo = mockObj.getAllTodo(); bool isExist = ValidateUtility.ToDoExists(getAllTodo, toDoITem); Assert.AreEqual(true, isExist); }
public void Test_GetToDoes_All() { MockTodoRepository mockToDoObj = new MockTodoRepository(); ToDoController tc = new ToDoController(mockToDoObj); // injecting mock repo into controller TodoResponse apiToDoResponse = tc.GetToDoes(); List <ToDo> ltsToDo = mockToDoObj.getAllTodo().ToList(); int iCountApi = apiToDoResponse.responseBody.todo.Count; int iCountMock = ltsToDo.Count; Assert.AreEqual(iCountApi, iCountMock); for (int i = 0; i < iCountApi; i++) { Assert.AreEqual(apiToDoResponse.responseBody.todo[i].Item, ltsToDo[i].Item); Assert.AreEqual(apiToDoResponse.responseBody.todo[i].Description, ltsToDo[i].Description); Assert.AreEqual(apiToDoResponse.responseBody.todo[i].SlNo, ltsToDo[i].SlNo); } }
public void Test_UpdateToDo_Internal_Server_Error() { Mock <ITodoRepository> mockRepository = new Mock <ITodoRepository>(); mockRepository.Setup(mr => mr.insert(It.IsAny <ToDo>())).Returns(0); ToDoController tc = new ToDoController(mockRepository.Object); MockTodoRepository mockObj = new MockTodoRepository(); List <ToDo> getAllTodo = mockObj.getAllTodo(); mockRepository.Setup(mr => mr.getAllTodo()).Returns(getAllTodo); ToDo toDoITem = new ToDo { SlNo = 2, Item = "Item", Description = "Desc" }; TodoResponse apiToDoResponse = tc.AddNewToDo(toDoITem); Assert.AreEqual(apiToDoResponse.responseHeader.error[0].errorCode, AppConstants.INSERT_FAILED); Assert.AreEqual(apiToDoResponse.responseHeader.error[0].errorMessage, AppConstants.INSERT_FAILED_MSG); Assert.AreEqual(apiToDoResponse.responseHeader.statusMessage, AppConstants.Error); Assert.AreEqual(apiToDoResponse.responseHeader.statusCode, HttpStatusCode.InternalServerError); }
public void Test_UpdateToDo_Item_Already_Exist() { Mock <ITodoRepository> mockRepository = new Mock <ITodoRepository>(); mockRepository.Setup(mr => mr.save(It.IsAny <ToDo>())).Returns(1); MockTodoRepository mockObj = new MockTodoRepository(); List <ToDo> getAllTodo = mockObj.getAllTodo(); mockRepository.Setup(mr => mr.getAllTodo()).Returns(getAllTodo); ToDoController tc = new ToDoController(mockRepository.Object); ToDo toDoITem = new ToDo { SlNo = 1, Item = "Item1", Description = "Desc Item1" }; TodoResponse apiToDoResponse = tc.AddNewToDo(toDoITem); Assert.AreEqual(apiToDoResponse.responseHeader.statusMessage, AppConstants.Error); Assert.AreEqual(apiToDoResponse.responseHeader.statusCode, HttpStatusCode.Conflict); Assert.AreEqual(apiToDoResponse.responseHeader.error[0].errorCode, AppConstants.TODO_ALREADY_EXIST); Assert.AreEqual(apiToDoResponse.responseHeader.error[0].errorMessage, AppConstants.TODO_ALREADY_EXIST_MSG); }