title: Rhino Mocks Partial Mock
body: <p>I am trying to test the logic from some existing classes. It is not possible to re-factor the classes at present as they are very complex and in production.</p>
  
  <p>What I want to do is create a mock object and test a method that internally calls another method that is very hard to mock.</p>
  
  <p>So I want to just set a behaviour for the secondary method call. </p>
  
  <p>But when I setup the behaviour for the method, the code of the method is invoked and fails. </p>
  
  <p>Am I missing something or is this just not possible to test without re-factoring the class?</p>
  
  <p>I have tried all the different mock types (Strick,Stub,Dynamic,Partial ect.) but they all end up calling the method when I try to set up the behaviour.</p>
  
  <pre><code>using System;
  using MbUnit.Framework;
  using Rhino.Mocks;
  
  namespace MMBusinessObjects.Tests
  {
      [TestFixture]
      public class PartialMockExampleFixture
      {
          [Test]
          public void Simple_Partial_Mock_Test()
          {
              const string param = "anything";
  
              //setup mocks
              MockRepository mocks = new MockRepository();
  
  
              var mockTestClass = mocks.StrictMock&lt;TestClass&gt;();
  
              //record beahviour *** actualy call into the real method stub ***
              Expect.Call(mockTestClass.MethodToMock(param)).Return(true);
  
              //never get to here
              mocks.ReplayAll();
  
              //this is what i want to test
              Assert.IsTrue(mockTestClass.MethodIWantToTest(param));
  
  
          }
  
          public class TestClass
          {
              public bool MethodToMock(string param)
              {
                  //some logic that is very hard to mock
                  throw new NotImplementedException();
              }
  
              public bool MethodIWantToTest(string param)
              {
                  //this method calls the 
                  if( MethodToMock(param) )
                  {
                      //some logic i want to test
                  }
  
                  return true;
              }
          }
      }
  }
  </code></pre>