我想在我的单元测试中创建一个继承类 StatelessService 的类 A 的实例。但我不能。我已经尝试了一切:模拟依赖项,实现我自己的上下文等等。
当我尝试创建实例时,StatelessService 在内部某处抛出 NullReferenceException。
可以做到吗?
class A : StatelessService
{
public A(StatelessServiceContext context) : base(context /* Here will be thrown NullReferenceException */)
{
// It will never even get there.
}
}
class UnitTest
{
public void TestMethod()
{
var activationContext = MOCK<ICodePackageActivationContext>();
var context = new StatelessServiceContext(..., activationContext, ...);
var a = new A(context); // Here will be thrown an exception.
}
}