I'm dealing with a brownfield app. Due to high complexity and no existing tests, dependency injection is not an option at this point. This code also does not program to interfaces. So any solution I come up with has to not use DI or interfaces.
I'm looking at fakeiteasy to see if it can provide us with some test capabilities that do not require major refactoring efforts. I'm also considering Microsoft Fakes if I can manage to get a license for it.
Specifically, I want to know if I can override a base class implementation while also testing the derived class:
[TestMethod]
public void Test()
{
//I want SomeBase to be fully mocked.
var baseFake = A.Fake<SomeBase>();
//Class under test. Create wrapper - unconfigured calls will be forwarded to wrapped
SomeDerived someDerived = new SomeDerived();
var derivedFakeWrapper = A.Fake<SomeDerived>(x => x.Wrapping(someDerived));
A.CallTo(() => derivedFakeWrapper.OtherCall()).DoesNothing();
//A.CallTo(() => derivedFakeWrapper.SomeCall()).DoesNothing();//This works. But I want to test SomeCall()
A.CallTo((() => derivedFakeWrapper.DoWork())).DoesNothing();//SomeCall makes a call to DoWork(). DoWork() should do nothing
A.CallTo((() => baseFake.DoWork())).DoesNothing();//Tried sticking somethin in the base
derivedFakeWrapper.SomeCall();
derivedFakeWrapper.OtherCall();
}
public class SomeBase
{
public virtual void DoWork()
{
Console.WriteLine("base implementation");
}
}
public class SomeDerived : SomeBase
{
public virtual void SomeCall()
{
Console.WriteLine("Do other work");
DoWork();
}
public virtual void OtherCall()
{
Console.WriteLine("Other call working normally");
}
}