Rhino mocks .Repeat.Any () doesn't work for me

I was having problems with the second layout call in my test run, so I moved the double calls to the test method. I have it:

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

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

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

This fails when I make a second call to set "z" with an exception, which implies that the method has already been 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 does not seem to justify Repeat.Any ()

What am I missing?

+3
source share
1 answer

Or you should 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;
+3
source

Source: https://habr.com/ru/post/1760623/


All Articles