Search code examples
c#visual-studio-2008rhino-mocksrhino-mocks-3.5

Can I tell if a property has been accessed via Rhino Mocks


I have a property in an interface that I have mocked using Rhino Mocks. I want to know if it was accessed in my unit test.

Is there a way to see if the property was accessed via Rhino Mocks?

I found this code here but it does not seem to work:

string name = customerMock.Name;
customerMock.AssertWasCalled(x => {var ignored = x.Name;});

I reproduced this code and I get the following:

Rhino.Mocks.Exceptions.ExpectationViolationException: IAddAddressForm.get_FirstName(); Expected #1, Actual #0..

I would like to use this syntax, but I must be missing something. I am calling it with a stub (not a mock) does that make a difference?


Solution

  • Turns out the syntax I was using does work. But it only works if the property is not in PropertyBehavior mode. (Which is the default for stubs and can be turned on for mocks).

    Once PropertyBehavior mode is turned on, then that syntax does not work. According to Ayende you have to check the value at that point.