Skip to content

Commit

Permalink
Add generator for DateOnly
Browse files Browse the repository at this point in the history
generator is limited to .net6 and above as it was introduced as part of .net6
  • Loading branch information
TomMalow authored and rickykaare committed Jan 2, 2025
1 parent eab80e7 commit 3d39793
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Atc.Test/Customizations/Generators/DateOnlyGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if NET6_0_OR_GREATER
namespace Atc.Test.Customizations.Generators;

/// <summary>
/// Responsible for generating <see cref="DateOnly"/> instances
/// that has not been canceled.
/// </summary>
[AutoRegister]
public class DateOnlyGenerator : ISpecimenBuilder
{
/// <inheritdoc/>
public object Create(object request, ISpecimenContext context)
{
if (!request.IsRequestFor<DateOnly>())
{
return new NoSpecimen();
}

return DateOnly.FromDateTime(context.Create<DateTime>());
}
}
#endif

0 comments on commit 3d39793

Please sign in to comment.