<!--
GENERATED FILE - DO NOT EDIT
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
Source File: /docs/mdsource/guids.source.md
To change this file edit the source file and then run MarkdownSnippets.
-->

# Guids

By default guids are sanitized during verification. This is done by finding each guid and taking a counter based that that specific guid. That counter is then used replace the guid values. This allows for repeatable tests when guid values are changing.

<!-- snippet: guid -->
<a id='snippet-guid'></a>
```cs
var guid = Guid.NewGuid();
var target = new GuidTarget
{
    Guid = guid,
    GuidNullable = guid,
    GuidString = guid.ToString(),
    OtherGuid = Guid.NewGuid()
};

await Verify(target);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2065-L2078' title='Snippet source file'>snippet source</a> | <a href='#snippet-guid' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Results in the following:

<!-- snippet: SerializationTests.ReUseGuid.verified.txt -->
<a id='snippet-SerializationTests.ReUseGuid.verified.txt'></a>
```txt
{
  Guid: Guid_1,
  GuidNullable: Guid_1,
  GuidString: Guid_1,
  OtherGuid: Guid_2
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.ReUseGuid.verified.txt#L1-L6' title='Snippet source file'>snippet source</a> | <a href='#snippet-SerializationTests.ReUseGuid.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Disable

To disable this behavior use:


### Instance

<!-- snippet: DontScrubGuids -->
<a id='snippet-DontScrubGuids'></a>
```cs
var settings = new VerifySettings();
settings.DontScrubGuids();
await Verify(target, settings);
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L679-L685' title='Snippet source file'>snippet source</a> | <a href='#snippet-DontScrubGuids' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Fluent

<!-- snippet: DontScrubGuidsFluent -->
<a id='snippet-DontScrubGuidsFluent'></a>
```cs
await Verify(target)
    .DontScrubGuids();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L693-L698' title='Snippet source file'>snippet source</a> | <a href='#snippet-DontScrubGuidsFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Globally

<!-- snippet: DontScrubGuidsGlobal -->
<a id='snippet-DontScrubGuidsGlobal'></a>
```cs
VerifierSettings.DontScrubGuids();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1594-L1598' title='Snippet source file'>snippet source</a> | <a href='#snippet-DontScrubGuidsGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Inline Guids

Strings containing inline Guids can also be scrubbed. To enable this behavior, use:


### Instance

<!-- snippet: ScrubInlineGuidsInstance -->
<a id='snippet-ScrubInlineGuidsInstance'></a>
```cs
[Fact]
public Task ScrubInlineGuidsInstance()
{
    var settings = new VerifySettings();
    settings.ScrubInlineGuids();
    return Verify(
        "content 651ad409-fc30-4b12-a47e-616d3f953e4c content",
        settings);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1650-L1662' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubInlineGuidsInstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Fluent

<!-- snippet: ScrubInlineGuidsFluent -->
<a id='snippet-ScrubInlineGuidsFluent'></a>
```cs
[Fact]
public Task ScrubInlineGuidsFluent() =>
    Verify("content 651ad409-fc30-4b12-a47e-616d3f953e4c content")
        .ScrubInlineGuids();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1641-L1648' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubInlineGuidsFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Globally

<!-- snippet: ScrubInlineGuidsGlobal -->
<a id='snippet-ScrubInlineGuidsGlobal'></a>
```cs
public static class ModuleInitializer
{
    [ModuleInitializer]
    public static void Init() =>
        VerifierSettings.ScrubInlineGuids();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1629-L1638' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubInlineGuidsGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Named Guid

Specific Guids can be named. When any of those Guids are found, it will be replaced with the supplied name.


### Instance

<!-- snippet: NamedGuidInstance -->
<a id='snippet-NamedGuidInstance'></a>
```cs
[Fact]
public Task NamedGuidInstance()
{
    var settings = new VerifySettings();
    var guid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
    settings.AddNamedGuid(guid, "instanceNamed");
    return Verify(
        new
        {
            value = guid
        },
        settings);
}
```
<sup><a href='/src/Verify.Tests/GuidScrubberTests.cs#L63-L79' title='Snippet source file'>snippet source</a> | <a href='#snippet-NamedGuidInstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Instance

<!-- snippet: NamedGuidFluent -->
<a id='snippet-NamedGuidFluent'></a>
```cs
[Fact]
public Task NamedGuidFluent()
{
    var guid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
    return Verify(
            new
            {
                value = guid
            })
        .AddNamedGuid(guid, "instanceNamed");
}
```
<sup><a href='/src/Verify.Tests/GuidScrubberTests.cs#L91-L105' title='Snippet source file'>snippet source</a> | <a href='#snippet-NamedGuidFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Globally

<!-- snippet: NamedGuidGlobal -->
<a id='snippet-NamedGuidGlobal'></a>
```cs
[ModuleInitializer]
public static void Init() => VerifierSettings.AddNamedGuid(new("c8eeaf99-d5c4-4341-8543-4597c3fd40c9"), "guidName");
```
<sup><a href='/src/Verify.Tests/GuidScrubberTests.cs#L3-L8' title='Snippet source file'>snippet source</a> | <a href='#snippet-NamedGuidGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Inferred Name

The name can be inferred from the variable name by omitting the name argument:

<!-- snippet: InferredNamedGuidFluent -->
<a id='snippet-InferredNamedGuidFluent'></a>
```cs
[Fact]
public Task InferredNamedGuidFluent()
{
    var namedGuid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
    return Verify(
            new
            {
                value = namedGuid
            })
        .AddNamedGuid(namedGuid);
}
```
<sup><a href='/src/Verify.Tests/GuidScrubberTests.cs#L107-L121' title='Snippet source file'>snippet source</a> | <a href='#snippet-InferredNamedGuidFluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result: 

<!-- snippet: GuidScrubberTests.InferredNamedGuidFluent.verified.txt -->
<a id='snippet-GuidScrubberTests.InferredNamedGuidFluent.verified.txt'></a>
```txt
{
  value: namedGuid
}
```
<sup><a href='/src/Verify.Tests/GuidScrubberTests.InferredNamedGuidFluent.verified.txt#L1-L3' title='Snippet source file'>snippet source</a> | <a href='#snippet-GuidScrubberTests.InferredNamedGuidFluent.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->