< Summary

Information
Class: Elsa.Testing.Shared.XunitConsoleTextWriter
Assembly: Elsa.Testing.Shared
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Testing.Shared/XunitConsoleTextWriter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 42
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
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%
get_Encoding()100%210%
Write(...)0%620%
Dispose(...)0%620%
FlushLine()0%2040%

File(s)

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

#LineLine coverage
 1using System.Text;
 2using Xunit.Abstractions;
 3
 4namespace Elsa.Testing.Shared;
 5
 6/// <summary>
 7/// Forwards text to <see cref="ITestOutputHelper"/>.
 8/// </summary>
 9public class XunitConsoleTextWriter : TextWriter
 10{
 11    private readonly ITestOutputHelper _output;
 012    private IList<char> _line = new List<char>();
 013    public XunitConsoleTextWriter(ITestOutputHelper output) => _output = output;
 014    public override Encoding Encoding => Console.Out.Encoding;
 15
 16    public override void Write(char value)
 17    {
 018        if (value == '\n')
 19        {
 020            FlushLine();
 021            _line = new List<char>();
 022            return;
 23        }
 24
 025        _line.Add(value);
 026    }
 27
 28    protected override void Dispose(bool disposing)
 29    {
 030        if (_line.Count > 0)
 031            FlushLine();
 032        base.Dispose(disposing);
 033    }
 34
 35    private void FlushLine()
 36    {
 037        if (_line.Count > 0 && _line.Last() == '\r')
 038            _line.RemoveAt(_line.Count - 1);
 39
 040        _output.WriteLine(new string(_line.ToArray()));
 041    }
 42}