RhinoMocks错误“只有赋值,调用,递增,递减和新对象表达式才能用作语句”

时间:2012-01-17 21:56:32

标签: c# .net unit-testing mocking rhino-mocks

var CoreDataManagerMock = MockRepository.GenerateMock<ICoreDataManager>();
CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedBasicRates).Return(new List<int>());
CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedCompoundRates).Return(new List<int>());
CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedResetRates).Return(new List<int>());

所以我想设置它以便模拟对象上的那三个调用返回new List<int>(),但是我得到了这个编译器错误:

Only assignment, call, increment, decrement, and new object expressions can be used as a statement

我说错了吗?实际方法返回类型List<int>

1 个答案:

答案 0 :(得分:4)

由于这些是方法,因此在设置Stub时需要括号:

CoreDataManagerMock.Stub(r => r.LoadTranQuotesThatNeedBasicRates())
                   .Return(new List<int>());