Example #1
0
        public void Generate_State_Specific_Location_Count()
        {
            // Arrange
            // - create the mock repository
            Mock<ILocationRepository> mock = new Mock<ILocationRepository>();
            mock.Setup(m => m.Locations).Returns(new List<Location>
             {
                 new Location {Id = 1, Name = "L1", State="MI" },
                 new Location {Id = 2, Name = "L2", State="IL"},
                 new Location {Id = 3, Name = "L3", State="MI"},
                 new Location {Id = 4, Name = "L4", State="IN"},
                 new Location {Id = 5, Name = "L5", State="MI"}

             });
            // Arrange - create the controller
            LocationsController target = new LocationsController(mock.Object);
            target.PageSize = 3;
            ViewResult indx = (ViewResult)target.Index("MI");
            ViewResult indxIl = (ViewResult)target.Index("IL");
            ViewResult indxIn = (ViewResult)target.Index("IN");
            ViewResult indxNull = (ViewResult)target.Index(null);

            // Act - get the set of states
            int res1 = ((LocationListViewModel)indx.Model).PagingInfo.TotalItems;
            int res2 = ((LocationListViewModel)indxIl.Model).PagingInfo.TotalItems;
            int res3 = ((LocationListViewModel)indxIn.Model).PagingInfo.TotalItems;
            int resAll = ((LocationListViewModel)indxNull.Model).PagingInfo.TotalItems;

            //Assert
            Assert.AreEqual(res1, 3);
            Assert.AreEqual(res2, 1);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }
Example #2
0
        public void Contains_All_Locations()
        {
            // Arrange - create the mock repository
            Mock<ILocationRepository> mock = new Mock<ILocationRepository>();
            mock.Setup(m => m.Locations).Returns(new List<Location>
             {
                 new Location {Id = 1, Name = "L1", State="MI" },
                 new Location {Id = 2, Name = "L2", State="IL"},
                 new Location {Id = 3, Name = "L3", State="MI"},
                 new Location {Id = 4, Name = "L4", State="IN"},
                 new Location {Id = 5, Name = "L5", State="MI"}

             });

            // Arrange
            LocationsController target = new LocationsController(mock.Object);
            ViewResult indx = (ViewResult)target.Index(null);
            //Action
            Location[] result = ((LocationListViewModel)indx.Model).Locations.ToArray();

            //Assert
            Assert.AreEqual(result.Length, 5);
            Assert.AreEqual("L1", result[0].Name);
            Assert.AreEqual("L2", result[1].Name);
            Assert.AreEqual("L3", result[2].Name);
        }
Example #3
0
        public void Can_Locations_Paginate()
        {
            // Arrange
            Mock<ILocationRepository> mock = new Mock<ILocationRepository>();
            mock.Setup(m => m.Locations).Returns(new List<Location>
             {
                 new Location {Id = 1, Name = "L1" },
                 new Location {Id = 2, Name = "L2"},
                 new Location {Id = 3, Name = "L3"},
                 new Location {Id = 4, Name = "L4"},
                 new Location {Id = 5, Name = "L5"}

             });

            LocationsController controller = new LocationsController(mock.Object);
            controller.PageSize = 3;
            ViewResult indx = (ViewResult)controller.Index(null, 2);
            //Act
            LocationListViewModel result =
                (LocationListViewModel)indx.Model;

            //Assert
            Location[] prodArray = result.Locations.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "L4");
            Assert.AreEqual(prodArray[1].Name, "L5");
        }
Example #4
0
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            Mock<ILocationRepository> mock = new Mock<ILocationRepository>();
            mock.Setup(m => m.Locations).Returns(new List<Location>
             {
                 new Location {Id = 1, Name = "L1" },
                 new Location {Id = 2, Name = "L2"},
                 new Location {Id = 3, Name = "L3"},
                 new Location {Id = 4, Name = "L4"},
                 new Location {Id = 5, Name = "L5"}

             });

            // Arrange
            LocationsController controller = new LocationsController(mock.Object);

            controller.PageSize = 3;
            ViewResult indx = (ViewResult)controller.Index(null, 2);
            //Act
            LocationListViewModel result =
                (LocationListViewModel)indx.Model;

            //Assert
            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Example #5
0
        public void Can_Filter_Locations()
        {
            // Arrange
            // - create the mock repository
            Mock<ILocationRepository> mock = new Mock<ILocationRepository>();
            mock.Setup(m => m.Locations).Returns(new List<Location>
             {
                 new Location {Id = 1, Name = "L1", State="MI" },
                 new Location {Id = 2, Name = "L2", State="IL"},
                 new Location {Id = 3, Name = "L3", State="MI"},
                 new Location {Id = 4, Name = "L4", State="IN"},
                 new Location {Id = 5, Name = "L5", State="MI"}

             });

            // Arrange - create a controller and make the page size 3 items
            LocationsController controller = new LocationsController(mock.Object);
            controller.PageSize = 3;

            ViewResult indx = (ViewResult)controller.Index("MI", 1);

            // Action
            Location[] result = ((LocationListViewModel)indx.Model)
                .Locations.ToArray();
            //Assert
            Assert.AreEqual(result.Length, 3);
            Assert.IsTrue(result[0].Name == "L1" && result[0].State == "MI");
            Assert.IsTrue(result[2].Name == "L5" && result[2].State == "MI");
        }