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

3 posts, 0 answers
  1. Aaron
    Aaron avatar
    3 posts
    Member since:
    Nov 2012

    Posted 14 Dec 2012 Link to this post

    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. Aaron
    Aaron avatar
    3 posts
    Member since:
    Nov 2012

    Posted 14 Dec 2012 Link to this post

    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.

  3. Aaron
    Aaron avatar
    3 posts
    Member since:
    Nov 2012

    Posted 14 Dec 2012 Link to this post

    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.

Back to Top