Skip to content

Commit 3d39793

Browse files
TomMalowrickykaare
authored andcommitted
Add generator for DateOnly
generator is limited to .net6 and above as it was introduced as part of .net6
1 parent eab80e7 commit 3d39793

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#if NET6_0_OR_GREATER
2+
namespace Atc.Test.Customizations.Generators;
3+
4+
/// <summary>
5+
/// Responsible for generating <see cref="DateOnly"/> instances
6+
/// that has not been canceled.
7+
/// </summary>
8+
[AutoRegister]
9+
public class DateOnlyGenerator : ISpecimenBuilder
10+
{
11+
/// <inheritdoc/>
12+
public object Create(object request, ISpecimenContext context)
13+
{
14+
if (!request.IsRequestFor<DateOnly>())
15+
{
16+
return new NoSpecimen();
17+
}
18+
19+
return DateOnly.FromDateTime(context.Create<DateTime>());
20+
}
21+
}
22+
#endif

0 commit comments

Comments
 (0)