Exemplo n.º 1
0
        public void CanPaginate()
        {
            //arrange
            Mock<IGameRepository> mock =
                new Mock<IGameRepository>();
            mock.Setup(m => m.Games).Returns(new List<Game>
            {
                            new Game {GameId=1,  Name="Game1", Category="Categ1" },
                            new Game {GameId=2,  Name="Game2", Category="Categ2"  },
                            new Game {GameId=3,  Name="Game3", Category="Categ1" },
                            new Game {GameId=4,  Name="Game4", Category="Categ2" },
                            new Game {GameId=5,  Name="Game5", Category="Categ3" }
               });

            GameController gamectrl = new GameController(mock.Object);
            gamectrl.pageSize = 3;

            //act
            var result =((SportListViewModel)gamectrl.List("Categ2",1)
                .Model).Games.ToList();
            //assert
            Assert.AreEqual(result.Count(), 2);
            Assert.AreEqual(result[0].Name, "Game2");
            Assert.AreEqual(result[1].Name, "Game4");
        }
Exemplo n.º 2
0
        public void Can_Send_Pagination_View_Model()
        {
            //arrange
            Mock<IGameRepository> mock =
                new Mock<IGameRepository>();
                         mock.Setup(m => m.Games).Returns(new List<Game>
                       {
                            new Game { GameId=1, Name="Game1", Category="Categ1" },
                            new Game {GameId=2,  Name="Game2", Category="Categ2"  },
                            new Game {GameId=3,  Name="Game3", Category="Categ1" },
                            new Game {GameId=4,  Name="Game4", Category="Categ4" },
                            new Game {GameId=5,  Name="Game5", Category="Categ3" }
                        });

            GameController controller = new GameController(mock.Object);
            controller.pageSize = 3;

            //Act
            SportListViewModel result = (SportListViewModel)controller.List("Categ2",2).Model;

            //Assert
            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 1);
            Assert.AreEqual(pageInfo.TotalPages, 1);
        }
Exemplo n.º 3
0
        public void Generate_Category_Specific_Game_Count()
        {
            //arrange
            Mock<IGameRepository> mock =
                new Mock<IGameRepository>();
            mock.Setup(m => m.Games).Returns(new Game[]
                       {
                            new Game { GameId=1, Name="Game1", Category="Categ1" },
                            new Game {GameId=2,  Name="Game2", Category="Categ2"  },
                            new Game {GameId=3,  Name="Game3", Category="Categ1" },
                            new Game {GameId=4,  Name="Game4", Category="Categ4" },
                            new Game {GameId=5,  Name="Game5", Category="Categ2" }
                        });

            GameController ctrl = new GameController(mock.Object);
            ctrl.pageSize = 3;

            //act
            int res1 = ((SportListViewModel)ctrl.List("Categ1").Model).PagingInfo.TotalItems;
            int res2 = ((SportListViewModel)ctrl.List("Categ2").Model).PagingInfo.TotalItems;
            int res3 = ((SportListViewModel)ctrl.List("Categ4").Model).PagingInfo.TotalItems;
            int resAll = ((SportListViewModel)ctrl.List(null).Model).PagingInfo.TotalItems;

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