forked from nickdodd79/AutoBogus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add WithDateTimeKind to builder
fixes nickdodd79#83
- Loading branch information
Showing
8 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using FluentAssertions; | ||
using System; | ||
using Xunit; | ||
|
||
namespace AutoBogus.Playground | ||
{ | ||
public class DateTimeKindFixture | ||
{ | ||
private sealed class Obj | ||
{ | ||
public DateTime Birthday { get; set; } | ||
} | ||
|
||
[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() | ||
{ | ||
var obj = AutoFaker.Generate<Obj>(); | ||
|
||
obj.Birthday.Should().Be(obj.Birthday.ToLocalTime()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
namespace AutoBogus.Generators | ||
{ | ||
using System; | ||
|
||
internal sealed class DateTimeGenerator | ||
: IAutoGenerator | ||
{ | ||
object IAutoGenerator.Generate(AutoGenerateContext context) | ||
{ | ||
return context.Faker.Date.Recent(); | ||
return context.Config.DateTimeKind.Invoke(context) == DateTimeKind.Utc | ||
? context.Faker.Date.Recent().ToUniversalTime() | ||
: context.Faker.Date.Recent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters