public void PublishTelemetryEventContainer_TelemetryIsEnabled_EnablesAndChainsThrough() { using (ShimsContext.Create()) { // Specific values of TelemetryAction and TelemetryProperty are unimportant for this test TelemetryAction action = (TelemetryAction)6; TelemetryProperty property = (TelemetryProperty)7; var fakeId = "id"; var fakeEvent = new TelemetryEvent(action, new Dictionary <TelemetryProperty, string> { { property, fakeId }, }); string actualName = null; IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null; ITelemetry telemetry = new StubITelemetry { PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) => { actualName = name; actualTelemetryPropertyBag = telemetryPropertyBag; } }; TelemetrySink.IsTelemetryAllowed = true; ShimTelemetrySink.TelemetryGet = () => telemetry; Logger.PublishTelemetryEvent(fakeEvent); Assert.AreEqual(fakeEvent.Action.ToString(), actualName); Assert.AreEqual(1, actualTelemetryPropertyBag.Count); Assert.AreEqual(fakeId, actualTelemetryPropertyBag[property.ToString()]); } }
public void AddOrUpdateContextProperty_SinkIsEnabled_ChainsToSink() { _sinkMock.Setup(x => x.IsEnabled).Returns(true); _sinkMock.Setup(x => x.AddOrUpdateContextProperty(Property1.ToString(), Value1)); Logger.AddOrUpdateContextProperty(Property1, Value1); _sinkMock.VerifyAll(); }
public void PublishTelemetryEvent_SingleProperty_SinkIsEnabled_ChainsToSink() { _sinkMock.Setup(x => x.IsEnabled).Returns(true); _sinkMock.Setup(x => x.PublishTelemetryEvent(Action1.ToString(), Property3.ToString(), Value2)); Logger.PublishTelemetryEvent(Action1, Property3, Value2); _sinkMock.VerifyAll(); }
/// <summary> /// Explicitly updates context properties to be appended to future calls to the current telemetry pipeline /// </summary> /// <param name="property"></param> /// <param name="value"></param> public static void AddOrUpdateContextProperty(TelemetryProperty property, string value) { if (!IsEnabled) { return; } TelemetrySink.AddOrUpdateContextProperty(property.ToString(), value); }
/// <summary> /// Publishes event with single property/value pair to the current telemetry pipeline /// </summary> /// <param name="action"></param> /// <param name="property"></param> /// <param name="value"></param> public static void PublishTelemetryEvent(TelemetryAction action, TelemetryProperty property, string value) { // Conversions to strings are expensive, so skip it if possible if (!IsEnabled) { return; } TelemetrySink.PublishTelemetryEvent(action.ToString(), property.ToString(), value); }