如何将吸气剂模拟/注入被测系统? [英] how to mock/inject a getter into a system under test?
本文介绍了如何将吸气剂模拟/注入被测系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Mark provides an elegant answer to a related question.
我的课程具有只读属性:
My class has a read only property:
public class myclass
{
...
public virtual string Devicelocation => Message.Message.Items[0].ToString();
...
public someMethod()
{
if(Devicelocation=="YourMom")
{
//dostuff
}
else
{
//dootherstuff
}
}
}
我想执行 someMethod(),并假设Devicelocation等同于什么.
I would like to execute someMethod() with an assumption for what Devicelocation is equivalent to.
如何模拟或将值注入Devicelocation?
推荐答案
您可以像这样设置设备位置:
var stub = new Mock<myclass>();
stub.SetupGet(x => x.Devicelocation).Returns("YourMom");
stub.Object.Devicelocation will now return "YourMom".
更新:
stub.Object.someMethod();
这篇关于如何将吸气剂模拟/注入被测系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文