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
31
votes
1 answer

Bogus.Faker: How to pick a random enum value

I'm using c# Bogus.Faker library to create random test data for my unit tests. I want to know how to easily pick a random enum value ? Any suggestions?
hannes neukermans
  • 12,017
  • 7
  • 37
  • 56
13
votes
2 answers

Bogus, AutoFixture, others(?): How to fill a nested model with fake data and set rules for specific properties?

I have a very nested model that I want to create thousands of with fake data. But, also, some properties in the model need to be in a specific range or have specific rules. I looked at these two fake data generators: AutoFixture only seems to…
Thypari
  • 801
  • 1
  • 6
  • 22
8
votes
2 answers

Bogus Mocking Data Same Values For 2 different properties

Bogus Mocking Data Same Values For 2 different properties is it possible to have 2 properties have same value in the fluent api. var users = new Faker() .StrictMode(false) .RuleFor(o => o.Id, f => orderIds++) .RuleFor(o => o.UserName,…
Dživo Jelić
  • 1,723
  • 3
  • 25
  • 47
8
votes
2 answers

how to represent nullable values with bogus?

There is a beautiful library that generates random/pseudo-random values for a DTO. var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi" }; var orderIds = 0; var testOrders = new Faker() //Ensure all properties have…
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
7
votes
1 answer

Bogus C# - how to get completely randomized objects without listing RuleFor for every property?

Using C# Bogus library, I would like to generate completely random objects without enumerating all fields as RuleFor explicitly. How I could configure my Faker to achieve that?
onkami
  • 8,791
  • 17
  • 90
  • 176
5
votes
1 answer

Bogus faked data: Conditional and random in the same field, possibly leaving a null faked data

In using .net Bogus github repository for filling up a database, I would like to both fill a field randomly with something like: { "Mother", "Sister", "Brother", "Father", "Uncle","Niece","Nephew","Cousin"} But also randomly leave occasional nulls…
SuperDave
  • 373
  • 5
  • 14
5
votes
1 answer

C# Faker Bogus generate owned property

I am trying to play with the Bogus library to generate random seed data in a .Net Core 2.1 application, using EF Core for data management. I have an object called Company, which owns an Address; this is a one-to-one relationship. Company model: …
pab
  • 150
  • 1
  • 11
4
votes
1 answer

How to use Bogus generate test data for one-to-one and many-to-many relationship in EF Core C#?

Bogus is a good tool to generate test data; however, I have two issues on using it for C# Entity Framework on .net 5.0 For the many-to-many relationship - how to generate the data for middle table? my current CourseStudent table is empty at the…
Panco
  • 351
  • 5
  • 13
4
votes
3 answers

How to use Bogus Faker with initialization properties?

I have an immutable DTO that I'd like to fake with Bogus Faker (version 31.0.2) but the property with an overriding rule only returns what it was initialized with by the constructor: Example DTO (real ones are more complex) using Xunit; using…
WooWaaBob
  • 3,397
  • 3
  • 23
  • 23
4
votes
2 answers

Bogus faker how to set a list of string array

I would like to ask your help to use Bogus Faker. I have this private readonly Faker _faker; _faker = new Faker("fr"); List _randomString = (List)_faker.Make(3, () => _faker.Random.Word()); // OK List _randomStrinArray =…
jolynice
  • 514
  • 1
  • 8
  • 25
3
votes
2 answers

Bogus faked strings length in range between values

Im writing rule for my string property generated by Bogus: var fakeThings= new Faker() .RuleFor(x => x.Name, f => f.Company.CompanyName()); How to generate string property in Bogus between specified values? Something like: .RuleFor(x =>…
michasaucer
  • 4,562
  • 9
  • 40
  • 91
3
votes
2 answers

How can I share state between Bogus (C# Faker) rules?

I'm using Bogus to generate test data but I have some fields that depend on parts of another object (that I want to be chosen randomly for each generation) but that have to be consistent with each other. That's probably not the best explanation so…
John
  • 76
  • 1
  • 6
3
votes
2 answers

How do I generate a rule for more than one option in Bogus?

I have a rule to select an option at random: .RuleFor(c=>field, x=>x.PickRandom("Option1", "Option2", "Option3", "Option4")) With a default value, I can alter the probability of one of the items. I would like to set the probabilities of all…
Cakemeister
  • 191
  • 2
  • 6
3
votes
2 answers

Can I specify the random seed for Bogus?

I'm using Bogus to generate test data. Is there a way to set the seed it uses so it generates the same test data, in the same order? For example, this test would fail: var person1 = new Bogus.Person(); var person2 = new…
b_levitt
  • 7,059
  • 2
  • 41
  • 56
3
votes
1 answer

Trying to generate a large-scale test data set with Bogus

I'm trying to generate a production-quality and -quantity size test data set with Bogus, and this library works extremely well with basic data - simple datatypes like int or string, things like first and last name etc. I'm currently not seeing how I…
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
1
2 3 4