Verify.NodaTime/readme.md

96 строки
2.9 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

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 -->
2024-03-26 04:17:04 +03:00
<a id='snippet-Example'></a>
2021-05-05 15:29:07 +03:00
```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-09-15 13:14:27 +03:00
<sup><a href='/src/Tests/Tests.cs#L23-L36' 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 -->
2024-03-26 04:17:04 +03:00
<a id='snippet-Disable'></a>
2021-05-05 15:29:07 +03:00
```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-09-15 13:14:27 +03:00
<sup><a href='/src/Tests/Tests.cs#L38-L52' 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/).