public void PublishTelemetryEventContainer_TelemetryIsEnabled_EnablesAndChainsThrough() { using (ShimsContext.Create()) { var fakeId = "id"; var fakeEvent = new TelemetryEvent(TelemetryAction.ColorContrast_Click_Dropdown, new Dictionary <TelemetryProperty, string> { { TelemetryProperty.AppSessionID, 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[TelemetryProperty.AppSessionID.ToString()]); } }
public void AddOrUpdateContextProperty_TelemetryIsEnabled_DoesNothing() { using (ShimsContext.Create()) { const TelemetryProperty expectedProperty = TelemetryProperty.Comment; const string expectedValue = "carrot"; string actualProperty = null; string actualValue = null; StubITelemetry telemetry = new StubITelemetry { AddOrUpdateContextPropertyStringString = (property, value) => { actualProperty = property; actualValue = value; } }; ShimLogger.IsEnabledGet = () => true; ShimLogger.TelemetryGet = () => telemetry; Logger.AddOrUpdateContextProperty(expectedProperty, expectedValue); Assert.AreEqual(expectedProperty.ToString(), actualProperty); Assert.AreEqual(expectedValue, actualValue); } }
public void PublishTelemetryEvent_SingleProperty_TelemteryIsEnabled_EnablesAndChainsThrough() { using (ShimsContext.Create()) { // TelemetryAction used here is arbitrary const TelemetryAction action = TelemetryAction.ColorContrast_Click_Eyedropper; const TelemetryProperty property = TelemetryProperty.Comment; const string value = "Friday"; string actualName = null; IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null; ITelemetry telemetry = new StubITelemetry { PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) => { actualName = name; actualTelemetryPropertyBag = telemetryPropertyBag; } }; ShimLogger.IsEnabledGet = () => true; ShimLogger.TelemetryGet = () => telemetry; Logger.PublishTelemetryEvent(action, property, value); Assert.AreEqual(action.ToString(), actualName); Assert.AreEqual(1, actualTelemetryPropertyBag.Count); Assert.AreEqual(value, actualTelemetryPropertyBag[property.ToString()]); } }
public void AddOrUpdateContextProperty_TelemetryIsEnabled_DoesNothing() { using (ShimsContext.Create()) { // Specific value of TelemetryProperty is unimportant for this test const TelemetryProperty expectedProperty = (TelemetryProperty)9; const string expectedValue = "carrot"; string actualProperty = null; string actualValue = null; StubITelemetry telemetry = new StubITelemetry { AddOrUpdateContextPropertyStringString = (property, value) => { actualProperty = property; actualValue = value; } }; TelemetrySink.IsTelemetryAllowed = true; ShimTelemetrySink.TelemetryGet = () => telemetry; Logger.AddOrUpdateContextProperty(expectedProperty, expectedValue); Assert.AreEqual(expectedProperty.ToString(), actualProperty); Assert.AreEqual(expectedValue, actualValue); } }
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 PublishTelemetryEvent_SingleProperty_TelemteryIsEnabled_EnablesAndChainsThrough() { using (ShimsContext.Create()) { // Specific values of TelemetryAction and TelemetryProperty are unimportant for this test const TelemetryAction action = (TelemetryAction)4; const TelemetryProperty property = (TelemetryProperty)5; const string value = "Friday"; 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(action, property, value); Assert.AreEqual(action.ToString(), actualName); Assert.AreEqual(1, actualTelemetryPropertyBag.Count); Assert.AreEqual(value, actualTelemetryPropertyBag[property.ToString()]); } }
public void PublishTelemetryEvent_MultiProperty_TelemteryIsEnabled_EnablesAndChainsThrough() { using (ShimsContext.Create()) { // TelemetryAction used here is arbitrary const TelemetryAction action = TelemetryAction.ColorContrast_Click_Eyedropper; const TelemetryProperty property = TelemetryProperty.Error; const string value = "Saturday"; string actualName = null; IReadOnlyDictionary <TelemetryProperty, string> actualConverterInput = null; IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null; ITelemetry telemetry = new StubITelemetry { PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) => { actualName = name; actualTelemetryPropertyBag = telemetryPropertyBag; } }; ShimLogger.IsEnabledGet = () => true; ShimLogger.TelemetryGet = () => telemetry; Dictionary <string, string> expectedConverterOutput = new Dictionary <string, string> { { "abc", "def" }, }; ShimLogger.ConvertFromPropertiesIReadOnlyDictionaryOfTelemetryPropertyString = (input) => { actualConverterInput = input; return(expectedConverterOutput); }; Dictionary <TelemetryProperty, string> initalInput = new Dictionary <TelemetryProperty, string> { { property, value }, }; Logger.PublishTelemetryEvent(action, initalInput); Assert.AreEqual(action.ToString(), actualName); Assert.AreEqual(initalInput, actualConverterInput); Assert.AreSame(expectedConverterOutput, actualTelemetryPropertyBag); Assert.AreEqual(action.ToString(), actualName); } }
public void PublishTelemetryEvent_MultiProperty_TelemteryIsEnabled_EnablesAndChainsThrough() { using (ShimsContext.Create()) { // Specific values of TelemetryAction and TelemetryProperty are unimportant for this test const TelemetryAction action = (TelemetryAction)8; const TelemetryProperty property = (TelemetryProperty)9; const string value = "Saturday"; string actualName = null; IReadOnlyDictionary <TelemetryProperty, string> actualConverterInput = null; IReadOnlyDictionary <string, string> actualTelemetryPropertyBag = null; ITelemetry telemetry = new StubITelemetry { PublishEventStringIReadOnlyDictionaryOfStringString = (name, telemetryPropertyBag) => { actualName = name; actualTelemetryPropertyBag = telemetryPropertyBag; } }; TelemetrySink.IsTelemetryAllowed = true; ShimTelemetrySink.TelemetryGet = () => telemetry; Dictionary <string, string> expectedConverterOutput = new Dictionary <string, string> { { "abc", "def" }, }; ShimLogger.ConvertFromPropertiesIReadOnlyDictionaryOfTelemetryPropertyString = (input) => { actualConverterInput = input; return(expectedConverterOutput); }; Dictionary <TelemetryProperty, string> initalInput = new Dictionary <TelemetryProperty, string> { { property, value }, }; Logger.PublishTelemetryEvent(action, initalInput); Assert.AreEqual(action.ToString(), actualName); Assert.AreEqual(initalInput, actualConverterInput); Assert.AreSame(expectedConverterOutput, actualTelemetryPropertyBag); Assert.AreEqual(action.ToString(), actualName); } }
public void ReportException_IsNotEnabled_DoesNotChainThrough() { using (ShimsContext.Create()) { Exception expectedException = new Exception("blah"); StubITelemetry telemetry = new StubITelemetry { ReportExceptionException = (e) => { Assert.Fail("This should not be called"); } }; ShimLogger.IsEnabledGet = () => false; ShimLogger.TelemetryGet = () => telemetry; Logger.ReportException(expectedException); } }
public void ReportException_CalledAsExtension_IsEnabled_ExceptionIsNotNull_ChainsThrough() { using (ShimsContext.Create()) { Exception expectedException = new Exception("blah"); Exception actualException = null; StubITelemetry telemetry = new StubITelemetry { ReportExceptionException = (e) => { actualException = e; } }; ShimLogger.IsEnabledGet = () => true; ShimLogger.TelemetryGet = () => telemetry; expectedException.ReportException(); Assert.AreSame(expectedException, actualException); } }
public void ReportException_IsEnabled_ExceptionIsNull_DoesNotChainThrough() { using (ShimsContext.Create()) { Exception expectedException = null; Exception actualException = null; StubITelemetry telemetry = new StubITelemetry { ReportExceptionException = (e) => { Assert.Fail("This should not be called"); } }; ShimLogger.IsEnabledGet = () => true; ShimLogger.TelemetryGet = () => telemetry; Logger.ReportException(expectedException); Assert.IsNull(actualException); } }
public void ReportException_IsEnabled_ExceptionIsNotNull_ChainsThrough() { using (ShimsContext.Create()) { Exception expectedException = new Exception("blah"); Exception actualException = null; StubITelemetry telemetry = new StubITelemetry { ReportExceptionException = (e) => { actualException = e; } }; TelemetrySink.IsTelemetryAllowed = true; ShimTelemetrySink.TelemetryGet = () => telemetry; Logger.ReportException(expectedException); Assert.AreSame(expectedException, actualException); } }