Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Jan 6, 2025
1 parent 55280f0 commit 067f7a6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Core.UnitTests/Logging/LoggerBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ public void LogVerbose_AllContextsEnabled_AddsInCorrectOrder()
writer.Received().WriteLine($"[DEBUG] [ThreadId {Thread.CurrentThread.ManagedThreadId}] [context] [verbose context] msg sent");
}

[TestMethod]
public void LogVerboseWithContext_AllContextsEnabled_AddsInCorrectOrder()
{
var messageLevelContext = new MessageLevelContext
{
Context = Substitute.For<IReadOnlyCollection<string>>(),
VerboseContext = Substitute.For<IReadOnlyCollection<string>>()
};
settingsProvider.IsThreadIdEnabled.Returns(true);
settingsProvider.IsVerboseEnabled.Returns(true);
contextManager.GetFormattedContextOrNull(default).Returns("context");
contextManager.GetFormattedVerboseContextOrNull(default).Returns("verbose context");
contextManager.GetFormattedContextOrNull(messageLevelContext).Returns("context with message level");
contextManager.GetFormattedVerboseContextOrNull(messageLevelContext).Returns("verbose context with message level");

testSubject.LogVerbose(messageLevelContext, "msg {0}", "sent");

writer.Received().WriteLine($"[DEBUG] [ThreadId {Thread.CurrentThread.ManagedThreadId}] [context with message level] [verbose context with message level] msg sent");
}

[TestMethod]
public void WriteLine_VerboseDisabled_Writes()
{
Expand Down Expand Up @@ -316,4 +336,24 @@ public void WriteLineFormatted_AllContextsEnabled_AddsInCorrectOrder()

writer.Received().WriteLine($"[ThreadId {Thread.CurrentThread.ManagedThreadId}] [context] [verbose context] msg sent");
}

[TestMethod]
public void WriteLineFormattedWithContext_AllContextsEnabled_AddsInCorrectOrder()
{
var messageLevelContext = new MessageLevelContext
{
Context = Substitute.For<IReadOnlyCollection<string>>(),
VerboseContext = Substitute.For<IReadOnlyCollection<string>>()
};
settingsProvider.IsThreadIdEnabled.Returns(true);
settingsProvider.IsVerboseEnabled.Returns(true);
contextManager.GetFormattedContextOrNull(default).Returns("context");
contextManager.GetFormattedVerboseContextOrNull(default).Returns("verbose context");
contextManager.GetFormattedContextOrNull(messageLevelContext).Returns("context with message level");
contextManager.GetFormattedVerboseContextOrNull(messageLevelContext).Returns("verbose context with message level");

testSubject.WriteLine(messageLevelContext, "msg {0}", "sent");

writer.Received().WriteLine($"[ThreadId {Thread.CurrentThread.ManagedThreadId}] [context with message level] [verbose context with message level] msg sent");
}
}

0 comments on commit 067f7a6

Please sign in to comment.