コード例 #1
0
ファイル: HomeController.cs プロジェクト: holmesjr/Glossary
 public ActionResult EditTerm(ModifyTermViewModel vm)
 {
     if (ModelState.IsValid)
     {
         var oldTerm = _glossaryRepository.GetTerm(vm.Id);
         if (oldTerm != null)
         {
             oldTerm.Term = vm.TermViewModel.Term;
             oldTerm.Definition = vm.TermViewModel.Definition;
             _glossaryRepository.SaveTerm(oldTerm);
         }
         return RedirectToAction("Index");
     }
     return View(vm);
 }
コード例 #2
0
        public void Edit_a_term()
        {
            const int termId = 1;
            var editedTerm = Builder<TermViewModel>.CreateNew().Build();
            var vm = new ModifyTermViewModel { Id = termId, TermViewModel = editedTerm };
            _glossaryRepo.GetTerm(termId).Returns(new GlossaryTerm { Id = termId, Definition = editedTerm.Definition, Term = editedTerm.Term });
            var controller = new HomeController(_glossaryRepo);

            controller.EditTerm(vm);

            _glossaryRepo.Received().SaveTerm(Arg.Is<GlossaryTerm>(t => t.Term == editedTerm.Term && t.Definition == editedTerm.Definition && t.Id == termId));
        }
コード例 #3
0
        public void Validate_an_edited_term()
        {
            const int termId = 1;
            var editedTerm = new TermViewModel();
            var vm = new ModifyTermViewModel { Id = termId, TermViewModel = editedTerm };
            _controller.ModelState.AddModelError("Term", "Error");

            var result = _controller.EditTerm(vm) as ViewResult;

            _glossaryRepo.DidNotReceive().SaveTerm(Arg.Any<GlossaryTerm>());
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Model, Is.EqualTo(vm));
        }