Example #1
0
        public void Can_Fiter_Pubs()
        {
            Mock<IPubRepository> mock = new Mock<IPubRepository>();
            mock.Setup(m => m.Pubs).Returns(new Pub[]{
                new Pub { PubId = 1, Name = "P1", Category="Cat1"},
                new Pub { PubId = 2, Name = "P2", Category = "Cat2" },
                new Pub { PubId = 3, Name = "P3", Category = "Cat1" },
                new Pub { PubId = 4, Name = "P4", Category = "Cat2" },
                new Pub { PubId = 5, Name = "P5", Category = "Cat3" }
            });

            PubController controller = new PubController(mock.Object);
            controller.PageSize = 3;

            Pub[] result = ((PubsListViewModel)controller.List("Cat2",1).Model).Pubs.ToArray();

            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");
        }
Example #2
0
        public void Can_Send_Pagination_View_Model()
        {
            Mock<IPubRepository> mock = new Mock<IPubRepository>();
            mock.Setup(m => m.Pubs).Returns(new Pub[]
            {
                new Pub {PubId = 1, Name="The Vine" },
                new Pub {PubId = 2, Name="The City Arms" },
                new Pub {PubId = 3, Name="The Waterhouse" },
                new Pub {PubId = 4, Name="Beef & Pudding" },
                new Pub {PubId = 5, Name="Town Hall Tavern" }
            });

            PubController controller = new PubController(mock.Object);

            PubsListViewModel result = (PubsListViewModel)controller.List(null, 2).Model;

            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2, "CurrentPage");
            Assert.AreEqual(pageInfo.ItemsPerPage, 2, "ItemsPerPage");
            Assert.AreEqual(pageInfo.TotalItems, 5, "TotalItems");
            Assert.AreEqual(pageInfo.TotalPages, 3, "TotalPages");
        }
Example #3
0
        public void Can_Paginate()
        {
            Mock<IPubRepository> mock = new Mock<IPubRepository>();
            mock.Setup(m => m.Pubs).Returns(new Pub[]
            {
                new Pub {PubId = 1, Name = "The Vine", Description = "Local to work", Category="Pub" },
                new Pub {PubId = 2, Name = "The City Arms", Description = "Local to work", Category="Pub" },
                new Pub {PubId = 3, Name = "The Waterhouse", Description = "Local to work", Category="Pub" },
                new Pub {PubId = 4, Name = "Beef & Pudding", Description = "Local eaterie", Category="Restaurant" },
                new Pub {PubId = 5, Name = "Town Hall Tavern", Description = "Local to work", Category="Pub" }
            });

            PubController controller = new PubController(mock.Object);
            controller.PageSize = 3;

            PubsListViewModel result = (PubsListViewModel)controller.List(null, 2).Model;

            Pub[] pubArray = result.Pubs.ToArray();

            Assert.IsTrue(pubArray.Length == 2);
            Assert.AreEqual(pubArray[0].Name, "Beef & Pudding");
            Assert.AreEqual(pubArray[1].Name, "Town Hall Tavern");
        }