title: Partial mocking of class with Moq
body: <p>I want to mock only the <code>GetValue</code> method of the following class, using Moq:</p>
  
  <pre><code>public class MyClass
  {
      public virtual void MyMethod()
      {
          int value = GetValue();
          Console.WriteLine("ORIGINAL MyMethod: " + value);
      }
  
      internal virtual int GetValue()
      {
          Console.WriteLine("ORIGINAL GetValue");
          return 10;
      }
  }
  </code></pre>
  
  <p>I already read a bit how this should work with Moq. The solution that I found online is to use the <code>CallBase</code> property, but that doesn't work for me.</p>
  
  <p>This is my test:</p>
  
  <pre><code>[Test]
  public void TestMyClass()
  {
       var my = new Mock&lt;MyClass&gt; { CallBase = true };
       my.Setup(mock =&gt; mock.GetValue()).Callback(() =&gt; Console.WriteLine("MOCKED GetValue")).Returns(999);
       my.Object.MyMethod();
       my.VerifyAll();
   }
  </code></pre>
  
  <p>I would expect that Moq uses the existing implementation of <code>MyMethod</code> and calls the mocked method, resulting in the following output:</p>
  
  <pre><code>ORIGINAL MyMethod: 999
  MOCKED GetValue
  </code></pre>
  
  <p>but that's what I get :</p>
  
  <pre><code>ORIGINAL GetValue
  ORIGINAL MyMethod: 10
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>Moq.MockVerificationException : The following setups were not matched: MyClass mock =&gt; mock.GetValue()
  </code></pre>
  
  <p>I got the feeling, that I misunderstood something completely. What am I missing here?
  Any help would be appreciated</p>