Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 2.18 KB

File metadata and controls

65 lines (51 loc) · 2.18 KB

Counter

The Counter class provides methods to attempt conversion of a CharSpan value into a string representation of supported types.

Supported types include

such as Guid, DateTimeOffset, DateTime, and, DateOnly and TimeOnly.

It handles matching equivalent values and assigning a number to each match. It is used by Scrubbers.

TryConvert

Takes a CharSpan and attempts to parse it to one of the supported types, then return the tokenized scrubbed value for that value.

One example usage is inside a custom scrubber:

[Fact]
public Task CounterTryConvert()
{
    var settings = new VerifySettings();
    settings.AddScrubber((builder, counter) =>
    {
        var values = builder.ToString().Split();
        builder.Clear();
        foreach (var value in values)
        {
            if (counter.TryConvert(value, out var result))
            {
                builder.Append(result);
            }
            else
            {
                builder.Append(value);
            }

            builder.Append(' ');
        }
    });

    return Verify("The user with id c9cb98bf-3def-415e-a009-7d58055f5ffc was created on 2022-10-12", settings);
}

snippet source | anchor

Results in:

The user with id Guid_1 was created on DateTime_1

snippet source | anchor