title: Rhino Mock - Stubbed method always returns null
body: <p>I've been trying to figure out what is happening with this particular test that I'm writing and now reaching out again to see if someone might know what is going on.</p>
  
  <p>I have a ModeltoXml method that when I test via another test class directly, it's fine.  However in another method I'm testing which makes a call to ModeltoXml my stub created in Rhino Mock always returns null.</p>
  
  <p>Below is roughly how my code looks for the test where I pass my stubbed methods in via the constructor.</p>
  
  <pre><code>[Test]
  
     var newEntry = new Model1{name="test"};
         var referrer = "http://example.com";
  
         var stubbedConfigMan = MockRepository.GenerateStub&lt;IConfigurationManager&gt;();
         var supportMethods = MockRepository.GenerateStub&lt;ISupportMethods&gt;();
         stubbedConfigMan.Stub(x =&gt; x.GetAppSetting("confEntry1")).Return("pathhere");
         supportMethods.Stub(x =&gt; x.ModeltoXml(newEntry)).IgnoreArguments().Return("test"); //this is the line of code which should be setting the return value
  
   var testObject = new MyApi().NewTicket(newEntry, referrer, supportMethods, stubbedConfigMan);
  </code></pre>
  
  <p>The concrete method that is invoked for this test has a line which looks like this:</p>
  
  <pre><code> public MyResponseModel NewTicket(Model1 newTicket, string referrer,     ISupportMethods supportMethods,IConfigurationManager configMan)
  {
  //.. other code here
     var getXml = supportMethods.ModeltoXml(newTicket);  //This line always returns null
  }
  </code></pre>
  
  <p>A simple entry for the ModeltoXml method:</p>
  
  <pre><code>public string ModeltoXml&lt;T&gt;(T item)
  {
  //Code here to serialize response
  
         return textWriter.ToString();
     }
  </code></pre>
  
  <p>And what I have on my interface:</p>
  
  <pre><code>public interface ISupportMethods
  {
    string ModeltoXml&lt;T&gt;(T item);
  }
  </code></pre>
  
  <p>I created another basic method which would except and return a string value.  I got this working in the same class however in the test I had to use the .IgnoreArguments option on the stub.  Thereafter when debugging I was seeing the set return value.</p>
  
  <p>However when I tried doing the same on the problematic line of code in my test class, I still see no return value appearing in my class under test during debug.</p>
  
  <p>So I'm a tad stuck!  I'm getting return values on other stubs in my test and it's this particular method/stub which just wont play ball.  </p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>A more simple example of the above I've found is under the same test:</p>
  
  <pre><code>       var stubbedConfigMan = MockRepository.GenerateStub&lt;IConfigurationManager&gt;();
         var supportMethods = MockRepository.GenerateStub&lt;ISupportMethods&gt;();
  
          supportMethods.Stub(x =&gt; x.ModeltoXml(newEntry)).IgnoreArguments().Return("test").Repeat.Any();
  
  //the class under test is successfully returning 'hero' when this method is called.
         supportMethods.Stub(x =&gt; x.mytest(Arg&lt;string&gt;.Is.Anything)).Return("hero");
  
  //If I use this line and debug test9 is set with my return value of "test".
  //However in the same run my class under test the method just returns null.
      var test9 = supportMethods.ModeltoXml(newEntry);
  
     var testObject = new MyApi().NewTicket(newEntry, referrer, supportMethods, stubbedConfigMan);
  </code></pre>
  
  <p>What the above examples shows is that passing my mocked/stub objects over to my class under test, something happens with the ModeltoXml stub.  I can't see/think of any reason why this is happening.</p>