public void CanEditFamily() { // Arrange AdminController target = new AdminController(GetPersonRepository(), GetFamilyRepository()); // Act Family f1 = target.EditFamily(1).ViewData.Model as Family; Family f2 = target.EditFamily(2).ViewData.Model as Family; Family f3 = target.EditFamily(3).ViewData.Model as Family; // Assertion Assert.AreEqual(1, f1.Id); Assert.AreEqual(2, f2.Id); Assert.AreEqual(3, f3.Id); }
public void CannotEditInvalidFamily() { // Arrange AdminController target = new AdminController(GetPersonRepository(), GetFamilyRepository()); // Act Family result = (Family)target.EditFamily(5).ViewData.Model; // Assertion Assert.IsNull(result); }
public void CannotSaveInvalidFamilyChanges() { // Arrange // need extra Moq functionality so can't use the normal mock repo, but this isn't dependant on content anyway Mock<IFamilyRepository> mock = new Mock<IFamilyRepository>(); AdminController target = new AdminController(GetPersonRepository(), mock.Object); Family family = new Family { FamilyName = "Test", Description = "The Test Family" }; // add a deliberate error to the model target.ModelState.AddModelError("error", "error"); // Act ActionResult result = target.EditFamily(family); // Assertion - save method was NOT called, and user WAS sent back to the family view mock.Verify(m => m.SaveFamily(It.IsAny<Family>()), Times.Never()); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void CanSaveValidFamilyChanges() { // Arrange // need extra Moq functionality so can't use the normal mock repo, but this isn't dependant on content anyway Mock<IFamilyRepository> mock = new Mock<IFamilyRepository>(); AdminController target = new AdminController(GetPersonRepository(), mock.Object); Family family = new Family { FamilyName = "Test", Description = "The Test Family" }; // Act ActionResult result = target.EditFamily(family); // Assertion - save method was called, and user was not sent back to the family view mock.Verify(m => m.SaveFamily(family)); Assert.IsNotInstanceOfType(result, typeof(ViewResult)); }