开发者

Rhino mocks .Repeat.Any() not working for me

I was having problems with a second call on a mock in my test run, so I moved the double calls into the test method. I have this:

RefBundle mockIRefBundle = mocks.StrictMock<IRefBundle>();

Expect.Call(mockIRefBundle.MaxTrackItems).Return( 6 ).Repeat.Any();

int q = mockIRefBundle.MaxTrackItems;
int z = mockIRefBundle.MaxTrackItems;

It fails when I make the second call to set "z" with an exception that implies the method was already called:

Error message:

System.InvalidOperationException: Previous method 
'IRefBundle.get_MaxTrackItems();
'requires a return value or an exception to throw..

and Stack

Rhino.Mocks.Impl.RecordMockState.AssertPreviousMethodIsClose()
Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation invocation, 
...

The second call 开发者_高级运维doesn't seem to honor the Repeat.Any()

What am I missing?


Either you have to use the new syntax:

RefBundle mockIRefBundle = MockRepository.GenerateMock<IRefBundle>();

mockIRefBundle.Expect(X => x.MaxTrackItems).Return(6).Repeat.Any();

int q = mockIRefBundle.MaxTrackItems;
int z = mockIRefBundle.MaxTrackItems;

or alternatively you need to call ReplayAll() before you start using your mocks:

RefBundle mockIRefBundle = MockRepository.GenerateMock<IRefBundle>();

mockIRefBundle.Expect(X => x.MaxTrackItems).Return(6).Repeat.Any();

mocks.ReplayAll();
int q = mockIRefBundle.MaxTrackItems;
int z = mockIRefBundle.MaxTrackItems;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜