-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" Version="34.0.2" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace John.Bogus; | ||
|
||
public class Order | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public decimal Price { get; set; } | ||
|
||
public string Currency { get; set; } | ||
|
||
public BillingDetails BillingDetails { get; set; } | ||
} | ||
|
||
public class BillingDetails | ||
{ | ||
public string CustomerName { get; set; } | ||
|
||
public string Email { get; set; } | ||
|
||
public string Phone { get; set; } | ||
|
||
public string AddressLine { get; set; } | ||
|
||
public string City { get; set; } | ||
|
||
public string PostCode { get; set; } | ||
|
||
public string Country { get; set; } | ||
} |
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,36 @@ | ||
using Bogus; | ||
using John.Bogus; | ||
using System.Text.Json; | ||
|
||
Randomizer.Seed = new Random(69); | ||
|
||
var billingDetailsFaker = new Faker<BillingDetails>("zh_TW") | ||
.RuleFor( x=> x.CustomerName, x => x.Person.FullName) | ||
.RuleFor( x=> x.Email, x=> x.Person.Email) | ||
.RuleFor(x => x.Phone, x => x.Person.Phone) | ||
.RuleFor(x => x.AddressLine, x => x.Address.StreetAddress()) | ||
.RuleFor(x => x.City, x => x.Address.City()) | ||
.RuleFor(x => x.Country, x => x.Address.Country()) | ||
.RuleFor(x => x.PostCode, x => x.Address.ZipCode()); | ||
|
||
var orderFaker = new Faker<Order>() | ||
.RuleFor(x => x.Id, Guid.NewGuid) | ||
.RuleFor(x => x.Currency, x => x.Finance.Currency().Code) | ||
.RuleFor(x => x.Price, x => x.Finance.Amount(5, 100)) | ||
.RuleFor(x => x.BillingDetails, x => billingDetailsFaker); | ||
|
||
//orderFaker.Generate(); | ||
//orderFaker.Generate(10); | ||
var jsonSerializerOptions = new JsonSerializerOptions() | ||
{ | ||
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, | ||
WriteIndented = true, | ||
}; | ||
|
||
foreach (var order in orderFaker.GenerateForever()) | ||
{ | ||
var text = JsonSerializer.Serialize(order, jsonSerializerOptions); | ||
|
||
Console.WriteLine(text); | ||
await Task.Delay(1000); | ||
} |
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