If you see this error when testing with RhinoMocks

System.InvalidOperationException: Use Arg<T> ONLY within a mock method call while recording. 0 arguments expected, 2 have been defined.

ensure that method on which you setuped expectation is virtual.
Actually this should be all you need.

I faced this when doing test like this:

[Test]
public void Start_Service_InitializeWasCalled()
{
    var service = MockRepository.GenerateMock<SpecificServiceBase>();
    //some setup here…
    service.Expect(x => x.Initialize(Arg<ServiceSettingElement>.Is.Anything, Arg<LogDelegate>.Is.Anything)).Repeat.Once();

    serviceControllerBase.Start();

    service.VerifyAllExpectations();
}

As you see I’m trying to verify that method Initialize was called after Start was triggered. Signature of method looks like:

public void Initialize(ServiceSettingElement configuration, LogDelegate logDelegate){}

After I changed it to:

public virtual void Initialize(ServiceSettingElement configuration, LogDelegate logDelegate){}

My test passed ok.

I want to mention that when testing with RhinoMocks you always need to pay attention on things like virtual methods, using interfaces instead of classes, also using protected instead of private to have possibility test those stuff with RhinoMocks.

If you haven't subsribed yet, you can subsribe below: