VerifyTests/Verify

Support for Ulid scrubbing

Opened this issue · 5 comments

Is the feature request related to a problem

Ulids are an interesting alternative to using Guids for uniquely identifying objects and data. See https://github.com/ulid/spec/blob/master/README.md

However Verify does currently not support those IDs, and as such will break tests if those IDs are generated on the fly, which is most likely the case in many unit test scenarios.

Describe the solution

Implement an Ulid scrubber that recognizes and translates the Ulid values like it already works now for GUIDs. I am able to work on a PR, however as I am not familiar with the codebase I would need some help before submitting it.

Describe alternatives considered

Also adding of scrubbers can be utilized, something like this, but ofc it would have more comfort to do it in the framework:

using VerifyTests;

namespace CloudAddInTests;
internal class VerifyModuleInitializer {

    private static Dictionary<string, string> scrubbedUlids = new ();

    [ModuleInitializer]
    public static void InitializeUlidScrubbing() {
        VerifierSettings.AddScrubber(UlidScrubber);
        VerifierSettings.OnVerify(scrubbedUlids.Clear, () => { });
    }

    private static void UlidScrubber(StringBuilder verifyInput) {
        string inputAsString = verifyInput.ToString();
        Regex detectUlid = new Regex("[0-7][0-9A-HJKMNP-TV-Z]{25}");
        var ulidsfound = detectUlid.Matches(inputAsString);
        foreach (Match match in ulidsfound) {
            if (!scrubbedUlids.ContainsKey(match.Value)) {
                scrubbedUlids.Add(match.Value, $"Ulid_{scrubbedUlids.Count + 1}");
            }
            verifyInput.Replace(match.Value, scrubbedUlids[match.Value]);
        }
    }

what nuget r u using for generating Ulids ?

I tried NUlid but it fails for Verify since it has no strong naming it seems. I guess thats a no go then?

Added a potential alternative solution in the original post. We will work with this for the time being to not being blocked ;)

@Flohack74 why not ship that alternative solution as a nuget?

@SimonCropp hooking into the scrubbers like above means that we need to add a class to each test assembly and specify a module initializer. Do you mean instead to reference a nuget that contains the module initializer only?