public void TestToDoIndex() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository)) { using (ToDoController controller = new ToDoController(businessLogic)) { // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); } } } }
public void TestDeleteWrongId() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository)) { using (ToDoController controller = new ToDoController(businessLogic)) { // Act controller.ModelState.AddModelError("test", "test"); var result = controller.Delete(45); //Assert Assert.IsTrue(result.Data.ToString() == "error", "Since the id is not present so throwing error."); } } } }
public void TestCreateWrongData() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository)) { using (ToDoController controller = new ToDoController(businessLogic)) { // Act ToDoItem item = new ToDoItem(); item.Name = ""; controller.ModelState.AddModelError("test", "test"); var result = controller.Create(item); //Assert Assert.IsTrue(result.Data.ToString() == "error", "Since the model is wrong so throwing error."); } } } }
public ActionResult ToDo_Search(string keySearch, int currentPage) { var todoBl = new ToDoBL(); List <ToDoInfo> lstToDo = new List <ToDoInfo>(); try { decimal totalRecord = 0; lstToDo = todoBl.Search(currentPage, ref totalRecord, keySearch); string htmlPaging = CommonFuc.Get_HtmlPaging <ToDoInfo>((int)totalRecord, 1, "công việc"); ViewBag.Paging = htmlPaging; ViewBag.ListToDo = lstToDo; ViewBag.SumRecord = totalRecord; } catch (Exception ex) { NaviCommon.Common.log.Error(ex.ToString()); } return(PartialView("~/Areas/ToDo/Views/ToDo/_Partial_ToDo_List.cshtml")); }
public ActionResult ToDo_Display() { var todoBl = new ToDoBL(); List <ToDoInfo> lstToDo = new List <ToDoInfo>(); try { decimal totalRecord = 0; lstToDo = todoBl.Search(1, ref totalRecord); string htmlPaging = CommonFuc.Get_HtmlPaging <ToDoInfo>((int)totalRecord, 1, "công việc"); ViewBag.Paging = htmlPaging; ViewBag.ListToDo = lstToDo; ViewBag.SumRecord = totalRecord; } catch (Exception ex) { NaviCommon.Common.log.Error(ex.ToString()); } return(View("~/Areas/ToDo/Views/ToDo/ToDo_Display.cshtml")); }
public void TestCreateAccurateData() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository)) { using (ToDoController controller = new ToDoController(businessLogic)) { // Act ToDoItem item = new ToDoItem(); item.Name = "Test item"; var result = controller.Create(item); var data = result.Data.GetType().GetProperty("data"); var dataVal = (ToDoItem)data.GetValue(result.Data, null); //Assert Assert.IsTrue(dataVal.Id > 0, "Successfully created, ToDo Id retrived:" + dataVal.Id); } } } }
public void TestUpdateWrongData() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository, new DataCache())) { using (ToDoController controller = new ToDoController(businessLogic)) { using (var repositoryGet = new ToDoRepository()) { using (var businessLogicGet = new ToDoBL(repositoryGet, new DataCache())) { using (ToDoController controllerGet = new ToDoController(businessLogicGet)) { // Act var result = controllerGet.GetAll(); var data = result.Data.GetType().GetProperty("data"); var dataVal = (List <ToDoItem>)data.GetValue(result.Data, null); if (dataVal != null && dataVal.Count > 0) { var item = dataVal[dataVal.Count - 1]; item.Name = ""; controller.ModelState.AddModelError("test", "test"); var resultUpdate = controller.Update(item); //Assert Assert.IsTrue(resultUpdate.Data.ToString() == "error", "Validation failed so error occur."); } else { Assert.IsTrue(true); } } } } } } } }
public void TestUpdateAccurateData() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository, new DataCache())) { using (ToDoController controller = new ToDoController(businessLogic)) { using (var repositoryGet = new ToDoRepository()) { using (var businessLogicGet = new ToDoBL(repositoryGet, new DataCache())) { using (ToDoController controllerGet = new ToDoController(businessLogicGet)) { // Act var result = controllerGet.GetAll(); var data = result.Data.GetType().GetProperty("data"); var dataVal = (List <ToDoItem>)data.GetValue(result.Data, null); if (dataVal != null && dataVal.Count > 0) { var item = dataVal[dataVal.Count - 1]; item.Name = "test update"; var resultUpdate = controller.Update(item); //Assert Assert.IsTrue(resultUpdate.Data != null, "Successfully updated"); } else { Assert.IsTrue(true); } } } } } } } }
public void TestDeleteAccurateId() { // Arrange using (var repository = new ToDoRepository()) { using (var businessLogic = new ToDoBL(repository, new DataCache())) { using (ToDoController controller = new ToDoController(businessLogic)) { using (var repositoryGet = new ToDoRepository()) { using (var businessLogicGet = new ToDoBL(repositoryGet, new DataCache())) { using (ToDoController controllerGet = new ToDoController(businessLogicGet)) { // Act var result = controllerGet.GetAll(); var data = result.Data.GetType().GetProperty("data"); var dataVal = (List <ToDoItem>)data.GetValue(result.Data, null); if (dataVal != null && dataVal.Count > 0) { var item = dataVal[dataVal.Count - 1]; var resultDelete = controller.Delete(item.Id); //Assert Assert.IsTrue(String.IsNullOrEmpty(resultDelete.Data.ToString()), "Since the id is not present so throwing error."); } else { Assert.IsTrue(true); } } } } } } } }
public ActionResult ToDo_Action(decimal code, int type) { var todoBl = new ToDoBL(); List <ToDoInfo> lstToDo = new List <ToDoInfo>(); int currStatus = 0; List <AllCodeInfo> lstStatus = new List <AllCodeInfo>(); try { lstToDo = todoBl.GetByCode(code, type); //var actionToDo = ....(code); //currStatus = actionToDo.Status; //ViewBag.ListStatus = Memory_BL.GetAllCodeByCdType(""); ViewBag.CurrentStatus = currStatus; ViewBag.ListToDo = lstToDo; ViewBag.ToDoType = type; } catch (Exception ex) { NaviCommon.Common.log.Error(ex.ToString()); } return(View("~/Areas/ToDo/Views/ToDo/ToDo_Action.cshtml")); }