title: Unit Testing One Method Calls Another Method in the Same Class
body: <p>I have two public methods on a class, both are called from external code, but one of the methods also calls the other. I want to unit test the one method and just verify it calls the other public method in the same class, and then I would have separate tests to test the other second method. The structure would look something like this:</p>
  
  <pre><code>public CalculatedResult GetCalculatedDetailsById(Guid id)
  {
    var entity = _entityRepository.GetEntity(id);
    if(entity == null)
    {
      throw new NotFoundException();
    }
  
    return GetCalculatedDetailsForEntity(entity);
  }
  
  public CalculatedResult GetCalculatedDetailsForEntity(Entity entity)
  {
    var supplementalData = _someDependency.GetSupplementalData(entity.Property);
    var calculatedData = _someOtherDependency.ProcessEntity(entity, supplementalData);
  
    _cache.Set(calculatedData, expiry);
  
    return calculatedData;
  }
  </code></pre>
  
  <p>For <code>GetCalculatedDetailsForEntity</code>, I would mock the dependencies, verify they get called appropriately, verify the cache gets set properly, verify the return value is what is expected given the input provided and the mocked values.</p>
  
  <p>For <code>GetCalculatedDetailsById</code> I would mock the repository dependency, test that it called the <code>GetEntity</code> as expected, and that it throws an exception when necessary. Then I want to verify it calls <code>GetCalculatedDetailsForEntity</code> with the expected entity object, but I don't want to verify it does all the logic in <code>GetCalculatedDetailsForEntity</code>, as I'm already testing that elsewhere.</p>
  
  <p>Is it possible to mock <code>GetCalculatedDetailsForEntity</code> for the <code>GetCalculatedDetailsById</code> tests just so that I can verify it's getting called as expected?</p>
  
  <p>My tech stack is .NET Core, XUnit, and Moq.</p>