vendredi 30 juin 2017

Unittest WCF service without RoleEnvironment/Telemetry client

I have a WCF Service:

[ServiceTelemetry]
public class MyWCFClass()
{
    private TelemetryClient telemetryClient;

    public MyWCFClass()
    {
        telemetryClient = new TelemetryClient()
        {
            InstrumentationKey = RoleEnvironment.GetConfigurationSettingValue("APPINSIGHTS_INSTRUMENTATIONKEY")
        };
    }
    public string TheMethod()
    {
        return "Nice";
    }
}

Works like a charm. Now I want to unit test this WCF service:

[TestMethod()]
public void DoTest()
{
    MyWCFClass theClass = new MyWCFClass();
    Assert.AreEqual("Nice", theClass.TheMethod());
}

My problem is, that when I run the test, an SEH exception occurs on the constructor of the WCFClass.

Is there any way to fake the RoleEnvironment part or skip the telemetry part?

Aucun commentaire:

Enregistrer un commentaire