I have an abstract class with a dependency which I would like to unit test:
public abstract class BaseClass
{
public BaseClass(IDependency dep) { ... }
public virtual void TestMethod() { ... }
...
}
I want to test this class using NInject's MockingKernel, so I drummed up the following:
using (var k = new MoqMockingKernel())
{
k.Bind<IDependency>().ToMock();
k.Bind<BaseClass>().ToMock();
k.GetMock<BaseClass>().CallBase = true;
var sut = k.Get<BaseClass>();
sut.TestMethod();
k.GetMock<BaseClass>().Verify(...);
}
but I'm running into a problem. It's looking for a parameterless constructor to create the partial BaseClass mock rather than passing the mocked IDependency in.
Looking at the source, it appears MockingKernel will never pass arguments to a mock at creation time.
Is there any way to create a partial mock with MockingKernel?