Skip to content

Bogus in C#: net10.0, UseSeeding, seeded generator, email test fix - #2300

Open
vladimir-pecanac-main wants to merge 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/79775-data-generation-bogus-dotnet
Open

vladimir-pecanac-main wants to merge 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/79775-data-generation-bogus-dotnet

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample for https://code-maze.com/data-generation-bogus-dotnet/ (folder dotnet-client-libraries/BogusNugetPackage only).

  • net7.0 to net10.0; Bogus 35.6.5, EF Core 10.0.13, direct System.Security.Cryptography.Pkcs 10.0.13 (clears NU1902/NU1903 from SqlClient's Pkcs 9.0.11)
  • Seeding moves from HasData() in OnModelCreating() to UseSeeding() in OnConfiguring(); EnsureCreated() becomes Migrate()
  • Employee generator keeps its Vehicles rule (no navigation workaround needed with UseSeeding)
  • New GenerateRepeatableVehicles(int seed) plus a same-seed test
  • Flaky email test fixed: Bogus does not always put the last name in the email, so the test asserts the email starts with the first name
  • Tests: xunit 2.9.3, runner 4.0.1, Test SDK 18.11.0, coverlet 10.1.0; 4 of 4 passing locally

…tor, email test fix

Retarget both projects to net10.0 (Bogus 35.6.5, EF Core 10.0.13, direct System.Security.Cryptography.Pkcs 10.0.13 for the SqlClient advisory; xunit 2.9.3, runner 4.0.1, Test SDK 18.11.0, coverlet 10.1.0).
EmployeeContext seeds through UseSeeding() in OnConfiguring(); OnModelCreating() and HasData() removed.
GetSeededEmployeesFromDb() calls Migrate() instead of EnsureCreated(); the employee generator keeps its Vehicles rule.
Add GenerateRepeatableVehicles(int seed) and a test that the same seed gives the same vehicles.
The email test asserts StartsWith(FirstName): Bogus does not always use the last name.
Bogus slugifies the name when it builds the email (D'angelo becomes Dangelo), so StartsWith(FirstName) failed about 2 to 3 times in 10,000 runs.
The test now asserts StartsWith(Utils.Slugify(FirstName)); 10,000 probe runs give 0 failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant