update: 3
I am trying to make fun of the method that a class uses to create new instances of other classes through a unit of work. When I try and mock a method to return fixed data, I get zero instead of a list when the getPage method was called.
here is my code
[TestFixture()]
public class CustomerServiceTests
{
private ICustomerService service;
private IUnitOfWork mockUnitOfWork;
private IGenericRepository<Entities.Customer> repository;
private int customerId;
private int ContactId;
[SetUp()]
public void Setup()
{
customerId = 1;
ContactId = 1;
}
[Test()]
public void GetCustomers_should_return_three_results()
{
mockUnitOfWork = MockRepository.GenerateMock<IUnitOfWork>();
repository = MockRepository.GenerateMock<IGenericRepository<Entities.Customer>>();
List<Entities.Customer> customerList = new List<Entities.Customer>
{
new Entities.Customer { Id = 1, CompanyName = "test1", ContractorId = 1 },
new Entities.Customer { Id = 2, CompanyName = "test2", ContractorId = 2 },
new Entities.Customer { Id = 3, CompanyName = "test3", ContractorId = 1 },
new Entities.Customer { Id = 4, CompanyName = "test4", ContractorId = 1 },
new Entities.Customer { Id = 5, CompanyName = "test5", ContractorId = 4 }
};
var IQueryableList = customerList.AsEnumerable();
mockUnitOfWork.Stub(uow => uow.CustomerRepository).Return(repository);
repository.Stub(repo => repo.GetPaged()).Return(new ContentList<Entities.Customer> { List = IQueryableList, Total = customerList.Count });
service = new CustomerService(mockUnitOfWork);
var resultList = service.GetCustomers(new PageRequest {PageSize = 20, PageIndex = 1 });
var total = resultList.Data.Total;
Assert.AreEqual(10, total);
}
Part of the utility code returns null instead of a list.
customers = _service.CustomerRepository.GetPaged(filter, orderBy, pageRequest.PageSize, pageRequest.PageIndex, "CustomersContacts");
source
share