private void ValidateASingleMessageActionBased( Action <ApplicationInsightsTraceListener, TraceEventCache> callTraceAction, string instrumentationKey, TraceOptions options) { #pragma warning disable CS0618 // Type or member is obsolete TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel; #pragma warning restore CS0618 // Type or member is obsolete using (var listener = new ApplicationInsightsTraceListener(instrumentationKey)) { listener.TraceOutputOptions = options; TraceEventCache traceEventCache = new TraceEventCache(); #if NET452 PrivateObject privateObject = new PrivateObject(traceEventCache); privateObject.SetField("timeStamp", DateTime.Now.Ticks); privateObject.SetField("stackTrace", "Environment.StackTrace"); #else TypeInfo traceEventCacheType = traceEventCache.GetType().GetTypeInfo(); traceEventCacheType.GetDeclaredField("_timeStamp").SetValue(traceEventCache, DateTime.Now.Ticks); #endif callTraceAction(listener, traceEventCache); TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems.FirstOrDefault(); Assert.IsNotNull(telemetry, "didn't got the event trace to the inner channel"); Assert.AreEqual(telemetry.Context.InstrumentationKey, instrumentationKey); } }