7.5.1.3 Adding the View Model Data; UNIT TEST: PAGE MODEL VIEW DATA
This commit is contained in:
parent
6164f14dfc
commit
a5e527e9b8
@ -31,10 +31,9 @@ namespace SportsStore.UnitTests
|
||||
ProductController controller = new ProductController(mock.Object);
|
||||
controller.PageSize = 3;
|
||||
// Act
|
||||
IEnumerable<Product> result =
|
||||
(IEnumerable<Product>)controller.List(2).Model;
|
||||
ProductsListViewModel result = (ProductsListViewModel)controller.List(2).Model;
|
||||
// Assert
|
||||
Product[] prodArray = result.ToArray();
|
||||
Product[] prodArray = result.Products.ToArray();
|
||||
Assert.IsTrue(prodArray.Length == 2);
|
||||
Assert.AreEqual(prodArray[0].Name, "P4");
|
||||
Assert.AreEqual(prodArray[1].Name, "P5");
|
||||
@ -66,5 +65,34 @@ namespace SportsStore.UnitTests
|
||||
+ @"<a class=""btn btn-default"" href=""Page3"">3</a>",
|
||||
result.ToString());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Can_Send_Pagination_View_Model()
|
||||
{
|
||||
|
||||
// Arrange
|
||||
Mock<IProductRepository> mock = new Mock<IProductRepository>();
|
||||
mock.Setup(m => m.Products).Returns(new Product[] {
|
||||
new Product {ProductID = 1, Name = "P1"},
|
||||
new Product {ProductID = 2, Name = "P2"},
|
||||
new Product {ProductID = 3, Name = "P3"},
|
||||
new Product {ProductID = 4, Name = "P4"},
|
||||
new Product {ProductID = 5, Name = "P5"}
|
||||
});
|
||||
|
||||
// Arrange
|
||||
ProductController controller = new ProductController(mock.Object);
|
||||
controller.PageSize = 3;
|
||||
|
||||
// Act
|
||||
ProductsListViewModel result = (ProductsListViewModel)controller.List(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user