lundi 28 décembre 2015

How to test a class that sets up its properties on constructor?

I have a lot of classes implementing some interfaces and I built some classes that "coordinates" the usage. So, I created a base class that contains the orchestration, and built a class for each combination of these interface implementations that I needed. Something like this:

public abstract class BaseDirector
{
   public IInterfaceA A { get; set; }
   public IInterfaceB B { get; set; }

   public virtual void Do()
   {
      A.Do();
      B.Do();
   }
}

public class Director1: BaseDirector
{
   public Director1()
   {
      A = new A1();
      B = new B2();
   }
}

public class Director2: BaseDirector
{
   public Director2()
   {
      A = new A2();
      B = new B12();
   }
}

It smells bad and I don't see how I can test this. Can someone give some directions on how to test this? Do I need to change the approach on "director" classes?

Aucun commentaire:

Enregistrer un commentaire