Skip to content

Commit

Permalink
Update LogTest.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Nov 28, 2023
1 parent 339e4f9 commit 9cb6a14
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions dotnet/test/common/Internal/Logging/LogTest.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@

using NUnit.Framework;
using System;
using System.Collections.Generic;

namespace OpenQA.Selenium.Internal.Logging
{
// mark it as non-parallelizable because of static nature of Log class
[NonParallelizable]
internal class LogTest
public class LogTest
{
private TestLogHandler testLogHandler;
private ILogger logger;

[SetUp]
public void SetUp()
{
testLogHandler = new TestLogHandler();
logger = Log.GetLogger<LogTest>();
}

[Test]
public void LoggerShouldEmitLogEvent()
public void LoggerShouldEmitEvent()
{
Log.SetMinimumLevel(LogEventLevel.Info).WithHandler(testLogHandler);

var logger = Log.GetLogger<LogTest>();

logger.Info("test message");

Assert.That(testLogHandler.Events, Has.Count.EqualTo(1));
Expand All @@ -34,6 +31,56 @@ public void LoggerShouldEmitLogEvent()
Assert.That(logEvent.IssuedBy, Is.EqualTo(typeof(LogTest)));
Assert.That(logEvent.Timestamp, Is.EqualTo(DateTimeOffset.Now).Within(100).Milliseconds);
}

[Test]
[TestCase(LogEventLevel.Trace)]
[TestCase(LogEventLevel.Debug)]
[TestCase(LogEventLevel.Info)]
[TestCase(LogEventLevel.Warn)]
[TestCase(LogEventLevel.Error)]
public void LoggerShouldEmitEventWithProperLevel(LogEventLevel level)
{
Log.SetMinimumLevel(level).WithHandler(testLogHandler);

switch (level)
{
case LogEventLevel.Trace:
logger.Trace("test message");
break;
case LogEventLevel.Debug:
logger.Debug("test message");
break;
case LogEventLevel.Info:
logger.Info("test message");
break;
case LogEventLevel.Warn:
logger.Warn("test message");
break;
case LogEventLevel.Error:
logger.Error("test message");
break;
}

Assert.That(testLogHandler.Events, Has.Count.EqualTo(1));

Assert.That(testLogHandler.Events[0].Level, Is.EqualTo(level));
}

[Test]
public void LoggerShouldNotEmitEventWhenLevelIsLess()
{
Log.SetMinimumLevel(LogEventLevel.Info).WithHandler(testLogHandler);

logger.Trace("test message");

Assert.That(testLogHandler.Events, Has.Count.EqualTo(0));
}

[Test]
public void A()
{
Log.CurrentContext.
}
}

class TestLogHandler : ILogHandler
Expand Down

0 comments on commit 9cb6a14

Please sign in to comment.