< Summary

Information
Class: TestUtilities.StringAssertions.StringEqualsWithNormalizedLineEndingsAssertion
Assembly: TestUtilities
File(s): /home/runner/work/KicktippAi/KicktippAi/src/TestUtilities/StringAssertions/StringEqualsWithNormalizedLineEndingsAssertion.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 50
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CheckAsync(...)100%11100%
GetExpectation()100%11100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/TestUtilities/StringAssertions/StringEqualsWithNormalizedLineEndingsAssertion.cs

#LineLine coverage
 1using TUnit.Assertions.Core;
 2
 3namespace TestUtilities.StringAssertions;
 4
 5/// <summary>
 6/// A custom TUnit assertion that compares strings with normalized line endings.
 7/// This is specifically introduced to ease assertions against CSV generated by CsvHelper,
 8/// which writes CRLF line endings by default following RFC 4180.
 9/// </summary>
 10public class StringEqualsWithNormalizedLineEndingsAssertion : Assertion<string>
 11{
 12    private readonly string _expected;
 13
 14    public StringEqualsWithNormalizedLineEndingsAssertion(AssertionContext<string> context, string expected)
 115        : base(context)
 16    {
 117        _expected = expected;
 118    }
 19
 20    protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<string> metadata)
 21    {
 122        var actual = metadata.Value;
 23
 124        if (actual is null)
 25        {
 126            return Task.FromResult(AssertionResult.Failed("Actual string was null"));
 27        }
 28
 129        var normalizedActual = actual.ReplaceLineEndings();
 130        var normalizedExpected = _expected.ReplaceLineEndings();
 31
 132        if (normalizedActual == normalizedExpected)
 33        {
 134            return Task.FromResult(AssertionResult.Passed);
 35        }
 36
 137        return Task.FromResult(AssertionResult.Failed(
 138            $"""
 139             Strings do not match (ignoring line endings).
 140             Expected:
 141             {_expected}
 142
 143             Actual:
 144             {actual}
 145             """));
 46    }
 47
 48    protected override string GetExpectation()
 149        => $"to be equal to \"{_expected}\" (ignoring line endings)";
 50}