Ejemplo n.º 1
0
        public void Can_Send_Pagination_View_Model()
        {
            Mock <IProductsRepository> mock = new Mock <IProductsRepository>();

            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {
                    ProductID = 1, Name = "P1"
                },
                new Product {
                    ProductID = 1, Name = "P2"
                },
                new Product {
                    ProductID = 1, Name = "P3"
                },
                new Product {
                    ProductID = 1, Name = "P4"
                },
            });
            ProductController productController = new ProductController(mock.Object);

            productController.PageSize = 2;
            ProductsListViewModel productViewModel  = (ProductsListViewModel)productController.List(null, 2).Model;
            PaggingInfo           paggingInfoResult = productViewModel.paggingInfo;

            Assert.AreEqual(paggingInfoResult.CurrentPage, 2);
            Assert.AreEqual(paggingInfoResult.TotalItems, 4);
            Assert.AreEqual(paggingInfoResult.ItemsPerPage, 2);
            Assert.AreEqual(paggingInfoResult.TotalPages, 2);
        }
Ejemplo n.º 2
0
        public static MvcHtmlString PageLinks(this HtmlHelper html, PaggingInfo pagingInfo, Func <int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder();

            for (int i = 1; i <= pagingInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrl(i));
                if (i == pagingInfo.CurrentPage)
                {
                    tag.AddCssClass("selected");
                }
                tag.InnerHtml = i.ToString();
                result.Append(tag.ToString());
            }
            return(MvcHtmlString.Create(result.ToString()));
        }
Ejemplo n.º 3
0
        public void Can_Generate_Page_Links()
        {
            HtmlHelper  htmlHelper  = null;
            PaggingInfo paggingInfo = new PaggingInfo()
            {
                CurrentPage  = 2,
                TotalItems   = 28,
                ItemsPerPage = 10
            };

            Func <int, string> pageUrl = i => "Page" + i;
            MvcHtmlString      result  = htmlHelper.PageLinks(paggingInfo, pageUrl);

            Assert.AreEqual(@"<a class=""btn btn-default"" href=""Page1"">1</a>"
                            + @"<a class=""btn btn-default btn-primary selected"" href=""Page2"">2</a>"
                            + @"<a class=""btn btn-default"" href=""Page3"">3</a>", result.ToString());
        }
Ejemplo n.º 4
0
        public void Generation_Page_Links()
        {
            PaggingInfo paginginfo = new PaggingInfo
            {
                CurrentPage  = 2,
                TotalItems   = 28,
                ItemsPerPage = 10
            };

            HtmlHelper myHelper = null;

            Func <int, string> pageUrlDelegate = i => "Strona" + i;

            MvcHtmlString result = myHelper.PageLinks(paginginfo, pageUrlDelegate);

            Assert.AreEqual(result.ToString(), @"<a href=""Strona1"">1</a><a class=""selected"" href=""Strona2"">2</a><a href=""Strona3"">3</a>");
        }