예제 #1
0
        public void Can_Send_Pagination_View_Model()
        {
            // Организация (arrange)
            Mock <ICollectionRepository> mock = new Mock <ICollectionRepository>();

            mock.Setup(m => m.Collections).Returns(new List <Collection>
            {
                new Collection {
                    CollectionId = 1, Name = "Игра1"
                },
                new Collection {
                    CollectionId = 2, Name = "Игра2"
                },
                new Collection {
                    CollectionId = 3, Name = "Игра3"
                },
                new Collection {
                    CollectionId = 4, Name = "Игра4"
                },
                new Collection {
                    CollectionId = 5, Name = "Игра5"
                }
            });
            CollectionController controller = new CollectionController(mock.Object);

            controller.pageSize = 3;

            // Act
            CollectionsListViewModel result
                = (CollectionsListViewModel)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);
        }
예제 #2
0
        public void Can_Paginate()
        {
            // Организация (arrange)
            Mock <ICollectionRepository> mock = new Mock <ICollectionRepository>();

            mock.Setup(m => m.Collections).Returns(new List <Collection>
            {
                new Collection {
                    CollectionId = 1, Name = "Игра1"
                },
                new Collection {
                    CollectionId = 2, Name = "Игра2"
                },
                new Collection {
                    CollectionId = 3, Name = "Игра3"
                },
                new Collection {
                    CollectionId = 4, Name = "Игра4"
                },
                new Collection {
                    CollectionId = 5, Name = "Игра5"
                }
            });
            CollectionController controller = new CollectionController(mock.Object);

            controller.pageSize = 3;

            // Действие (act)
            CollectionsListViewModel result = (CollectionsListViewModel)controller.List(null, 2).Model;

            // Утверждение
            List <Collection> collections = result.Collections.ToList();

            Assert.IsTrue(collections.Count == 2);
            Assert.AreEqual(collections[0].Name, "Игра4");
            Assert.AreEqual(collections[1].Name, "Игра5");
        }