Skip to content

Commit

Permalink
Update tests to use new line constant
Browse files Browse the repository at this point in the history
  • Loading branch information
normj committed Jun 26, 2019
1 parent 2c79776 commit 5bbbe15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion test/AWS.Logger.AspNetCore.Tests/TestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
/// <summary>
/// Basic test case that creates multiple threads and each thread mocks log messages
Expand Down
32 changes: 16 additions & 16 deletions test/AWS.Logger.AspNetCore.Tests/TestFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
{
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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);

}
}
Expand Down
2 changes: 1 addition & 1 deletion test/AWS.Logger.AspNetCore.Tests/TestFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Func<LogLevel, object, Exception, string> 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));
}
}
}
11 changes: 6 additions & 5 deletions test/AWS.Logger.AspNetCore.Tests/TestScope.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using Xunit;

Expand All @@ -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]
Expand All @@ -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 (\"=>\").");
}
Expand All @@ -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.");
Expand All @@ -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.");
Expand Down

0 comments on commit 5bbbe15

Please sign in to comment.