Skip to content

Scrub numeric ids#351

Merged
SimonCropp merged 4 commits into
masterfrom
ScrubNumericIds
May 8, 2021
Merged

Scrub numeric ids#351
SimonCropp merged 4 commits into
masterfrom
ScrubNumericIds

Conversation

@SimonCropp

@SimonCropp SimonCropp commented May 7, 2021

Copy link
Copy Markdown
Member

By default numeric properties (int, uint, long, and ulong) suffixed with Id are sanitized during verification. This is done by finding each id and taking a counter based that that specific id. That counter is then used replace the id values. This allows for repeatable tests when id are bing generated.

[Fact]
public Task NumericIdScrubbing()
{
    var target = new
    {
        Id = 5,
        OtherId = 5,
        YetAnotherId = 4
    };

    return Verifier.Verify(target);
}

snippet source | anchor

Results in the following:

{
  Id: Id_1,
  OtherId: Id_1,
  YetAnotherId: Id_2
}

snippet source | anchor

To disable this globally use:

[Fact]
public Task NumericIdScrubbingDisabled()
{
    var target = new
    {
        Id = 5,
        OtherId = 5,
        YetAnotherId = 4
    };
    return Verifier.Verify(target)
        .ModifySerialization(settings => settings.DontScrubNumericIds());
}

snippet source | anchor

[Fact]
public Task NumericIdScrubbingDisabledGlobal()
{
    VerifierSettings.ModifySerialization(settings => settings.DontScrubNumericIds());
    return Verifier.Verify(
            new
            {
                Id = 5,
                OtherId = 5,
                YetAnotherId = 4
            });
}

snippet source | anchor

To disable this behavior globally use:

[Fact]
public Task NumericIdScrubbingDisabled()
{
    var target = new
    {
        Id = 5,
        OtherId = 5,
        YetAnotherId = 4
    };
    return Verifier.Verify(target)
        .ModifySerialization(settings => settings.DontScrubNumericIds());
}

snippet source | anchor

[Fact]
public Task NumericIdScrubbingDisabledGlobal()
{
    VerifierSettings.ModifySerialization(settings => settings.DontScrubNumericIds());
    return Verifier.Verify(
            new
            {
                Id = 5,
                OtherId = 5,
                YetAnotherId = 4
            });
}

snippet source | anchor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant