Exemplo n.º 1
0
        public void Create_should_display_error_message_if_there_is_a_data_exception()
        {
            var repositoryStub = MockRepository.GenerateStub<IGlossaryTermRepository>();

            var glossaryTermCausingError = new GlossaryTerm();

            repositoryStub.Expect(m => m.Create(glossaryTermCausingError)).Throw(new DataException(""));

            var controller = new GlossaryTermController(repositoryStub);
            controller.Create(glossaryTermCausingError);

            Assert.AreEqual("The term could not be saved. Please try again.", controller.ModelState[""].Errors.First().ErrorMessage);
        }
Exemplo n.º 2
0
        public void Index_should_sort_the_terms_alphabetically_when_in_reversed_order()
        {
            var termStartingWithA = new GlossaryTerm { Term = "a" };
            var termStartingWithB = new GlossaryTerm { Term = "b" };

            var glossaryTermsFromRepository = new List<GlossaryTerm>
                                    {
                                        termStartingWithB,
                                        termStartingWithA
                                    };

            var glossaryTerms = GetGlossaryTermsFromController(CreateRepositoryForGettingAllTerms(glossaryTermsFromRepository));

            Assert.AreEqual(termStartingWithA.Term, glossaryTerms.ElementAt(0).Term);
            Assert.AreEqual(termStartingWithB.Term, glossaryTerms.ElementAt(1).Term);
        }
Exemplo n.º 3
0
        public ActionResult Create(GlossaryTerm glossaryterm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _repository.Create(glossaryterm);
                    return RedirectToAction("Index");
                }
                catch (DataException)
                {
                    ModelState.AddModelError("", "The term could not be saved. Please try again.");
                }
            }

            return View(glossaryterm);
        }
Exemplo n.º 4
0
 public void Edit(GlossaryTerm glossaryTerm)
 {
     _db.Entry(glossaryTerm).State = EntityState.Modified;
     _db.SaveChanges();
 }
Exemplo n.º 5
0
 public void Delete(GlossaryTerm glossaryTerm)
 {
     _db.GlossaryTerms.Remove(glossaryTerm);
     _db.SaveChanges();
 }
Exemplo n.º 6
0
 public void Create(GlossaryTerm glossaryTerm)
 {
     _db.GlossaryTerms.Add(glossaryTerm);
     _db.SaveChanges();
 }