< Summary - CoreWCF Coverage — PR #1766

Information
Class: Helpers.XunitLogger
Assembly: UnitTests.Common
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/Helpers/XunitLogger.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 53
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 Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
BeginScope(...)100%110%
IsEnabled(...)100%110%
Log(...)0%220%
.cctor()100%110%
Dispose()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/Helpers/XunitLogger.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using Microsoft.Extensions.Logging;
 6using Xunit;
 7
 8namespace Helpers
 9{
 10    public class XunitLogger : ILogger
 11    {
 12        private readonly ITestOutputHelper _testOutputHelper;
 13        private readonly string _categoryName;
 14        private readonly string _callerMethodName;
 15
 016        public XunitLogger(ITestOutputHelper testOutputHelper, string categoryName, string callerMethodName)
 17        {
 018            _testOutputHelper = testOutputHelper;
 019            _categoryName = categoryName;
 020            _callerMethodName = callerMethodName;
 021        }
 22
 23        public IDisposable BeginScope<TState>(TState state)
 024            => NoopDisposable.Instance;
 25
 26        public bool IsEnabled(LogLevel logLevel)
 027            => true;
 28
 29        public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exce
 30        {
 31            try
 32            {
 033                _testOutputHelper.WriteLine($"{_categoryName} [{eventId}] {formatter(state, exception)}");
 034                if (exception != null)
 35                {
 036                    _testOutputHelper.WriteLine(exception.ToString());
 37                }
 038            }
 039            catch (InvalidOperationException e) when (e.Message == "There is no currently active test.")
 40            {
 41                // Swallow exception as this is caused by bug in earlier versions of AspNetCore which would
 42                // write to the logger from the heartbeat code after the host was shut down.
 043            }
 044        }
 45
 46        private class NoopDisposable : IDisposable
 47        {
 048            public static NoopDisposable Instance = new NoopDisposable();
 49            public void Dispose()
 050            { }
 51        }
 52    }
 53}