I am working through Steve Sanderson's book Pro ASP.NET MVC Framework and I having some issues with one unit test which produce error.
In the example below it test the Paginate.
[TestMethod]
public void Can_Paginate()
{
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"}
}.AsQueryable());
ProductController controller = new ProductController(mock.Object);
controller.PageSize = 3;
IEnumerable<Product> result = (IEnumerable<Product>)controller.List(2).Model;
Product[] prodArray = result.ToArray();
Assert.IsTrue(prodArray.Length == 2);
Assert.AreEqual(prodArray[0].Name, "P4");
Assert.AreEqual(prodArray[0].Name, "P5");
}
The message error is:
Test method UnitTestProject3.Peginate.Can_Peginate threw exception: System.NullReferenceException.
Has anyone run into a similar issue or gotten the test to pass?