public void RequestReply_TelemetryIsWritten() { TestTelemetryChannel.Clear(); using (var host = new HostingContext <SimpleService, ISimpleService>()) { host.Open(); var binding = new NetTcpBinding(); var configuration = new TelemetryConfiguration(); var factory = new ChannelFactory <ISimpleService>(binding, host.GetServiceAddress()); ISimpleService channel = null; try { var behavior = new ClientTelemetryEndpointBehavior(configuration); #if NET40 factory.Endpoint.Behaviors.Add(behavior); #else factory.Endpoint.EndpointBehaviors.Add(behavior); #endif channel = factory.CreateChannel(); channel.GetSimpleData(); ((IClientChannel)channel).Close(); factory.Close(); Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0, "No telemetry events written"); } catch { if (channel != null) { ((IClientChannel)channel).Abort(); } factory.Abort(); throw; } } }
public void BehaviorAddsCustomBinding() { using (var host = new HostingContext <SimpleService, ISimpleService>()) { var binding = new NetTcpBinding(); var configuration = new TelemetryConfiguration(); var factory = new ChannelFactory <ISimpleService>(binding, host.GetServiceAddress()); ISimpleService channel = null; try { var behavior = new ClientTelemetryEndpointBehavior(configuration); #if NET40 factory.Endpoint.Behaviors.Add(behavior); #else factory.Endpoint.EndpointBehaviors.Add(behavior); #endif channel = factory.CreateChannel(); var innerChannel = GetInnerChannel(channel); ((IClientChannel)channel).Close(); factory.Close(); Assert.IsInstanceOfType(innerChannel, typeof(ClientTelemetryChannelBase), "Telemetry channel is missing"); } catch { factory.Abort(); if (channel != null) { ((IClientChannel)channel).Abort(); } throw; } } }