Sometimes Rhino.Mocks is driving me mad, 'cause there's not enough documentation on topics that, I suppose, are relatively easy.
What I want to do is to expect call to AddContact("test", contact). So for the second parameter I must use parameter constraint Property.AllPropertiesMatch(contact). But what should I use for the first one?
_contactManagerMock
.Expect(m => m.AddContact(null, null))
.Constraints(??????????, Property.AllPropertiesMatch(contact));
What goes instead of "??????????"
I was looking for this as well, here is a more detailed answer.
This is an example of how to use the AllPropertyMatch in Rhino.Mocks. I tested this in Rhino.Mocks 3.6.
//arrange
var contactManagerMock = MockRepository.GenerateMock<IManager>();
contactManagerMock.Expect(m => m.AddContact(
Arg.Is("test"),
Arg<Contact>.Matches(Property.AllPropertiesMatch(contact))))
//Act
//Perform action here that should result in the above expected call
//Assert
contactManagerMock.VerifyAllExpectations();
This says to expect the AddContact method to be called. The first parameter should be a string with the value 'test' the second should be an object of type Contact that has all the same properties as the instance of contact. Calling VerifyAllExpectations performs the assertion.
More info on the Rhino.Mocks site.