public void Adds_new_branch_to_the_branch_repository() { var branch = new Branch(); BranchRepositoryMock.Setup(repo => repo.Add(branch)).Verifiable(); BranchController.Create(branch); BranchRepositoryMock.Verify(repo => repo.Add(branch), Times.Once()); }
public void Returns_create_view_if_new_branch_is_invalid() { BranchController.ModelState.AddModelError("Name", "The Name field is required"); var invalidBranch = new Branch(); var viewResult = BranchController.Create(invalidBranch) as ViewResult; viewResult.Model.ShouldEqual(invalidBranch); viewResult.ViewName.ShouldEqual(string.Empty); }
public void Returs_crete_view_with_model_error_if_new_branch_name_already_exists() { var branchWithExistingBranchName = new Branch() {Name = "foo"}; BranchRepositoryMock.Setup(repo => repo.IsBranchNameExists(branchWithExistingBranchName.Name)).Returns(true); var viewResult = BranchController.Create(branchWithExistingBranchName) as ViewResult; viewResult.Model.ShouldEqual(branchWithExistingBranchName); viewResult.ViewName.ShouldEqual(string.Empty); AssertModelError(BranchController, "Name", "Branch name already exists"); }
public ActionResult Create(Branch branch) { if (ModelState.IsValid) { if (!branchRepository.IsBranchNameExists(branch.Name)) { branchRepository.Add(branch); return RedirectToAction("Index"); } ModelState.AddModelError("name", "Branch name already exists"); } return View(branch); }