ฉันค่อนข้างใหม่กับ Unity และการพึ่งพาการฉีด ฉันกำลังพยายามเขียน Unit Test ที่มีลักษณะดังนี้:
[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...
}
เมื่อดำเนินการทดสอบนี้ คอนเทนเนอร์จะส่ง ArgumentNullException ภายในเมธอด RegisterInstance พร้อมด้วยข้อความ Value cannot be null. Parameter name: assignmentValueType.
บรรทัดบนสุดของการติดตามสแต็กคือ at Microsoft.Practices.Unity.Utility.Guard.TypeIsAssignable(Type assignmentTargetType, Type assignmentValueType, String argumentName)
เหตุใดฉันจึงไม่สามารถลงทะเบียน MockInstance กับ UnityContainer ได้ และฉันจะแก้ไขปัญหานี้ได้อย่างไร