Skip to content

Commit

Permalink
Add John.Bogus
Browse files Browse the repository at this point in the history
  • Loading branch information
john72831 committed Mar 15, 2023
1 parent 2e0b3b4 commit 1409f40
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
15 changes: 15 additions & 0 deletions John.Bogus/John.Bogus.csproj
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>
35 changes: 35 additions & 0 deletions John.Bogus/Order.cs
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; }
}
36 changes: 36 additions & 0 deletions John.Bogus/Program.cs
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);
}
7 changes: 7 additions & 0 deletions John.sln
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "John.LazyCache", "John.Lazy
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "John.VariableInParallel", "John.VariableInParallel\John.VariableInParallel.csproj", "{C1A55740-3923-4445-94D3-A97D84FF4FB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "John.Bogus", "John.Bogus\John.Bogus.csproj", "{F320134A-FD76-484B-929C-A11AA349C2E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -195,6 +197,10 @@ Global
{C1A55740-3923-4445-94D3-A97D84FF4FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1A55740-3923-4445-94D3-A97D84FF4FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1A55740-3923-4445-94D3-A97D84FF4FB2}.Release|Any CPU.Build.0 = Release|Any CPU
{F320134A-FD76-484B-929C-A11AA349C2E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F320134A-FD76-484B-929C-A11AA349C2E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F320134A-FD76-484B-929C-A11AA349C2E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F320134A-FD76-484B-929C-A11AA349C2E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -231,6 +237,7 @@ Global
{12DE5E75-F984-4603-9C5D-9FE86BAC7B6F} = {A9756AC7-5794-4122-8CD4-EA27917AC914}
{FD67D340-B951-46AD-A34D-DF2340BD28F3} = {0E4DC26C-0E24-419F-A8F8-73D7C7172263}
{C1A55740-3923-4445-94D3-A97D84FF4FB2} = {DCA1731F-2C26-40A9-87E5-247F3A30D4CE}
{F320134A-FD76-484B-929C-A11AA349C2E7} = {0E4DC26C-0E24-419F-A8F8-73D7C7172263}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A169F98-AF3D-41C2-86AA-956352BF2D93}
Expand Down

0 comments on commit 1409f40

Please sign in to comment.