< Summary

Information
Class: Elsa.Testing.Shared.XunitLogger
Assembly: Elsa.Testing.Shared
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Testing.Shared/XunitLogger.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 37
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
BeginScope(...)100%210%
IsEnabled(...)100%210%
Log(...)0%620%
.cctor()100%210%
Dispose()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Testing.Shared/XunitLogger.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2using Xunit.Abstractions;
 3
 4namespace Elsa.Testing.Shared;
 5
 06public class XunitLogger(ITestOutputHelper testOutputHelper, string categoryName) : ILogger
 7{
 08    public IDisposable BeginScope<TState>(TState state) where TState : notnull => NoopDisposable.Instance;
 9
 10    public bool IsEnabled(LogLevel logLevel)
 011        => true;
 12
 13    public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Excepti
 14    {
 15        try
 16        {
 017            testOutputHelper.WriteLine($"{categoryName} [{eventId}] {formatter(state, exception)}");
 18
 019            if (exception != null)
 020                testOutputHelper.WriteLine(exception.ToString());
 021        }
 022        catch (InvalidOperationException)
 23        {
 24            // Suppress "no currently active test" exceptions that can occur when background tasks
 25            // (like timers) try to log after tests have completed
 026        }
 027    }
 28
 29    private class NoopDisposable : IDisposable
 30    {
 031        public static readonly NoopDisposable Instance = new();
 32
 33        public void Dispose()
 34        {
 035        }
 36    }
 37}