diff --git a/test/AWS.Logger.AspNetCore.Tests/TestClass.cs b/test/AWS.Logger.AspNetCore.Tests/TestClass.cs index 96c1c5b..9f3871e 100644 --- a/test/AWS.Logger.AspNetCore.Tests/TestClass.cs +++ b/test/AWS.Logger.AspNetCore.Tests/TestClass.cs @@ -96,7 +96,7 @@ public void ExceptionMockTest() coreLogger, null); var logMessageCount = 10; LogMessages(logMessageCount); - Assert.Contains("[Error] testlogging: Error message System.Exception: Exception message.\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Error] testlogging: Error message System.Exception: Exception message.{Environment.NewLine}", coreLogger.ReceivedMessages); } /// /// Basic test case that creates multiple threads and each thread mocks log messages diff --git a/test/AWS.Logger.AspNetCore.Tests/TestFilter.cs b/test/AWS.Logger.AspNetCore.Tests/TestFilter.cs index b8667c0..8890b2e 100644 --- a/test/AWS.Logger.AspNetCore.Tests/TestFilter.cs +++ b/test/AWS.Logger.AspNetCore.Tests/TestFilter.cs @@ -54,9 +54,9 @@ public void FilterLogLevel() logger.LogCritical("critical"); Assert.Equal(3, coreLogger.ReceivedMessages.Count); - Assert.Contains("[Warning] FilterLogLevel: warning\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Error] FilterLogLevel: error\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Critical] FilterLogLevel: critical\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Warning] FilterLogLevel: warning{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Error] FilterLogLevel: error{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Critical] FilterLogLevel: critical{Environment.NewLine}", coreLogger.ReceivedMessages); } [Fact] @@ -75,7 +75,7 @@ public void CustomFilter() logger.LogWarning("warning"); Assert.Single(coreLogger.ReceivedMessages); - Assert.Contains("[Warning] goodCategory: warning\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Warning] goodCategory: warning{Environment.NewLine}", coreLogger.ReceivedMessages); string val; while (!coreLogger.ReceivedMessages.IsEmpty) { @@ -112,9 +112,9 @@ public void ValidAppsettingsFilter() logger.LogCritical("critical"); Assert.Equal(5, coreLogger.ReceivedMessages.Count); - Assert.Contains("[Warning] AWS.Logger.AspNetCore.Tests.TestFilter: warning\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Error] AWS.Logger.AspNetCore.Tests.TestFilter: error\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Critical] AWS.Logger.AspNetCore.Tests.TestFilter: critical\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Warning] AWS.Logger.AspNetCore.Tests.TestFilter: warning{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Error] AWS.Logger.AspNetCore.Tests.TestFilter: error{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Critical] AWS.Logger.AspNetCore.Tests.TestFilter: critical{Environment.NewLine}", coreLogger.ReceivedMessages); } [Fact] @@ -155,9 +155,9 @@ public void InValidAppsettingsFilter() logger.LogCritical("critical"); Assert.Equal(5, coreLogger.ReceivedMessages.Count); - Assert.Contains("[Warning] AWS.Log: warning\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Error] AWS.Log: error\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Critical] AWS.Log: critical\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Warning] AWS.Log: warning{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Error] AWS.Log: error{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Critical] AWS.Log: critical{Environment.NewLine}", coreLogger.ReceivedMessages); } [Fact] @@ -183,9 +183,9 @@ public void DefaultFilterCheck() logger.LogCritical("critical"); Assert.Equal(5, coreLogger.ReceivedMessages.Count); - Assert.Contains("[Warning] AWS.Log: warning\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Error] AWS.Log: error\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Critical] AWS.Log: critical\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Warning] AWS.Log: warning{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Error] AWS.Log: error{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Critical] AWS.Log: critical{Environment.NewLine}", coreLogger.ReceivedMessages); } [Fact] @@ -211,9 +211,9 @@ public void MissingLogLevelCheck() logger.LogCritical("critical"); Assert.Equal(6, coreLogger.ReceivedMessages.Count); - Assert.Contains("[Warning] AWS.Logger.AspNetCore.Tests.TestFilter: warning\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Error] AWS.Logger.AspNetCore.Tests.TestFilter: error\r\n", coreLogger.ReceivedMessages); - Assert.Contains("[Critical] AWS.Logger.AspNetCore.Tests.TestFilter: critical\r\n", coreLogger.ReceivedMessages); + Assert.Contains($"[Warning] AWS.Logger.AspNetCore.Tests.TestFilter: warning{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Error] AWS.Logger.AspNetCore.Tests.TestFilter: error{Environment.NewLine}", coreLogger.ReceivedMessages); + Assert.Contains($"[Critical] AWS.Logger.AspNetCore.Tests.TestFilter: critical{Environment.NewLine}", coreLogger.ReceivedMessages); } } diff --git a/test/AWS.Logger.AspNetCore.Tests/TestFormatter.cs b/test/AWS.Logger.AspNetCore.Tests/TestFormatter.cs index a3274ce..6115c75 100644 --- a/test/AWS.Logger.AspNetCore.Tests/TestFormatter.cs +++ b/test/AWS.Logger.AspNetCore.Tests/TestFormatter.cs @@ -26,7 +26,7 @@ Func customFormatter string expectedMessage = customFormatter(logLevel, message, null); - Assert.Equal(expectedMessage, coreLogger.ReceivedMessages.First().Replace("\r\n", string.Empty)); + Assert.Equal(expectedMessage, coreLogger.ReceivedMessages.First().Replace(Environment.NewLine, string.Empty)); } } } diff --git a/test/AWS.Logger.AspNetCore.Tests/TestScope.cs b/test/AWS.Logger.AspNetCore.Tests/TestScope.cs index 7004794..bce3d0c 100644 --- a/test/AWS.Logger.AspNetCore.Tests/TestScope.cs +++ b/test/AWS.Logger.AspNetCore.Tests/TestScope.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Microsoft.Extensions.Logging; using Xunit; @@ -24,7 +25,7 @@ public void MakeSureCanCreateScope() } Assert.Single(coreLogger.ReceivedMessages); - Assert.True(coreLogger.ReceivedMessages.Contains("[Information] MakeSureCanCreateScope: log\r\n"), "Messages don't contain actual log message."); + Assert.True(coreLogger.ReceivedMessages.Contains($"[Information] MakeSureCanCreateScope: log{Environment.NewLine}"), "Messages don't contain actual log message."); } [Fact] @@ -40,7 +41,7 @@ public void MakeSureCanLogWithoutScope() logger.LogInformation("log"); Assert.Single(coreLogger.ReceivedMessages); - var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains("[Information] MakeSureCanCreateScope: log\r\n")); + var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains($"[Information] MakeSureCanCreateScope: log{Environment.NewLine}")); Assert.True(msg != null, "Messages don't contain actual log message."); Assert.False(msg.Contains("=>"), "Fragment of scopes exists (\"=>\")."); } @@ -61,7 +62,7 @@ public void MakeSureScopeIsIncluded() } Assert.Single(coreLogger.ReceivedMessages); - var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains("[Information] Test scope => MakeSureCanCreateScope: log\r\n")); + var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains($"[Information] Test scope => MakeSureCanCreateScope: log{Environment.NewLine}")); Assert.True(msg != null, "Messages don't contain actual log message."); // Same message should contain the scope Assert.True(msg.Contains("Test scope => "), "Scope is not included."); @@ -86,7 +87,7 @@ public void MakeSureScopesAreIncluded() } Assert.Single(coreLogger.ReceivedMessages); - var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains("[Information] OuterScope InnerScope => MakeSureCanCreateScope: log\r\n")); + var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains($"[Information] OuterScope InnerScope => MakeSureCanCreateScope: log{Environment.NewLine}")); Assert.True(msg != null, "Messages don't contain actual log message."); // Same message should contain the scope Assert.True(msg.Contains("OuterScope"), "Outer scope is not included.");