示例#1
0
 public static MvcHtmlString PageLinks(this HtmlHelper html,
                                      PadingInfo 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));
         tag.InnerHtml = i.ToString();
         if (i == pagingInfo.CurrentPage)
         {
             tag.AddCssClass("selected");
             tag.AddCssClass("btn-primary");
         }
         tag.AddCssClass("btn btn-default");
         result.Append(tag.ToString());
     }
     return MvcHtmlString.Create(result.ToString());
 }
        public void Can_Send_View_Model()
        {
            Mock <IProductRepository> mock = new Mock <IProductRepository>();

            mock.Setup(m => m.Products).Returns((new Product[] {
                new Product {
                    ProductID = 2, Name = "P2"
                },
                new Product {
                    ProductID = 3, Name = "P3"
                },
                new Product {
                    ProductID = 4, Name = "P4"
                },
                new Product {
                    ProductID = 5, Name = "P5"
                }
            }).AsQueryable <Product>());

            //Организация

            ProductController controller =
                new ProductController(mock.Object)
            {
                PageSize = 3
            };

            //Действие
            ProductsListViewModel result =
                controller.List(null, 2).ViewData.Model as ProductsListViewModel;
            //Утверждение
            PadingInfo PageInfo = result.padingInfo;

            Assert.Equal(2, PageInfo.CurentPage);
            Assert.Equal(3, PageInfo.ItemPerPage);
            Assert.Equal(5, PageInfo.TotalItems);
            Assert.Equal(2, PageInfo.TotalPages);
        }
示例#3
0
        public void Can_Send_Pagination_View_Model()
        {
            //Model
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(b => b.Books).Returns(new Book[]
            {
                new Book {
                    BookId = 1, Name = "B1"
                },
                new Book {
                    BookId = 2, Name = "B2"
                },
                new Book {
                    BookId = 3, Name = "B3"
                },
                new Book {
                    BookId = 4, Name = "B4"
                },
                new Book {
                    BookId = 5, Name = "B5"
                },
            });
            BookController bookController = new BookController(mock.Object)
            {
                PageSize = 3
            };
            //Act
            BooksListViewModel result   = bookController.List(null, 2).ViewData.Model as BooksListViewModel;
            PadingInfo         pageInfo = result.PadingInfo;

            //Cheking conditions
            Assert.Equal(2, pageInfo.CurrentPage);
            Assert.Equal(3, pageInfo.ItemsPerPage);
            Assert.Equal(5, pageInfo.TotalItems);
            Assert.Equal(2, pageInfo.TotalPages);
        }