Exemple #1
0
        public void TestLogMessage()
        {
            List <ITelemetry> sentTelemetry   = new List <ITelemetry>();
            TelemetryModule   telemetryModule = Helpers.GetTelemetryModule(sentTelemetry, this.testTelemetryKey);

            telemetryModule.Log(LogLevel.Warn, "A Message");

            List <TelemetryItem> mapped = DoTheMapping(sentTelemetry);

            Assert.AreEqual(TelemetryItemTypes.LogMessage, mapped.Single().TelemetryItemType);
            Assert.AreEqual(LogLevel.Warn.ToString(), mapped.Single().LogLevel.ToString());
            Assert.AreEqual((int)LogLevel.Warn, (int)mapped.Single().LogLevel);
            Assert.AreEqual((sentTelemetry[0] as TraceTelemetry).Message, mapped[0].LogMessage);
        }
Exemple #2
0
        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]);
                    }
                }
            }
        }