I am trying to create application using .net mvc 4 and fluent nhibernate.
I have created ProductsFacade which is responsible for getting and inserting data to a database.
Method GetProductsByPageAndCategory is used to get page of records from database. I want to write unit test which checks if pagination works well.
It's hard to do because pagination must be done in single QueryOver query. I can't write separate method only fetching data, mock it and write separate method for pagination. So I need to mock database. I use moq tool for mocking.
Maybe anyone could give some tips on how to do it? Or any other alternative how to solve my problem?
public class ProductFacade {
//...
public virtual IList<Product> GetProductsByPageAndCategory(
string category,
int pageNumber,
int pageSize)
{
//IList<Product> products = ;
var productsQuery = _session.QueryOver<Product>();
if (category != null)
{
productsQuery.Where(p => p.Category == category);
}
IList<Product> products = productsQuery
.OrderBy(p => p.Id)
.Desc
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.List<Product>();
return products;
}
//...
}
sessionvariable is the solution. Then you can verify if the calls to subsequent fluent methods are done correctly. What's the problem?