Skip to content

VerifyTests/Verify.Yaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify.Yaml

Discussions Build status NuGet Status

Adds Verify support for converting YamlDotNet types.

See Milestones for release notes.

Sponsors

Entity Framework Extensions

Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.

Entity Framework Extensions

NuGet

Usage

[ModuleInitializer]
public static void Init() =>
    VerifyYaml.Initialize();

snippet source | anchor

YamlDocument

[Test]
public Task YamlDocumentSample()
{
    var yaml =
        """
        node:
          original: http://www.foo.com/
          short: foo
          error:
            code: 0
            msg: No action taken
        """;

    var input = new StringReader(yaml);
    var yamlStream = new YamlStream();
    yamlStream.Load(input);
    return Verify(yamlStream);
}

snippet source | anchor

Results in:

[
  {
    node: {
      error: {
        msg: No action taken,
        code: 0
      },
      short: foo,
      original: http://www.foo.com/
    }
  }
]

snippet source | anchor

Ignoring and Scrubbing

Values in the json can be ignored or scrubbed:

[Test]
public Task ScrubIgnoreMemberSample()
{
    var yaml =
        """
        node:
          original: http://www.foo.com/
          short: foo
          error:
            code: 0
            msg: No action taken
        """;

    var input = new StringReader(yaml);
    var yamlStream = new YamlStream();
    yamlStream.Load(input);
    return Verify(yamlStream)
        .ScrubMember("short")
        .IgnoreMember("msg");
}

snippet source | anchor

Results in:

[
  {
    node: {
      error: {
        code: 0
      },
      short: Scrubbed,
      original: http://www.foo.com/
    }
  }
]

snippet source | anchor

Dates and Guid scrubbing

Json values that map to known date and time formats are scrubbed. See Guids scrubbing and Date scrubbing

[Test]
public Task GuidsAndDatesSample()
{
    var yaml =
        """
        node:
          date: 1/10/2023
          short: foo
          error:
            guid: 123e4567-e89b-12d3-a456-426614174000
            msg: No action taken
        """;

    var input = new StringReader(yaml);
    var yamlStream = new YamlStream();
    yamlStream.Load(input);
    return Verify(yamlStream);
}

snippet source | anchor

Results in:

[
  {
    node: {
      error: {
        msg: No action taken,
        guid: Guid_1
      },
      short: foo,
      date: Date_1
    }
  }
]

snippet source | anchor

Inline dates and Guids

Inline dates and Guids can be scrubbed:

[Test]
public Task InlineGuidsAndDatesSample()
{
    var yaml =
        """
        node:
          date: 2023/10/01
          short: foo 2023/10/01
          error:
            guid: 123e4567-e89b-12d3-a456-426614174000
            msg: No action taken 123e4567-e89b-12d3-a456-426614174000
        """;

    var input = new StringReader(yaml);
    var yamlStream = new YamlStream();
    yamlStream.Load(input);
    return Verify(yamlStream)
        .ScrubInlineDates("yyyy/MM/dd")
        .ScrubInlineGuids();
}

snippet source | anchor

Results in:

[
  {
    node: {
      error: {
        msg: No action taken Guid_1,
        guid: Guid_1
      },
      short: foo Date_1,
      date: Date_1
    }
  }
]

snippet source | anchor

Inline date and Guids scrubbing can also be defined globally:

Icon

Pattern designed by Grafix Point from The Noun Project.

About

Adds Verify support for converting YamlDotNet types.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 3

  •  
  •  
  •  

Languages