Пример #1
0
        public ActionResult AddTerm(TermViewModel newTerm)
        {
            if(ModelState.IsValid)
            {
                _glossaryRepository.SaveTerm( new GlossaryTerm { Definition = newTerm.Definition, Term = newTerm.Term });
                return RedirectToAction("Index");
            }

            return View(newTerm);
        }
Пример #2
0
        public void Validate_a_new_term()
        {
            var newTerm = new TermViewModel();
            _controller.ModelState.AddModelError("Term", "Error");

            var result = _controller.AddTerm(newTerm) as ViewResult;

            _glossaryRepo.DidNotReceive().SaveTerm(Arg.Any<GlossaryTerm>());
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Model, Is.EqualTo(newTerm));
        }
Пример #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));
        }