2021-05-05 15:29:07 +03:00
# <img src="/src/icon.png" height="30px"> Verify.NodaTime
[![Build status ](https://ci.appveyor.com/api/projects/status/ej794va900x9257f?svg=true )](https://ci.appveyor.com/project/SimonCropp/Verify-NodaTime)
[![NuGet Status ](https://img.shields.io/nuget/v/Verify.NodaTime.svg )](https://www.nuget.org/packages/Verify.NodaTime/)
Adds [Verify ](https://github.com/VerifyTests/Verify ) support for scrubbing [NodaTime ](https://nodatime.org/ ) values.
## NuGet package
https://nuget.org/packages/Verify.NodaTime/
## Usage
2022-08-29 07:13:08 +03:00
<!-- snippet: enable -->
< a id = 'snippet-enable' > < / a >
```cs
[ModuleInitializer]
2023-01-09 04:43:56 +03:00
public static void Init() =>
2022-08-29 07:13:08 +03:00
VerifyNodaTime.Enable();
2021-05-05 15:29:07 +03:00
```
2023-01-09 04:43:56 +03:00
< sup > < a href = '/src/Tests/ModuleInitializer.cs#L3-L9' title = 'Snippet source file' > snippet source< / a > | < a href = '#snippet-enable' title = 'Start of snippet' > anchor< / a > < / sup >
2022-08-29 07:13:08 +03:00
<!-- endSnippet -->
2021-05-05 15:29:07 +03:00
Then all Noda date/times will be scrubbed:
<!-- snippet: Example -->
< a id = 'snippet-example' > < / a >
```cs
[Fact]
public Task ScrubbingExample()
{
var target = new Person
{
Dob = LocalDateTime.FromDateTime(DateTime.Now)
};
2021-12-22 13:57:24 +03:00
return Verify(target);
2021-05-05 15:29:07 +03:00
}
```
2022-05-17 15:43:49 +03:00
< sup > < a href = '/src/Tests/Tests.cs#L26-L39' title = 'Snippet source file' > snippet source< / a > | < a href = '#snippet-example' title = 'Start of snippet' > anchor< / a > < / sup >
2021-05-05 15:29:07 +03:00
<!-- endSnippet -->
Resulting in:
<!-- snippet: Tests.ScrubbingExample.verified.txt -->
< a id = 'snippet-Tests.ScrubbingExample.verified.txt' > < / a >
```txt
{
Dob: LocalDateTime_1
}
```
< sup > < a href = '/src/Tests/Tests.ScrubbingExample.verified.txt#L1-L3' title = 'Snippet source file' > snippet source< / a > | < a href = '#snippet-Tests.ScrubbingExample.verified.txt' title = 'Start of snippet' > anchor< / a > < / sup >
<!-- endSnippet -->
To disable scrubbing use `DontScrubNodaTimes` :
<!-- snippet: Disable -->
< a id = 'snippet-disable' > < / a >
```cs
[Fact]
public Task DisableExample()
{
var target = new Person
{
2021-08-14 17:06:46 +03:00
Dob = LocalDateTime.FromDateTime(new(2010, 2, 10))
2021-05-05 15:29:07 +03:00
};
2021-12-22 13:57:24 +03:00
return Verify(target)
2021-05-05 15:29:07 +03:00
.DontScrubNodaTimes();
}
```
2022-05-17 15:43:49 +03:00
< sup > < a href = '/src/Tests/Tests.cs#L41-L55' title = 'Snippet source file' > snippet source< / a > | < a href = '#snippet-disable' title = 'Start of snippet' > anchor< / a > < / sup >
2021-05-05 15:29:07 +03:00
<!-- endSnippet -->
Resulting in:
<!-- snippet: Tests.DisableExample.verified.txt -->
< a id = 'snippet-Tests.DisableExample.verified.txt' > < / a >
```txt
{
2022-06-02 11:30:27 +03:00
Dob: DateTimeOffset_1
2021-05-05 15:29:07 +03:00
}
```
< sup > < a href = '/src/Tests/Tests.DisableExample.verified.txt#L1-L3' title = 'Snippet source file' > snippet source< / a > | < a href = '#snippet-Tests.DisableExample.verified.txt' title = 'Start of snippet' > anchor< / a > < / sup >
<!-- endSnippet -->
## Icon
[Clock ](https://thenounproject.com/term/clock/731041/ ) designed by [Mooyai Khomsun Chaiwong ](https://thenounproject.com/mooyai/ ) from [The Noun Project ](https://thenounproject.com/ ).