How to test that action uses argument?
Posted
by
Caster Troy
on Stack Overflow
See other posts from Stack Overflow
or by Caster Troy
Published on 2014-08-23T09:48:56Z
Indexed on
2014/08/23
10:20 UTC
Read the original article
Hit count: 154
I am supposed to be using test-driven development but in this particular case, as I am having trouble, I implemented the action method first. It looks like this:
public ViewResult Index(int pageNumber = 1)
{
var posts = repository.All();
var model = new PagedList<Post>(posts, pageNumber, PageSize);
return View(model);
}
Both the repository and the PagedList<>
have been tested already. Now I want to verify that when the action is given a page number that the page number is actually considered.
private Mock<IPostsRepository> repository;
private HomeController controller;
[Test]
public void Index_Doohickey()
{
var actual = controller.Index(2);
// .. How do I test that the controller actually uses the page number here?
}
© Stack Overflow or respective owner