title: How to fake an object in NSubstitute and ignore its method's internal implementation?
body: <p>I'm new to NSubstitute and trying to fake an existing class named <code>OrgDataWS</code>. This class has a method named <code>GetDataSet</code>:</p>
  
  <pre><code> public XmlElement GetDataSet(int token)
   {
          string perfLogMessage = string.Format("Org.GetDataSet: {0}", Guid.NewGuid().ToString());
          MultiMessagePerformanceCounter performanceCounter = MultiMessagePerformanceCounter.StartNew(perfLogMessage);
          XmlElement result = orgDataManager.GetDataSet(token);
          performanceCounter.Stop();
  
          return result;
   }
  </code></pre>
  
  <p>The following is my test methods:</p>
  
  <pre><code> [TestMethod]
   public void GetDataSetTest()
   {
        var dataWSStub = Substitute.For&lt;OrgDataWS&gt;();
  
        var orgManagerStub = Substitute.For&lt;OrgDataManager&gt;();
  
        var document = new XmlDocument();
        var xmlElement = document.CreateElement("a");
        orgManagerStub.GetDataSet(Arg.Any&lt;int&gt;()).Returns&lt;XmlElement&gt;(xmlElement);
  
  
        dataWSStub.OrgDataManager = orgManagerStub;
  
  
        var result = dataWSStub.GetDataSet(99);
   }
  </code></pre>
  
  <p>However, when I run my test methods, this line </p>
  
  <pre><code>orgManagerStub.GetDataSet(Arg.Any&lt;int&gt;()).Returns&lt;XmlElement&gt;(xmlElement);
  </code></pre>
  
  <p>threw an exception. This exception is from the implementation of <code>OrgDataManager</code> class, from my understanding, this is not supposed to happen. The purpose of using that clause is that I hope if the <code>orgManagerStub</code>'s <code>DataDataSet</code> method is invoked with any <code>Int</code> parameter, just return my <code>xmlElement</code> instance. I didn't hope my code to run the detailed implementation of <code>OrgDataManager</code>. </p>
  
  <p>What's wrong with my test code? How to fix it?</p>