I think it’s a good practise to always return empty lists or arrays instead of null when a method comes up with no results to avoid null checks in the code.
Because Rhino Mocks returns the default value for an object, which is null for lists and arrays, a lot of times I have to either add the null checks back in or setup the mocks with expectations to return lists.
Is there a way to configure or extend Rhino Mocks with this behaviour?
var repositoryMock = MockRepository.GenerateMock<ICustomerRepository>(); IList<Customer> customers = repositoryMock.getCustomers(); Assert.IsNotNull(customers); Assert.AreEqual(0, customers.Count );
Turns out that this behaviour is possible with Moq as long as the returned object is IEnumerable. The following tests pass: