I am new to Rhino Mocks, and using mock isolation frameworks in general for unit testing. I have written the following test, where I have set up an expectation for a mock IDataProvider object to return a collection of objects. The collection supplied has one object in it.
When I run the test, the call to the IDataProvider returns a empty list when it should return the list with one object in it.
Any ideas whats going wrong?
Here is my test: (Please excuse any bad practises here... feel free to mention any. Im trying to learn! Thanks)
[TestMethod()]
public void FetchDataSeries_NeedsUpdate_SuccessfulDataSeriesRetrievedFromDataProvider() {
List<IDataSeries> dataSeries = new List<IDataSeries>();
dataSeries.Add(new DataSeries("test"));
DrillDownLevel level = DrillDownLevel.YEAR;
int? year = 2008;
var dataProvider = _MockRepository.CreateMock<IDataProvider>();
dataProvider.Expect(dp => dp.GetDataSeries(String.Empty, level, year, null ,null, null)).Return(dataSeries);
_DataSourceContext.DataProvider = dataProvider;
CollectionAssert.AreEqual(dataSeries, _DataSourceContext.FetchDataSeries(level, year, null, null, null));
dataProvider.VerifyAllExpectations();
}
Relevant portion of method under test: (The DataProvider.GetDataSeries call returns empty list... this should return stubbed list.)
public override List<IDataSeries> FetchDataSeries(DrillDownLevel? drillDownLevel, int? year, int? month, DateTime? week, int? day) {
List<IDataSeries> dataSeries = new List<IDataSeries>();
// Cache data for maximum cache period
// if data has been cached for longer than the maxium cache period OR the updateInterval has elapsed UNLESS LastUpdateAttempt was less than minimum update interval
if (NeedsUpdate(LastUpdate, LastUpdateAttempt)) {
// Attempt to get new data
LoggingService.InfoFormat("DataSourceContext: {0}: Attempting to get new data:", Name);
dataSeries = DataProvider.GetDataSeries(DataQuery, drillDownLevel, year, month, week, day);
}
return dataSeries;
}