title: The right way to mock (with moq) methods that return mocked objects?
body: <p>Which of these is correct?</p>
  
  <pre><code>var mockLogger = new Mock&lt;EntLibLogger&gt;();
  mockLogger.Setup(i =&gt; i.CreateTracer(It.IsAny&lt;string&gt;()))
      .Returns((string operationName) =&gt;
          {
              var mockTracer = new Mock&lt;EntLibTracer&gt;(operationName);
              mockTracer.Setup(i =&gt; i.IsTracingEnabled())
                  .Returns(true);
              mockTracer.CallBase = true;
  
              return mockTracer.Object;
          });
  mockLogger.CallBase = true;
  
  //EntLibLogger.Current is a singleton that is shared across multiple threads.
  //This Initialize method will set EntLibLogger.Current to the mocked instance
  //instead of the default (non-mocked) configuration
  EntLibLogger.Initialize(mockLogger.Object);
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>var mockTracer = new Mock&lt;EntLibTracer&gt;(operationName);
  mockTracer.Setup(i =&gt; i.IsTracingEnabled())
      .Returns(true);
  mockTracer.CallBase = true;
  
  var mockLogger = new Mock&lt;EntLibLogger&gt;();
  mockLogger.Setup(i =&gt; i.CreateTracer(It.IsAny&lt;string&gt;()))
      .Returns(mockTracer.Object);
  mockLogger.CallBase = true;
  
  EntLibLogger.Initialize(mockLogger.Object);
  </code></pre>
  
  <p>I believe the first approach is correct but I am not sure if Moq might be doing some magic under the hood and just wanted to validate :)</p>