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

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

3 Answers 241 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?

3 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.
James
Top achievements
Rank 1
Iron
commented on 26 Jun 2025, 05:38 PM

That question is no longer available. I cannot figure out at all how to assign values to ref args in private method mocks.
0
Martin
Telerik team
answered on 27 Jun 2025, 06:42 AM

Hi James,

Here's the new URL to the question you mentioned: https://www.telerik.com/forums/using-doinstead-for-a-private-method

Best regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Martin
Telerik team
Share this question
or