Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
reyang committed Aug 12, 2021
1 parent 88d2543 commit 2f152ae
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions LOGGING/test/ILogger.Tests/ILoggerIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public void ApplicationInsightsLoggerPopulateStructureLoggingParamsIntoCustomPro
var customProperties = (itemsReceived[0] as TraceTelemetry).Properties;
Assert.IsTrue(customProperties["CustomerName"].Equals("TestCustomerName"));
Assert.IsTrue(customProperties["Age"].Equals("20"));
Assert.IsTrue(customProperties.ContainsKey("OriginalFormat"));
Assert.IsFalse(customProperties.ContainsKey("{OriginalFormat}"));
}

/// <summary>
Expand Down Expand Up @@ -227,16 +229,27 @@ public void ApplicationInsightsLoggerAddsScopeWhenSwitchIsTrue()
{
using (testLogger.BeginScope<IReadOnlyCollection<KeyValuePair<string, object>>>(new Dictionary<string, object> { { "Key", "Value" } }))
{
testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
using (testLogger.BeginScope("TestScope {Key1} and {Key2}", "Value1", "Value2"))
{
testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
}
}
}

Assert.AreEqual(" => TestScope", (itemsReceived[0] as ISupportProperties).Properties["Scope"]);
Assert.AreEqual("Value", (itemsReceived[0] as ISupportProperties).Properties["Key"]);
Assert.AreEqual("Value1", (itemsReceived[0] as ISupportProperties).Properties["Key1"]);
Assert.AreEqual("Value2", (itemsReceived[0] as ISupportProperties).Properties["Key2"]);
Assert.IsTrue((itemsReceived[0] as ISupportProperties).Properties.ContainsKey("OriginalFormat"));
Assert.IsFalse((itemsReceived[0] as ISupportProperties).Properties.ContainsKey("{OriginalFormat}"));

Assert.AreEqual(" => TestScope", (itemsReceived[1] as ISupportProperties).Properties["Scope"]);
Assert.AreEqual("Value", (itemsReceived[1] as ISupportProperties).Properties["Key"]);
Assert.AreEqual("Value1", (itemsReceived[1] as ISupportProperties).Properties["Key1"]);
Assert.AreEqual("Value2", (itemsReceived[1] as ISupportProperties).Properties["Key2"]);
Assert.IsTrue((itemsReceived[1] as ISupportProperties).Properties.ContainsKey("OriginalFormat"));
Assert.IsFalse((itemsReceived[1] as ISupportProperties).Properties.ContainsKey("{OriginalFormat}"));

Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("ExceptionMessage", (itemsReceived[1] as ExceptionTelemetry).Message);
Expand Down

0 comments on commit 2f152ae

Please sign in to comment.