コード例 #1
0
ファイル: AdminTests.cs プロジェクト: mesutc/DotTree
        public void CannotSaveInvalidPersonChanges()
        {
            // Arrange
            //  need extra Moq functionality so can't use the normal mock repo, but this isn't dependant on content anyway
            Mock<IPersonRepository> mock = new Mock<IPersonRepository>();
            AdminController target = new AdminController(mock.Object, GetFamilyRepository());
            Person person = new Person { FirstName = "Testable", LastName = "Test" };

            // add a deliberate error to the model
            target.ModelState.AddModelError("error", "error");

            // Act
            ActionResult result = target.EditPerson(person);

            // Assertion - save method was NOT called, and user WAS sent back to the family view
            mock.Verify(m => m.SavePerson(It.IsAny<Person>()), Times.Never());
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
コード例 #2
0
ファイル: AdminTests.cs プロジェクト: mesutc/DotTree
        public void CanSaveValidPersonChanges()
        {
            // Arrange
            //  need extra Moq functionality so can't use the normal mock repo, but this isn't dependant on content anyway
            Mock<IPersonRepository> mock = new Mock<IPersonRepository>();
            AdminController target = new AdminController(mock.Object,GetFamilyRepository());
            Person person = new Person { FirstName = "Testable", LastName = "Test" };

            // Act
            ActionResult result = target.EditPerson(person);

            // Assertion - save method was called, and user was not sent back to the family view
            mock.Verify(m => m.SavePerson(person));
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }