Moq with constructor argument
I have a factory that looks like below:
public IFoo GetFoo(IFile file开发者_Go百科)
{
return _kernel.Get<IFoo>(new ConstructorArgument("file", file));
}
It works fine until I use Moq to mock IFoo
. In the mock there is no constructor argument named file, and I get a Ninject.ActivationException.
How should I solve this?
You should be mocking your factory during testing. Hopefully, the "GetFoo" method is part of your factory interface. Mock the factory and then you can set up the factory to return whatever IFoo you want (a test IFoo or perhaps a mock IFoo).
精彩评论