I have an interface IFoo
public interface IFoo
{
void DoSomeStuff();
}
And I have two derived types FooImpl1 and FooImpl2:
public class FooImpl1 : IFoo
{
public void DoSomeStuff()
{
//...
}
}
public class FooImpl2 : IFoo
{
public void DoSomeStuff()
{
//Should do EXACTLY the same job as FooImpl1.DoSomeStuff()
}
}
I have a test class which tests IFoo contract of FooImpl1 :
private static IFoo FooFactory()
{
return new FooImpl1();
}
[Fact]
public void TestDoSomeStuff()
{
IFoo foo = FooFactory();
//Assertions.
}
How can I reuse this test class to test both FooImpl1 and FooImpl2?
How about having base class for
IFootests with abstract method returning appropriate implementation?Now, all derived types have to do is simply provide that one instance: