title: How to mock the functionality of the test class itself using Moq in ASP.NET MVC unit test
body: <p>I am developing an ASP.NET MVC project. In my project, I am doing unit testing. I use Moq for unit test. But I am having a problem with testing a method of a model class that has dependency on another of its functions.</p>
  
  <p>This is the sample of model class that I want to test</p>
  
  <pre><code>public class ItemRepo:IItemRepo
  {
      private DbContext context = new DbContext();
  
      public IEnumerable&lt;Item&gt; GetItems()
      {
          return context.items;
      }
  
      public string GenerateItemCode()
      {
         Item item = this.GetItems.OrderByDescending(x=&gt;x.Id).FirstOrDefault();
         //do something
         return itemCode;
      }
  }
  </code></pre>
  
  <p>I want to test GenerateItemCode method</p>
  
  <pre><code>    [TestClass]
      public class ItemRepoTests
      {
          [TestMethod]
          public void GenerateItemCode_IncreaseDigit()
          {
              Item[] items = new Item[]{
                  new Item{
                      ItemCode = "DN999934"
                  }
              };
              ItemRepo itemRepo = new ItemRepo();
              //I want to mock GetItems method here
          }
      }
  </code></pre>
  
  <p>I commented what I want to mock in test code. How can I mock that method? How can I unit test that method mocking dependency function?</p>