是否可以模拟Specflow';情景语境?(C#)
尝试为使用ScenarioContext的Specflow步骤编写单元测试。此步骤尝试从ScenarioContext检索属性的值。是否可以模拟ScenarioContext,以便设置此属性的值 在本地使用VS professional和Moq框架。谢谢 据我所知,ScenarioContext没有实现任何接口。在ScenarioContext上尝试模拟失败(原因在下面的代码块中)是否可以模拟Specflow';情景语境?(C#),c#,unit-testing,specflow,C#,Unit Testing,Specflow,尝试为使用ScenarioContext的Specflow步骤编写单元测试。此步骤尝试从ScenarioContext检索属性的值。是否可以模拟ScenarioContext,以便设置此属性的值 在本地使用VS professional和Moq框架。谢谢 据我所知,ScenarioContext没有实现任何接口。在ScenarioContext上尝试模拟失败(原因在下面的代码块中) private Mock\u propertyBucket; 行政长官(){ var mo=new Mock();
private Mock\u propertyBucket;
行政长官(){
var mo=new Mock();//由于ScenarioContext没有公共构造函数,此行失败。
Add(“response”,response);//此属性是specflow步骤最终使用的属性
_propertyBucket=new Mock();
_Setup(pb=>pb.ScenarioContext).Returns(mo.Object);
}
仅供参考:我正在研究一个多框架目标解决方案。该框架适用于net472和netCore3.1.x。ScenarioContext的实现在.Net Core和.Net framework之间是不同的。您尝试过什么吗?关于ScenarioContext类型,Intellisense告诉了你什么?嗨@GregBurghardt,我用我到目前为止尝试过的方法更新了这个问题。ThankscenarioContext继承自Dictionary,后者实现IDictionary。
private Mock<IPropertyBucket> _propertyBucket;
ctor(){
var mo = new Mock<ScenarioContext>(); // this line fails as ScenarioContext has no public contructor.
mo.Object.Add("response", Response); // this property is what the specflow step is using eventually
_propertyBucket = new Mock<IPropertyBucket>();
_propertyBucket.Setup(pb => pb.ScenarioContext).Returns(mo.Object);
}