コード例 #1
0
        public void CanAddPerson()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            PersonSectionAddEditModel personSection = new PersonSectionAddEditModel();

            personSection.id = 5;
            personSection.name = "Zbigniew";
            personSection.surname = "Strzelec";
            personSection.area_code = 44;
            personSection.email = "*****@*****.**";
            personSection.section_name = "4";
            personSection.phone_number = 12345;
            personSection.phone_number2 = 666666;

            var redirectToRouteResult = controller.Add(personSection) as RedirectToRouteResult;
            mock_person.Verify(m => m.AddObject(It.IsAny<Person>()), Times.Once());

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
        }
コード例 #2
0
        public void CantAddPerson()
        {
            Mock<IRepository<Person>> mock_person = new Mock<IRepository<Person>>();
            Mock<IRepository<Section>> mock_section = new Mock<IRepository<Section>>();
            mock_section.Setup(m => m.Repository).Returns(CreateSectionTab().AsQueryable());
            mock_person.Setup(m => m.Repository).Returns(CreatePersonTab().AsQueryable());

            PersonController controller = new PersonController(mock_person.Object, mock_section.Object);
            PersonSectionAddEditModel personSection = null;
            var redirectToRouteResult = controller.Add(personSection) as RedirectToRouteResult;
            mock_person.Verify(m => m.AddObject(It.IsAny<Person>()), Times.Once());

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
        }