dimanche 24 juillet 2016

unit test c# mock interface composed inside another interface

Im novice to coding. I have a class -

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();
}

I want to test functionA where I can penetrate into all the three method of interfaceB.In my unit test, I create instance ofclass A and when i call it im not able to set the behavior of Class B. It keeps hitting the db, however I need it for other test cases. How do I completely mock this so that I can test the entire logic?

Aucun commentaire:

Enregistrer un commentaire