public void TestView() { List <ITelemetry> sentTelemetry = new List <ITelemetry>(); TelemetryModule telemetryModule = Helpers.GetTelemetryModule(sentTelemetry, this.testTelemetryKey); telemetryModule.View("A View", new Dictionary <string, string>() { { "AKey", $"AValue" } }); List <TelemetryItem> mapped = DoTheMapping(sentTelemetry); Assert.AreEqual(TelemetryItemTypes.View, mapped.Single().TelemetryItemType); Assert.AreEqual("AValue", mapped[0].Properties["AKey"]); Assert.AreEqual(1, mapped[0].Properties.Count); }
public void CheckListOfItems() { List <ITelemetry> sentTelemetry = new List <ITelemetry>(); TelemetryModule telemetryModule = Helpers.GetTelemetryModule(sentTelemetry, this.testTelemetryKey); telemetryModule.Event("TestEvent", new Dictionary <string, string>() { { "AKey", $"AValue" } }); telemetryModule.View("TestView"); telemetryModule.Log(LogLevel.Warn, "A log message"); telemetryModule.Exception(new Exception("An error that happened")); telemetryModule.Exception(new Exception("An error that happened with note"), "A note for error"); byte[] serialized = JsonSerializer.Serialize(sentTelemetry, true); var items = AppInsightsDeserializer.Deserialize(serialized, true).ToList(); var mapped = AppInsightsTelemetryMapper.Map(items).ToList(); for (int index = 0; index < sentTelemetry.Count; index++) { ITelemetry appInsightsItem = sentTelemetry[index]; TelemetryItem telimenaItem = mapped[index]; Assert.AreEqual(appInsightsItem.Timestamp, telimenaItem.Timestamp); Assert.AreEqual(appInsightsItem.Sequence, telimenaItem.Sequence); Assert.AreEqual(appInsightsItem.Context.User.Id, telimenaItem.UserIdentifier); if (telimenaItem.TelemetryItemType != TelemetryItemTypes.LogMessage && telimenaItem.TelemetryItemType != TelemetryItemTypes.Exception) { Assert.AreEqual(appInsightsItem.GetPropertyValue <string>("Name"), telimenaItem.EntryKey); } foreach (KeyValuePair <string, string> keyValuePair in appInsightsItem.GetPropertyValue <ConcurrentDictionary <string, string> >("Properties")) { var props = typeof(TelimenaContextPropertyKeys).GetProperties().Select(x => x.Name); if (!props.Contains(keyValuePair.Key)) { Assert.AreEqual(keyValuePair.Value, telimenaItem.Properties[keyValuePair.Key]); } } } }