我有一个WCF服务:
[ServiceTelemetry]
public class MyWCFClass()
{
private TelemetryClient telemetryClient;
public MyWCFClass()
{
telemetryClient = new TelemetryClient()
{
InstrumentationKey = RoleEnvironment.GetConfigurationSettingValue("APPINSIGHTS_INSTRUMENTATIONKEY")
};
}
public string TheMethod()
{
return "Nice";
}
}
像魅力一样工作。现在我想对这个WCF服务进行单元测试:
[TestMethod()]
public void DoTest()
{
MyWCFClass theClass = new MyWCFClass();
Assert.AreEqual("Nice", theClass.TheMethod());
}
我的问题是,当我运行测试时,WCFClass的构造函数会发生SEH异常。
有没有办法伪造RoleEnvironment部分或跳过遥测部分?