Ejemplo n.º 1
0
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            Mock<ITourRepository> mock = new Mock<ITourRepository>();
            mock.Setup(m => m.Tours).Returns(new Tour[] 
            {
                new Tour {TourID = 1, Name = "P1"},
                new Tour {TourID = 2, Name = "P2"},
                new Tour {TourID = 3, Name = "P3"},
                new Tour {TourID = 4, Name = "P4"},
                new Tour {TourID = 5, Name = "P5"}
            });

            // Arrange
            TourController controller = new TourController(mock.Object);
            controller.PageSize = 3;

            // Act
            ToursListViewModel result = (ToursListViewModel)controller.List(null, 2).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);
        }
Ejemplo n.º 2
0
        public void Can_Retrieve_Image_Data()
        {
            // Arrange - create a Tour with image data
            Tour tour = new Tour
            {
                TourID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            // Arrange - create the mock repository
            Mock<ITourRepository> mock = new Mock<ITourRepository>();
            mock.Setup(m => m.Tours).Returns(new Tour[] {
                new Tour {TourID = 1, Name = "P1"},
                tour,
                new Tour {TourID = 3, Name = "P3"}
            }.AsQueryable());

            // Arrange - create the controller
            TourController target = new TourController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(2);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(tour.ImageMimeType, ((FileResult)result).ContentType);
        }
Ejemplo n.º 3
0
        public void Cannot_Retrieve_Image_Data_For_Invalid_ID()
        {
            // Arrange - create the mock repository
            Mock<ITourRepository> mock = new Mock<ITourRepository>();
            mock.Setup(m => m.Tours).Returns(new Tour[] {
                new Tour {TourID = 1, Name = "P1"},
                new Tour {TourID = 2, Name = "P2"}
            }.AsQueryable());

            // Arrange - create the controller
            TourController target = new TourController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(100);

            // Assert
            Assert.IsNull(result);
        }
Ejemplo n.º 4
0
        public void Can_Paginate()
        {
            // Arrange
            Mock<ITourRepository> mock = new Mock<ITourRepository>();
            mock.Setup(m => m.Tours).Returns(new Tour[] 
            {
                new Tour {TourID = 1, Name = "P1"},
                new Tour {TourID = 2, Name = "P2"},
                new Tour {TourID = 3, Name = "P3"},
                new Tour {TourID = 4, Name = "P4"},
                new Tour {TourID = 5, Name = "P5"}
            });
            TourController controller = new TourController(mock.Object);
            controller.PageSize = 3;

            // Act
            ToursListViewModel result = (ToursListViewModel)controller.List(null, 2).Model;

            // Assert
            Tour[] tourArray = result.Tours.ToArray();
            Assert.IsTrue(tourArray.Length == 2);
            Assert.AreEqual(tourArray[0].Name, "P4");
            Assert.AreEqual(tourArray[1].Name, "P5");
        }
Ejemplo n.º 5
0
        public void Can_Filter_Tours()
        {
            // Arrange
            // - create the mock repository
            Mock<ITourRepository> mock = new Mock<ITourRepository>();
            mock.Setup(m => m.Tours).Returns(new Tour[] 
            {
            new Tour {TourID = 1, Name = "P1", Category = "Cat1"},
            new Tour {TourID = 2, Name = "P2", Category = "Cat2"},
            new Tour {TourID = 3, Name = "P3", Category = "Cat1"},
            new Tour {TourID = 4, Name = "P4", Category = "Cat2"},
            new Tour {TourID = 5, Name = "P5", Category = "Cat3"}
            } );

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

            // Action
            Tour[] result = ((ToursListViewModel)controller.List("Cat2", 1).Model)
            .Tours.ToArray();

            // Assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[1].Category == "Cat2");
        }
Ejemplo n.º 6
0
        public void Generate_Category_Specific_Tour_Count() {
            // Arrange
            // - create the mock repository
            Mock<ITourRepository> mock = new Mock<ITourRepository>();
            mock.Setup(m => m.Tours).Returns(new Tour[] {
            new Tour {TourID = 1, Name = "P1", Category = "Cat1"},
            new Tour {TourID = 2, Name = "P2", Category = "Cat2"},
            new Tour {TourID = 3, Name = "P3", Category = "Cat1"},
            new Tour {TourID = 4, Name = "P4", Category = "Cat2"},
            new Tour {TourID = 5, Name = "P5", Category = "Cat3"}
            });

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

            // Action - test the Tour counts for different categories
            int res1 = ((ToursListViewModel)target
            .List("Cat1").Model).PagingInfo.TotalItems;
            int res2 = ((ToursListViewModel)target
            .List("Cat2").Model).PagingInfo.TotalItems;
            int res3 = ((ToursListViewModel)target
            .List("Cat3").Model).PagingInfo.TotalItems;
            int resAll = ((ToursListViewModel)target
            .List(null).Model).PagingInfo.TotalItems;

            // Assert
            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 2);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }