2021-05-05 15:29:07 +03:00
# <img src="/src/icon.png" height="30px"> Verify.NodaTime
2023-02-10 01:27:32 +03:00
[![Discussions ](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true&label= )](https://github.com/orgs/VerifyTests/discussions)
2021-05-05 15:29:07 +03:00
[![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.
2023-09-21 15:09:51 +03:00
**See [Milestones ](../../milestones?state=closed ) for release notes.**
2021-05-05 15:29:07 +03:00
## 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() =>
2023-02-07 13:22:14 +03:00
VerifyNodaTime.Initialize();
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
}
```
2024-01-17 13:15:42 +03:00
< sup > < a href = '/src/Tests/Tests.cs#L25-L38' 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();
}
```
2024-01-17 13:15:42 +03:00
< sup > < a href = '/src/Tests/Tests.cs#L40-L54' 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/ ).