title: Mocking return values of a concrete class method using Moq
body: <p>I have an abstract factory like this.</p>
  
  <pre><code>public abstract class AbstractFactory
  {
      public abstract ISyncService GetSyncService(EntityType entityType);
  }
  </code></pre>
  
  <p>And I have its concrete implementation like this.</p>
  
  <pre><code>public class SyncFactory : AbstractFactory
  {
      private readonly IOperatorRepository _operatorRepository;
  
      public SyncFactory( IOperatorRepository operatorRepository)
      {
          _operatorRepository = operatorRepository;
      }
  
      public override ISyncService GetSyncService(EntityType entityType)
      {            
              return new OperatorSyncService(_operatorRepository);           
      }
  }
  </code></pre>
  
  <p>This concrete factory is accessed in a method like this.</p>
  
  <pre><code>public void MethodTobeTested()
  {
      var syncService =
                  new SyncFactory(_operatorRepository).GetSyncService(entityType);
  }
  </code></pre>
  
  <p>Now I need to write a unit test for MethodTobeTested().</p>
  
  <p>I mocked the return value of the GetSyncService() like this. But it's calling the actual OperatorSyncService, not the mock. I need this mock to mock another method inside OperatorSyncService </p>
  
  <pre><code>private Mock&lt;SyncFactory&gt; _syncServiceMock;
  _syncServiceMock = new Mock&lt;SyncFactory&gt;();
  
  _syncServiceMock.Setup(m =&gt; m.GetSyncService(operator)).Returns(_operatorSyncServiceMock.Object);
  </code></pre>
  
  <p>Any idea on how to resolve this?</p>