Skip to content

Instantly share code, notes, and snippets.

@jptoto
Created February 10, 2011 16:26
Show Gist options
  • Save jptoto/820821 to your computer and use it in GitHub Desktop.
Save jptoto/820821 to your computer and use it in GitHub Desktop.
Sample Test w/ Moq
[Test]
public void Can_View_A_Single_Page_Of_Products()
{
//Arrange, if there are 5 products in the repository...
IProductsRepository repository = UnitTestHelpers.MockProductsRepository(
new Product { Name = "P1" }, new Product { Name = "P2" }, new Product { Name = "P3" },
new Product { Name = "P4" }, new Product { Name = "P5" }
);
var controller = new ProductsController(repository);
controller.PageSize = 3;
//Act When the user asks for the second page...
var result = controller.List(null, 2);
//Assert (they'll just see the last two produdcts)
var viewModel = (ProductsListViewModel)result.ViewData.Model;
var displayedProducts = viewModel.Products;
displayedProducts.Count.ShouldEqual(2);
displayedProducts[0].Name.ShouldEqual("P4");
displayedProducts[1].Name.ShouldEqual("P5");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment