fake_seed_data.cs in C#
Bogus generates the realistic test data you did not want to write.
// fake_seed_data: Bogus builds realistic fixtures from declarative rules
using Bogus;
var faker = new Faker<User>()
.CustomInstantiator(f => new User(
f.Name.FullName(),
f.Internet.Email(),
f.Random.Int(18, 80)));
var users = faker.Generate(5);
foreach (var user in users)
{
Console.WriteLine($"{user.Name,-24} {user.Age,3} {user.Email}");
}
var adults = users.Count(u => u.Age >= 30);
Console.WriteLine($"{adults} of {users.Count} are 30 or older");
record User(string Name, string Email, int Age);
How it works
- A
Faker<User>holds the rules;CustomInstantiatorfills a record. Generate(5)yields fresh, plausible users each run.- Downstream code — the count of 30+ — treats it as real data.
Keywords and builtins used here
Userforeachinintnewrecordstringusingvar
The run, in numbers
- Lines
- 19
- Characters to type
- 505
- Tokens
- 113
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 80 seconds.
Step 2 of 2 in Encore, step 16 of 16 in The open ecosystem.