This is a migrated thread and some comments may be shown as answers.

Mock.NonPublic.Arrange on private method with by ref argument

2 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 14 Dec 2012, 07:39 PM
I'm attempting to mock a private method that has an argument passed by ref.  The Mock.NonPublic.Arrange() is throing an ArgumentException with the message "Could not resolve the target method; make sure that you have provided arguments correctly."

Regardless of how I set up the arguments in the test, it can't seem to match the function.  Is there a workaround?  Here's a sample method signature:
private void PrivateMethodWith1ArgByRef(ref object arg)

The test calls Mock.NonPublic.Arrange() as follows:
Mock.NonPublic.Arrange(class1, "PrivateMethodWith1ArgByRef", ArgExpr.IsNull<object>()).DoNothing();

Instead of IsNull<object>(), I tried IsAny<object>(), I tried passing in a variable of type object, and I tried passing in typeof(object).

In the interim, is there some kind of a workaround?

2 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 14 Dec 2012, 08:46 PM
Looking into it a little further, if there was an override of Arrange that took an additional parameter for an array of types, then we could call MakeByRefType().

That at least is how I can find the MethodInfo object using reflection.
0
Aaron
Top achievements
Rank 1
answered on 14 Dec 2012, 08:50 PM
I'm sorry.  It appears that my question was answered by a similar question with this answer: http://www.telerik.com/community/forums/justmock/general-discussions/using-doinstead-for-a-private-method.aspx#2413199

I'll watch for updates, including internal builds, that may have an update for this kind of thing.
Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Share this question
or