예제 #1
0
        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
        }
예제 #2
0
        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
        }
예제 #3
0
        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);
        }