Skip to content

Latest commit

 

History

History
60 lines (52 loc) · 1.76 KB

numeric-ids.md

File metadata and controls

60 lines (52 loc) · 1.76 KB

Numeric Ids

Numbers are not scrubbed. Sometimes it is helpful to scrub numeric Ids. This can be done using ScrubMembers and checking the DeclaringType and the name of the member.

public class NumericIdSample
{
    public class Target : IHasId
    {
        public required int Id { get; init; }
        public required string Name { get; init; }
    }

    [ModuleInitializer]
    public static void Init() =>
        VerifierSettings.ScrubMembers(
            _ => typeof(IHasId).IsAssignableFrom(_.DeclaringType) &&
                 _.Name == "Id");

    [Fact]
    public Task Test()
    {
        var target = new Target
        {
            Id = new Random().Next(),
            Name = "The Name"
        };
        return Verify(target);
    }

    public interface IHasId
    {
        public int Id { get; init; }
    }
}

snippet source | anchor

Produces

{
  Id: {Scrubbed},
  Name: The Name
}

snippet source | anchor