Skip to content

Commit

Permalink
Update code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrietataru committed Mar 4, 2024
1 parent 2080d52 commit 32c0551
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Ace.CSharp.DataFaker.Tests/Fakers/FakeDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ace.CSharp.DataFaker.Tests.Fakers;

public class FakeDto
public sealed class FakeDto
{
private const string LocaleCode = "en_US";

Expand Down
38 changes: 38 additions & 0 deletions src/sample/Ace.CSharp.DataFaker.Sample/FakeDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
namespace Ace.CSharp.DataFaker.Sample;

internal sealed class DtoFaker : AbstractDataFaker<DtoFaker>
{
protected sealed override string LocaleCode => base.LocaleCode;
protected sealed override int DefaultCount => base.DefaultCount;
protected sealed override DateTime RefDate => base.RefDate;

private Faker<FooDto> FakeFooDto =>
new Faker<FooDto>(locale: LocaleCode)
.RuleFor(
dto => dto.Id,
func => func.Random.Uuid())
.RuleFor(
dto => dto.Title,
func => func.Lorem.Sentence())
.RuleFor(
dto => dto.Description,
func => func.Lorem.Sentences())
.RuleFor(
dto => dto.AvatarUrl,
func => new Uri(func.Internet.Avatar()))
.RuleFor(
dto => dto.Index,
func => func.Random.Int(min: 1, max: int.MaxValue))
.RuleFor(
dto => dto.Size,
func => func.Random.Decimal(min: 1.0M, max: 10.0M))
.RuleFor(
dto => dto.CreatedAt,
func => func.Date.PastOffset(yearsToGoBack: 1, RefDate))
.RuleFor(
dto => dto.ExpiresAt,
func => func.Date.FutureOffset(yearsToGoForward: 1, RefDate))
.RuleFor(
dto => dto.IsActive,
func => func.Random.Bool())
.StrictMode(ensureRulesForAllProperties: true);
}

internal sealed class FakeDto
{
private const string LocaleCode = "en_US";
Expand Down
2 changes: 1 addition & 1 deletion src/sample/Ace.CSharp.DataFaker.Sample/FakeEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static List<T> ManyOf<T>(int minCount, int maxCount)
return Fake.ManyOf<T, FakeEntity>(minCount, maxCount);
}

private static Faker<FooEntity> FakeFoo =>
private static Faker<FooEntity> FakeFooEntity =>
new Faker<FooEntity>(locale: LocaleCode)
.RuleFor(
dto => dto.Id,
Expand Down
13 changes: 13 additions & 0 deletions src/sample/Ace.CSharp.DataFaker.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@
Console.WriteLine();
}

{
Console.WriteLine("Generating FooDto(s) using the Instance class..");

var faker = new DtoFaker();

var fooDto = faker.Of<FooDto>();
var fooDtos = faker.ManyOf<FooDto>();

Console.WriteLine($"Foo Id: {fooDto.Id}");
Console.WriteLine($"Foos count: {fooDtos.Count}");
Console.WriteLine();
}

Console.ReadKey();

0 comments on commit 32c0551

Please sign in to comment.