internal static ProjectObj Convert(EditProjectModel model) { return new ProjectObj { Id = model.Id, Name = model.Name, Description = model.Description }; }
public void Edit_Post_Update_Success() { //arrange var id = 2; var mockLogic = new Mock<IProjectLogic>(MockBehavior.Strict); mockLogic.Setup(m => m.Update(It.Is<ProjectObj>(p => p.Id == id), It.IsAny<string>())).Returns(true); var model = new EditProjectModel() { Id = id }; var controller = new ProjectController(mockLogic.Object); controller = SetupController(controller); //act var actual = controller.Edit(model) as RedirectResult; var expectedUrl = controller.Url.Project_Show(id); //assert Assert.IsNotNull(actual); Assert.AreEqual(expectedUrl, actual.Url); }
public void Edit_Post_Update_Bad_ModelState() { //arrange var mockLogic = new Mock<IProjectLogic>(MockBehavior.Strict); var model = new EditProjectModel() { Id = 0 }; var controller = new ProjectController(mockLogic.Object); controller = SetupController(controller); controller.ModelState.AddModelError("test", "test"); //act var actual = controller.Edit(model) as RedirectResult; var expectedUrl = controller.Url.Project_Edit(0); //assert Assert.IsNotNull(actual); Assert.AreEqual(expectedUrl, actual.Url); }
public void Edit_Post_Create_Failure() { //arrange var mockLogic = new Mock<IProjectLogic>(MockBehavior.Strict); mockLogic.Setup(m => m.Create(It.IsAny<ProjectObj>(), It.IsAny<string>())).Returns(-1); var model = new EditProjectModel(); var controller = new ProjectController(mockLogic.Object); controller = SetupController(controller); //act var actual = controller.Edit(model) as RedirectResult; var expectedUrl = controller.Url.Project_Create(); //assert Assert.IsNotNull(actual); Assert.AreEqual(expectedUrl, actual.Url); }
public ActionResult Edit(EditProjectModel model) { if (!ModelState.IsValid) { return Redirect(Url.Project_Edit(model.Id)); } ProjectObj project; if (!model.Id.HasValue) { project = ModelConverter.Convert(model); project.Id = ProjectLogic.Create(project, CurrentUserName); if (project.Id == -1) { this.AddError("CreatingProject", "There was an error creating your project. If this continues contact support."); return Redirect(Url.Project_Create()); } } else { project = ModelConverter.Convert(model); var success = ProjectLogic.Update(project, CurrentUserName); if (!success) { this.AddError("UpdatingProject", "There was an error updating your project. If this continues contact support."); return Redirect(Url.Project_Edit(model.Id.Value)); } } return Redirect(Url.Project_Show(project.Id.Value)); }
public ActionResult Edit(int? id = null) { EditProjectModel model = null; if (id.HasValue) { var project = ProjectLogic.Get(id.Value); if (project != null) { model = ModelConverter.ConvertToEdit(project); } else { this.AddWarning("NoItemFound", "No project was found with that Id. Switching to Create mode."); return Redirect(Url.Project_Create()); } } if (model == null) { model = new EditProjectModel(); model.Tags = new List<ListItemTagModel>(); } return View("Edit", model); }