public void CreatePrincessShouldRedirectToIndexWhenSuccess() { Princess user = PersonFactory.CreatePrincess("Justin"); var result = controller.Create(user) as JsonResult; Assert.IsTrue(result.Data.ToString().Contains("Redirect")); Assert.IsTrue(result.Data.ToString().Contains("Princess/")); }
public void CanAddPrincess() { Princess expected = PersonFactory.CreatePrincess("Arthur"); PrincessRepository.Add(expected); var princesses = _context.Princesses.ToList(); Assert.AreEqual(1, princesses.Count()); Assert.AreEqual(expected, princesses.FirstOrDefault()); }
public void EditPrincessShouldBeRedirectToIndexWhenUpdated() { Princess princess = PersonFactory.CreatePrincess("Jayce"); repository.Expect(x => x.Update(princess)).Return(MessageType.Success); mocks.ReplayAll(); var result = controller.Edit(princess) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); repository.AssertWasCalled(x => x.Update(princess)); }
public void RetrievePrincessById() { Princess expected = PersonFactory.CreatePrincess("Cendrion"); _context.Princesses.Add(expected); _context.SaveChanges(); Princess actual = PrincessRepository.FindById(expected.Id); ; Assert.AreEqual(expected, actual); }
public void EditPrincessShouldRetrieveTheModel() { Princess princess = PersonFactory.CreatePrincess("Jeny"); int id = 5; repository.Expect(x => x.FindById(id)).Return(princess); mocks.ReplayAll(); var result = controller.Edit(id) as ViewResult; Assert.AreEqual(princess, result.Model); repository.AssertWasCalled(x => x.FindById(id)); }
public void DeletePrincessShouldShowDeleteConfirmation() { Princess princess = PersonFactory.CreatePrincess("Princess Of Something"); int id = 5; repository.Expect(x => x.FindById(Arg <int> .Is.Equal(id))).Return(princess); mocks.ReplayAll(); var result = controller.Delete(id) as ViewResult; Assert.AreEqual(princess, result.Model); repository.VerifyAllExpectations(); }
public void PrincessCanBeUpdated() { Princess expected = PersonFactory.CreatePrincess("Esmeralda"); _context.Princesses.Add(expected); _context.SaveChanges(); expected.FirstName = "Reine Esmeralda"; MessageType message = PrincessRepository.Update(expected); Assert.AreEqual(MessageType.Success, message); Assert.AreEqual(expected, _context.Princesses.Find(expected.Id)); }
public void IndexShouldShowPrincesses() { var princesses = new List <Princess> { PersonFactory.CreatePrincess("Benoit XVI"), PersonFactory.CreatePrincess("Mafalda") }; repository.Expect(x => x.FindAll()).Return(princesses); mocks.ReplayAll(); var result = controller.Index() as ViewResult; Assert.AreEqual(princesses, result.Model); repository.AssertWasCalled(x => x.FindAll()); }
public void PrincessShouldNotUseBadIdToDelete() { Princess expected1 = PersonFactory.CreatePrincess("Elisabeth"); Princess expected2 = PersonFactory.CreatePrincess("Elisabeth II"); _context.Princesses.Add(expected1); _context.Princesses.Add(expected2); _context.SaveChanges(); PrincessRepository.Remove(6); var princesses = _context.Princesses.ToList(); Assert.AreEqual(2, princesses.Count()); }
public void CanDeletePrincess() { Princess expected1 = PersonFactory.CreatePrincess("Méchante reine"); Princess expected2 = PersonFactory.CreatePrincess("Blanche neige"); _context.Princesses.Add(expected1); _context.Princesses.Add(expected2); _context.SaveChanges(); PrincessRepository.Remove(expected1.Id); var princesses = _context.Princesses.ToList(); Assert.AreEqual(1, princesses.Count()); Assert.AreEqual(expected2, princesses.FirstOrDefault()); }