public void Can_Send_Pagination_View_Model()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

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

            PagingInfo pagingInfo = result.PagingInfo;

            Assert.AreEqual(pagingInfo.CurrentPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPages, 2);
        }
        public void Can_Paginate()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

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

            List <Thing> things = result.Things.ToList();

            Assert.IsTrue(things.Count == 2);
            Assert.AreEqual(things[0].Name, "Thing4");
            Assert.AreEqual(things[1].Name, "Thing5");
        }
        public void Can_Filter_Things()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2", Kind = "Kind2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4", Kind = "Kind3"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5", Kind = "Kind2"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            List <Thing> result = ((ThingsListViewModel)controller.List("Kind2", 1).Model).Things.ToList();

            Assert.AreEqual(result.Count(), 2);
            Assert.IsTrue(result[0].Name == "Thing2" && result[0].Kind == "Kind2");
            Assert.IsTrue(result[1].Name == "Thing5" && result[1].Kind == "Kind2");
        }
        public void Generate_Kind_Specific_Thing_Count()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2", Kind = "Kind2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3", Kind = "Kind1"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4", Kind = "Kind3"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5", Kind = "Kind2"
                }
            });

            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            int res1   = ((ThingsListViewModel)controller.List("Kind1").Model).PagingInfo.TotalItems;
            int res2   = ((ThingsListViewModel)controller.List("Kind2").Model).PagingInfo.TotalItems;
            int res3   = ((ThingsListViewModel)controller.List("Kind3").Model).PagingInfo.TotalItems;
            int resAll = ((ThingsListViewModel)controller.List(null).Model).PagingInfo.TotalItems;

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