Questions tagged [bogus]

Use this tag for questions about Bogus, a .NET library for generating fake data.

Bogus is a .NET library for generating fake data, with support for C#, F# and VB.NET. It is a port of the faker.js JavaScript library.

Releases are available on NuGet and the source is available on GitHub.

49 questions
0
votes
2 answers

use bogus to seed data in Entity Framework Core. with foreign key?

I used bogus to seed data in Entity Framework Core, but I get a foreign key constraint error: SqliteException: SQLite Error 19: 'UNIQUE constraint failed: Vaccines.Id'. This is my data generation class: public static class DataGenerator { …
MSH
  • 395
  • 1
  • 4
  • 13
0
votes
0 answers

Is there a way to restrict characters generated by Bogus?

Our C# app has restrictions on certain string properties. For example, a city can't have apostrophes, among other values. When running my tests, I sometimes get false failures because Bogus generated a string with an invalid value. For now, I've…
John Boldt
  • 91
  • 7
0
votes
0 answers

generate mockup using bogus

I have a tricky issue. I'm writing a tool where a user can pass the source code of a C# model as input and it will return mockups (n instances with random content). The question is: Based on this implementation, what are your suggestions to fix the…
CloudAnywhere
  • 669
  • 1
  • 11
  • 27
0
votes
0 answers

Bogus one to many

I want to seed data with Bogus, but I get one error again and again trying to add migration. public class DataContext : DbContext { public DataContext(DbContextOptions options): base(options){ } public DbSet Users { get;…
Setup
  • 1
  • 1
0
votes
1 answer

How to provide an optional instance to Bogus Faker in .NET?

I have my own static helper to generate fake instances of my domain records/classes. Does Bogus have the ability to use a provided instance or fake a new instance if there was none, provided? Here's some code to explain. public static Foo…
0
votes
0 answers

Bogus (Faker) runs on every request

I've been using C# Bogus (aka Faker) to generate data with EF Core, and it's been absolutely invaluable for development. I have this set up in my context class, in the OnModelCreating method. This seems necessary to get the data into the database,…
Randy Hall
  • 7,716
  • 16
  • 73
  • 151
0
votes
1 answer

How to change the format of test dates generated by Bogus in C#

I'd like to format the test dates generated by Bogus to dd.MM.yyyy (eg. 29.09.2022). I've been searching for a solution but can't find anything. I tried the following but it doesn't work: var personData = new Faker() .RuleFor( p…
Mazzmax
  • 7
  • 1
  • 4
0
votes
1 answer

Using Bogus to set member property value range

I have the following classes: Class Person Property ID As String = Nothing Property Firstname As String = "" Property Lastname As String = "" End Class Class Account Property AccountNumber As String = "" Property Owners As…
0
votes
2 answers

Using AutoBogus to set member property value range

I have the following classes: Class Person Property ID As String = Nothing Property Firstname As String = "" Property Lastname As String = "" End Class Class Account Property AccountNumber As String = "" Property Owners As…
0
votes
1 answer

How to generate fixed number of items out of total items with same value in Bogus C#

I am trying to generate 3000 fake records in C# with condition that each 1000 items will have same time stamp(update_time) in UTC milliseconds, then next 1000 will have same time stamp in UTC milliseconds. how to achieve that? private static…
Mehul Parmar
  • 347
  • 4
  • 21
0
votes
1 answer

Bogus RuleFor private field

I have class with private readonly field public class Bar { private readonly ICollection somePrivateCollection = new HashSet(); public IEnumerable SomePublicCollection =>…
Vla Mai
  • 313
  • 3
  • 16
0
votes
1 answer

How to generate fake data with pre-defined list for one column while use Bogus to generate random string in another column in C# EF Core?

I have a list of 9 items and I would like to generate exact 9 records in Standard table with the values in the list for StandardName column and use Bogus to generate the random value for the Description column. Is there a quick and easy way to do it…
R390GT1
  • 48
  • 4
0
votes
0 answers

How to use C# Bogus with Polymorphism? (Base class array uses different derived classes)

I'm using a public API. One of the types has a property that is an array of a base class that needs to be populated with its derived classes (uniquely and one of each derived class). How would I go about that? addresses = new AddressInfo[] { new…
Nomnom
  • 4,193
  • 7
  • 27
  • 37
0
votes
0 answers

Apply rules Generically on top of generics

I'm trying to make an mock data generator which will generate mocks based on a set of rules. I've been playing around with Bogus. I don't want to have to setup my rules for my entity classes each time, I would like to generically be able to apply…
johnny 5
  • 19,893
  • 50
  • 121
  • 195
0
votes
1 answer

BogusFaker ForeignKey dependency for Random Data - C#

When we use ASP.NET MVC framework we have the famous AspNetUsers table, which contains an unique Id for each user. I want to generate data in other tables based on the upon created 'fake' users. How can I pull the Id (from AspNetUsers) that was…
SpcCode
  • 887
  • 2
  • 13
  • 24