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
        }
        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);
        }
        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);
        }
        public void ShowPeopleByRaceInvalidRace()
        {
            // 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.GetPeopleByRace(It.IsAny<Race>(), It.IsAny<int>(), out pageCount)).Returns(peopleList);
            PersonController controller = new PersonController(mock.Object);
            FormCollection form = new FormCollection();
            form["RacesList"] = "Invalid Race";//Check out invalid race
            form["SelectedPage"] = "1";
            // Act
            RedirectToRouteResult result = controller.ShowPeopleByRace(form) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);//If invalid Race ridirect to Index() action
        }
        public void ShowPeopleByRaceNullList()
        {
            // Arrange
            Mock<IPersonRepository> mock = new Mock<IPersonRepository>();
            List<Person> peopleList = null;
            int pageCount = 1;
            mock.Setup<List<Person>>(d => d.GetPeopleByRace(It.IsAny<Race>(), It.IsAny<int>(), out pageCount)).Returns(peopleList);
            PersonController controller = new PersonController(mock.Object);
            FormCollection form = new FormCollection();
            form["RacesList"] = Race.Saxons.ToString();
            form["SelectedPage"] = "1";
            // Act
            RedirectToRouteResult result = controller.ShowPeopleByRace(form) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("ShowMessage", result.RouteValues["action"]);//If invalid Race ridirect to Index() action
        }
        public void ShowPeopleByRace()
        {
            // 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.GetPeopleByRace(It.IsAny<Race>(), It.IsAny<int>(), out pageCount)).Returns(peopleList);
            PersonController controller = new PersonController(mock.Object);
            FormCollection form = new FormCollection();
            form["RacesList"] = Race.Saxons.ToString();
            form["SelectedPage"] = "1";
            // Act
            ViewResult result = controller.ShowPeopleByRace(form) as ViewResult;

            // Assert
            Assert.AreEqual<List<Person>>(peopleList, (List<Person>)result.Model);
        }