public void Test_UpdateToDo_Add() { MockTodoRepository mockToDoObj = new MockTodoRepository(); ToDoController tc = new ToDoController(mockToDoObj); ToDo toDoITem = new ToDo { SlNo = 0, Item = "Insert Test", Description = "Test the Post api" }; TodoResponse apiToDoResponse = tc.AddNewToDo(toDoITem); Assert.AreEqual(AppConstants.Success, apiToDoResponse.responseHeader.statusMessage); Assert.AreEqual(HttpStatusCode.OK, apiToDoResponse.responseHeader.statusCode); }
public void Test_UpdateToDo_Id_Empty_Input() { Mock <ITodoRepository> mockRepository = new Mock <ITodoRepository>(); ToDoController tc = new ToDoController(mockRepository.Object); ToDo toDoITem = new ToDo { SlNo = 2, Item = "", Description = "" }; TodoResponse apiToDoResponse = tc.AddNewToDo(toDoITem); Assert.AreEqual(apiToDoResponse.responseHeader.error[0].errorCode, AppConstants.ITEM_EMPTY); Assert.AreEqual(apiToDoResponse.responseHeader.error[0].errorMessage, AppConstants.ITEM_EMPTY_MSG); Assert.AreEqual(apiToDoResponse.responseHeader.error[1].errorCode, AppConstants.DESCRIPTION_EMPTY); Assert.AreEqual(apiToDoResponse.responseHeader.error[1].errorMessage, AppConstants.DESCRIPTION_EMPTY_MSG); Assert.AreEqual(apiToDoResponse.responseHeader.statusMessage, AppConstants.Error); Assert.AreEqual(apiToDoResponse.responseHeader.statusCode, HttpStatusCode.BadRequest); }
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); }