Mock a protected method
<p>I've looked through almost every link I can possibly find on google to do with this subject and have come up with two of the following solutions which do not run correctly. I have a protected method that simply returns a string.</p>

<pre><code>protected virtual string ConfirmText
    {
        get
        {
            return "someTextHere";
        }
    }
</code></pre>

<p>This is in a viewmodel. My tests so far that I have tried are -</p>

<pre><code>[TestMethod]
    public void Confirm_Text_test()
    {
        Mock&lt;TestViewModel&gt; testViewModel= new Mock&lt;TestViewModel&gt;(null, null, null);

        testViewModel.Protected()
            .Setup&lt;string&gt;("ConfirmText")
            .Returns("Ok")
            .Verifiable();


        testViewModel.Verify();
    }
</code></pre>

<p>I understand that with the above example I have only setup, and assert, not acted upon it. I haven't been able to find a way to act upon the set-up such as</p>

<pre><code>var result = testViewModel.ConfirmText;
</code></pre>

<p>as it says it is inaccessible due to its protection level.</p>

<p>The next way I have tried is</p>

<pre><code>var result = testViewModel.Object.GetType()
            .InvokeMember("ConfirmText",
             BindingFlags.InvokeMethod | 
             BindingFlags.NonPublic | 
             BindingFlags.Instance, 
             null, 
             testViewModel.Object, 
             null);
</code></pre>

<p>Am I missing something out, as most examples I've looked into show something similar to the first method I tried.</p>