Skip to content

Commit

Permalink
Will bring back some of this stuff shortly
Browse files Browse the repository at this point in the history
  • Loading branch information
soenneker committed Feb 5, 2024
1 parent e3e1f3e commit 6f2b41f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
15 changes: 8 additions & 7 deletions src/Config/Base/IBaseAutoFakerConfigBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Soenneker.Utils.AutoBogus.Abstract;
using Soenneker.Utils.AutoBogus.Context;
using Soenneker.Utils.AutoBogus.Generators;

namespace Soenneker.Utils.AutoBogus.Config.Base;
Expand All @@ -22,14 +23,14 @@ public interface IBaseAutoFakerConfigBuilder<TBuilder>
/// </summary>
/// <param name="dateTimeKind">The dateTimeKind to use.</param>
/// <returns>The current configuration builder instance.</returns>
TBuilder WithDateTimeKind(Func<AutoFakerContext, DateTimeKind> dateTimeKind);
//TBuilder WithDateTimeKind(Func<AutoFakerContext, DateTimeKind> dateTimeKind);

/// <summary>
/// Registers the DateTimeKind to use when generating date and time values.
/// </summary>
/// <param name="dateTimeKind">The dateTimeKind to use.</param>
/// <returns>The current configuration builder instance.</returns>
TBuilder WithDateTimeKind(DateTimeKind dateTimeKind);
///// <summary>
///// Registers the DateTimeKind to use when generating date and time values.
///// </summary>
///// <param name="dateTimeKind">The dateTimeKind to use.</param>
///// <returns>The current configuration builder instance.</returns>
//TBuilder WithDateTimeKind(DateTimeKind dateTimeKind);

/// <summary>
/// Registers the number of items to generate for a collection.
Expand Down
8 changes: 5 additions & 3 deletions src/Generators/Types/DateTimeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ internal sealed class DateTimeGenerator
{
object IAutoFakerGenerator.Generate(AutoFakerContext context)
{
return context.AutoFakerConfig.DateTimeKind.Invoke(context) == DateTimeKind.Utc
? context.Faker.Date.Recent().ToUniversalTime()
: context.Faker.Date.Recent();
return context.Faker.Date.Recent();

//return context.Config.DateTimeKind.Invoke(context) == DateTimeKind.Utc
// ? context.Faker.Date.Recent().ToUniversalTime()
// : context.Faker.Date.Recent();
}
}
48 changes: 24 additions & 24 deletions test/Soenneker.Utils.AutoBogus.Tests/AutoConfigBuilderFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ public void Should_Set_Config_Locale()

public class WithDateTimeKind : AutoConfigBuilderFixture
{
[Fact]
public void Should_Set_Config_DateTimeKind()
{
var kind = DateTimeKind.Utc;
_builder.WithDateTimeKind<ITestBuilder>(context => kind, null);
_fakerConfig.DateTimeKind.Invoke(null).Should().Be(kind);
}

[Fact]
public void Should_Set_Config_DateTimeKind_To_Default_If_Null()
{
var kind = AutoFakerConfig.DefaultDateTimeKind.Invoke(null);
_builder.WithDateTimeKind<ITestBuilder>(null, null);
_fakerConfig.DateTimeKind.Invoke(null).Should().Be(kind);
}
//[Fact]
//public void Should_Set_Config_DateTimeKind()
//{
// var kind = DateTimeKind.Utc;
// _builder.WithDateTimeKind<ITestBuilder>(context => kind, null);
// _fakerConfig.DateTimeKind.Invoke(null).Should().Be(kind);
//}

//[Fact]
//public void Should_Set_Config_DateTimeKind_To_Default_If_Null()
//{
// var kind = AutoFakerConfig.DefaultDateTimeKind.Invoke(null);
// _builder.WithDateTimeKind<ITestBuilder>(null, null);
// _fakerConfig.DateTimeKind.Invoke(null).Should().Be(kind);
//}

private sealed record Obj(DateTime Birthday);

[Fact]
public void Should_ConvertToUtc()
{
var obj = AutoFaker.Generate<Obj>(builder =>
{
builder.WithDateTimeKind(DateTimeKind.Utc);
});
obj.Birthday.Should().Be(obj.Birthday.ToUniversalTime());
}
//[Fact]
//public void Should_ConvertToUtc()
//{
// var obj = AutoFaker.Generate<Obj>(builder =>
// {
// builder.WithDateTimeKind(DateTimeKind.Utc);
// });
// obj.Birthday.Should().Be(obj.Birthday.ToUniversalTime());
//}

[Fact]
public void Should_BeLocal()
Expand Down

0 comments on commit 6f2b41f

Please sign in to comment.