views:

34

answers:

1

I'm having problems figuring out the proper arguments of the Arg option in RhinoMocks.

I am trying to mock the MSIRecordGetString method which has a ref Int32 parameter. Currently I have:

_Api.RecordGetString(Arg<IntPtr>.Is.Anything,
                     Arg<Int32>.Is.Anything, 
                     Arg<StringBuilder>.Is.Anything, 
                     ref Arg<Int32>.Ref( ???, 0).Dummy);

Can anyone let me know what ??? should/could be replaced with. I know it should be something of type AbstractConstraint but I'm not sure what is valid. Having difficulty finding any examples of proper usage.

Cheers.

+1  A: 

I'm actually used to Moq, but my understanding of that first argument is a constraint, but seeing as you don't particularly care for the value (I'm assuming), could you do the following:

ref Arg<Int32>(Is.Anything(), 0).Dummy

?

Matthew Abbott
Hi Matt, thanks for the answer. Not really sure I get the reasons for this constraint though. Why is this different from the Out syntax which doesn't require an abstractconstraint?
Ben Cawley
Likely because out parameters have to be assigned to, whereas ref parameters do not, so the design idea is that ref parameters may have a pre-existing value to pass in. You can constrain it at this point?
Matthew Abbott