title: MOQ returning null. [mock concrete class method]
body: <p>[using Moq]</p>
  
  <p>I am trying to mock a concrete class and mock a virtual method "Get()" of that class. When testing a method "GetItemsNotNull()" I always get returned null, instead of the return of the mocked function.</p>
  
  <p>Here is the code</p>
  
  <hr>
  
  <pre><code>//SomeClasses.cs
  namespace MoQExamples
  {
      public abstract class Entity
      {
  
      }
  
      public class Abc : Entity
      {
  
      }
  
      public interface IRepository&lt;T&gt; where T : Entity
      {
          IQueryable&lt;T&gt; Get();
      }
  
      public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : Entity
      {
          private readonly ISession _session;
  
          public Repository()
          {
              _session = null;
          }
  
          public Repository(ISession session)
          {
              _session = session;
          }
  
          protected ISession CurrentSession
          {
              get { return _session; }
          }
  
          public virtual IQueryable&lt;T&gt; Get()
          {
              return CurrentSession.Query&lt;T&gt;();
          }
  
      }
  
      public interface IAbcRepository
      {
          Abc GetItemsNotNull();
      }
  
      public class AbcRepository : Repository&lt;Abc&gt;, IAbcRepository
      {
          public Abc GetItemsNotNull()
          {
              return Get().FirstOrDefault(abc =&gt; abc !=null);
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p>and here are the test class</p>
  
  <pre><code>namespace MoQExamples
  {
      [TestFixture]
      public class SomeClassesTest
      {
          private readonly Mock&lt;AbcRepository&gt; _abcRepositoryMock = new Mock&lt;AbcRepository&gt;(MockBehavior.Strict) { CallBase = true };
  
          [SetUp]
          public void SetupTest()
          {
              _abcRepositoryMock.Setup(x =&gt; x.Get()).Returns(Get);
          }
  
          public IQueryable&lt;Abc&gt; Get()
          {
              return (new List&lt;Abc&gt;() { new Abc() }) as IQueryable&lt;Abc&gt;;
          }
  
          [Test]
          public void TestGetItemsNotNull()
          {
              Assert.IsNotNull(_abcRepositoryMock.Object.GetItemsNotNull());
          }
  
      }
  }
  </code></pre>
  
  <p>the assert alays fails..instead of returning the SomeClassesTest.Get()</p>
  
  <p>thanks for advance guys!</p>