title: unit test c# mock interface composed inside another interface
body: <p>I'm a novice to coding.</p>
  
  <p>I have a class, <code>A</code>:</p>
  
  <pre><code>public class A 
  {
      public InterfaceB _b;   
  
      public A() 
      {  
          _b = new B(); 
      } 
  
      public string functionA() 
      {
          if(String.IsNullOrEmpty(_b.GetId())) 
              return String.Empty;
          else if(String.IsNullOrEmpty(_b.GetKey())) 
              return String.Empty;
          else  
              return _b.GetToken(); 
      } 
  } 
  
  public interface InterfaceB 
  {    
      string GetId();   
      string GetKey(); 
      string GetToken();
  }
  </code></pre>
  
  <p>I want to test <code>functionA</code> where I can penetrate into all the three method of <code>interfaceB</code>. In my unit test, I create an instance of class <code>A</code> and when I call it I'm not able to set the behavior of class <code>B</code>.</p>
  
  <p>It keeps hitting the db, however I need it for other test cases.</p>
  
  <p>How do I completely mock this so that I can test the entire logic?</p>