Benn trying to test a service layer method which returns a simple IList using RhinoMocks 3.6
[TestMethod]
public void GetItems_Returns_ActionItemsList()
{
// arrange
var mockRepository = MockRepository.GenerateMock<IActionItemRepository>();
mockRepository.Stub(s => s.Select()).Return(GetFakeActionItems());
var service = new ActionItemQueueService(mockRepository);
// act
var actual = service.GetItems();
mockRepository.VerifyAllExpectations();
// assert
Assert.IsInstanceOfType(actual, typeof(IList<ActionItem>));
}
Real simplle right? The GetFakeActionItems method for reference;
internal IQueryable<ActionItem> GetFakeActionItems()
{
return new List<ActionItem> {
new ActionItem{
Id = 5,
ClientName = "Bank of American Corporation",
ActionNeeded = RequiredAction.Change,
RecordIndicator = "ROI",
RequestDate = DateTime.Now.AddDays(-3)
}
} as IQueryable<ActionItem>;
}
Here is the class and method under test...
public class ActionItemQueueService : IActionQueueService
{
private readonly IActionItemRepository _actionItemRepository;
public ActionItemQueueService(IActionItemRepository actionItemRepository)
{
_actionItemRepository = actionItemRepository;
if (_actionItemRepository == null)
{
throw new ArgumentNullException("ActionItemRepository");
}
}
public IList<Model.ActionItem> GetItems()
{
return _actionItemRepository.Select().ToList<Model.ActionItem>();
}
}
Nothing wild.... When I run my test, I Get an ArgumentNullException when the GetItems() method is called when _actionItemRepository.Select() fires. Value cannot be null. Parameter name: source.
Confused and perplexed wondering if anyone has any insight into what I am missing.
Many thanks!