Mock.NonPublic.Arrange with inherited non-overridden members doesn't seem to work.

2 posts, 0 answers
  1. Charles
    Charles avatar
    1 posts
    Member since:
    Sep 2010

    Posted 07 Mar 2011 Link to this post

    I just started using JustMock but I've searched for a solution to this problem and haven't found it yet so I'll pose the problem here.
    As in the distilled example below, I have a class that inherits from another class.  The parent class defines multiple protected virtual methods that the child class does not override.  I'm interested in testing a specific protected virtual method the child does implement but my attempts to mock the non-overridden parent methods fail with the following exception:

    [System.ArgumentException] = {"Could not resolve the target method; make sure that you have provided arguments correctly."}

    (In the example, it is thrown on the call to Mock.NonPublic.Arrange(..) )

    Am I doing something wrong? Is there a way within JustMock to get around this error? Or must I subclass my child class further and override all the methods I'm interested in mocking in order to get it to work?  That last option does work, but it's not exactly ideal.
    Any help is greatly appreciated!


    public class Foo
        public Foo()
        protected virtual void MethodToMock()
        protected virtual void MethodToTest()
    public class Bar : Foo
        public Bar()
        protected override void MethodToTest()
    public void BarTest()
        var mock = Mock.Create<Bar>(Behavior.CallOriginal);
        Mock.NonPublic.Arrange(mock, "MethodToMock").DoNothing();
        // Test MethodToTest here
  2. Ricky
    Ricky avatar
    467 posts

    Posted 09 Mar 2011 Link to this post

    Hi Charles,

    Thanks again for sending the issue. You are right about the problem. It should not throw any exception when mocking non virtual protected member from base class. However, this is issue is fixed and will go out with the Q1 build in few days.

    Sorry for the inconvenience and please do feel free to report any further exceptions that you might encounter or might seem inappropriate to you. We would love to assists you.

    Kind Regards,
    the Telerik team

    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft R3 2016 release webinar banner
Back to Top