Пример #1
0
        public void IndexNullList()
        {
            // Arrange
            Mock<IPersonRepository> mock = new Mock<IPersonRepository>();
            List<Person> peopleList = null;
            int pageCount = 1;
            mock.Setup<List<Person>>(d => d.GetPeople(It.IsAny<int>(), out pageCount)).Returns(peopleList);
            PersonController controller = new PersonController(mock.Object);

            // Act
            RedirectToRouteResult result = controller.Index() as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("ShowMessage", result.RouteValues["action"]);//If invalid Race ridirect to Index() action
        }
Пример #2
0
        public void IndexPageNoGreaterThanPageCount()
        {
            // Arrange
            Mock<IPersonRepository> mock = new Mock<IPersonRepository>();
            List<Person> peopleList = new List<Person>();
            peopleList.Add(new Person { Name = "Person#1", Age = 10, Race = Race.Angles });
            peopleList.Add(new Person { Name = "Person#2", Age = 12, Race = Race.Jutes });
            int pageCount = 1;
            mock.Setup<List<Person>>(d => d.GetPeople(It.IsAny<int>(), out pageCount)).Returns(peopleList);
            PersonController controller = new PersonController(mock.Object);

            // Act
            ViewResult result = controller.Index(10) as ViewResult;

            // Assert
            Assert.AreEqual("The Page No. is greater than maximim number of pages", result.ViewBag.ErrorMessage);
        }
Пример #3
0
        public void IndexPageNo()
        {
            // Arrange
            Mock<IPersonRepository> mock = new Mock<IPersonRepository>();
            List<Person> peopleList = new List<Person>();
            peopleList.Add(new Person { Name = "Person#1", Age = 10, Race = Race.Angles });
            peopleList.Add(new Person { Name = "Person#2", Age = 12, Race = Race.Jutes });
            int pageCount = 1;
            mock.Setup<List<Person>>(d => d.GetPeople(It.IsAny<int>(), out pageCount)).Returns(peopleList);
            PersonController controller = new PersonController(mock.Object);

            // Act
            ViewResult result = controller.Index(1) as ViewResult;

            // Assert
            Assert.AreEqual(1, result.ViewBag.CurrentPage);
        }