Registering NUnit DynamicMock Instances in a UnityContainer
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-04-09T18:50:13Z
Indexed on
2010/04/09
18:53 UTC
Read the original article
Hit count: 405
I'm somewhat new to Unity and dependency injection. I'm trying to write a unit test that goes something like this:
[Test]
public void Test()
{
UnityContainer container = new UnityContainer();
DynamicMock myMock = new DynamicMock(typeof(IMyInterface));
container.RegisterInstance(typeof(IMyInterface), myMock.MockInstance); //Error here
// Continue unit test...
}
When this test executes, the container throws an ArgumentNullException inside the RegisterInstance method with the message Value cannot be null. Parameter name: assignmentValueType.
The top line of the stack trace is at Microsoft.Practices.Unity.Utility.Guard.TypeIsAssignable(Type assignmentTargetType, Type assignmentValueType, String argumentName)
.
Why can't I register a MockInstance with the UnityContainer, and how do I work around this?
© Stack Overflow or respective owner