We might get into a little of a purist argument on this one, but I might actually just stub out a derived class and skip mocking altogether. Yeah, a little longer and a little messier, but it doesn't require any special understanding of what's going on for later test maintainers.
public abstract MyClass
{
public MyClass()
{
MyMethod();
}
protected abstract MyMethod();
}
[TestFixture]
publc UnitTests
{
[Test]
public void MyMethodGetsCalled()
{
DerivedClass testObject = new DerivedClass();
Assert.IsTrue(testObject.MyMethodWasCalled);
}
public DerivedClass : MyClass
{
public bool MyMethodWasCalled = false;
protected override MyMethod()
{
this.MyMethodWasCalled = true;
}
}
}