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

How to use AutoBogus/Bogus to generate a constant value for a property based on its type?

I'm trying to generate objects of a class whereby its value should reflect its type. For example, if its property's type is a string, then that property's value should be "string" and if it is an integer, it should be of a max integer value. So far,…
John Evans Solachuk
  • 1,953
  • 5
  • 31
  • 67
2
votes
1 answer

Use AutoFaker set RuleFor to null

I'm trying the next rule : var result = new AutoFaker().RuleFor(x => x.AnotherModel, null).Generate(); public class MyModel { public string Test { get; set; } public AnotherModel AnotherModel { get; set; } } public class…
user7849697
  • 503
  • 1
  • 8
  • 19
2
votes
1 answer

Generate fake data for Enum in Bogus library

I want to create fake data with Bogus library to test database performance. Here my book example: public class Book { public Guid Id { get; set; } public string Title { get; set; } public double Price { get; set;…
user16336308
2
votes
2 answers

Can I Set the Country in Bogus (C#)

I've just started working with Bogus in C# .net 5.0. I am managing to return very usable data in a sandbox app but I want to restrict the the data to be USA based. Is there a way to do this? (here's part of my sandbox app) using Bogus; namespace…
john rains
  • 321
  • 3
  • 8
2
votes
1 answer

Returning a concrete implementation as a generic

I have an interface which looks like this: public interface IFaker { Faker GetFaker() where T : class; } public class DogFaker : IFaker { public Faker GetFaker() where T : class { return new Faker() …
TomSelleck
  • 6,706
  • 22
  • 82
  • 151
1
vote
0 answers

Generating child data with C# Bogus gives EF Core seed relationship error

According to the official example it is possible to generate seed data for a child while generating the parent. int commentId = 1; var comments = new Faker() .RuleFor(m => m.Id, f => commentId++) .RuleFor(m =>…
Randy Hall
  • 7,716
  • 16
  • 73
  • 151
1
vote
0 answers

Separate copy of DbContext class for unit testing?

I have a CatalogDbContext class. I want to use Bogus library to seed fake data into the database that my unit tests will use. The example provided in bogus's github repo makes use of the HasData method of the CatalogDbContext class to seed data into…
blogs4t
  • 2,329
  • 5
  • 20
  • 33
1
vote
1 answer

Create a List of Numbers in Bogus

I need to obtain a list of random positive numbers generated with Bogus. The returned object should be the IEnumerable type. This will give a number, is there an easy way to generate a list using Bogus? var fakeNumber = new…
1
vote
1 answer

Generate Random Age Height Weight using Bogus

using Bogus we can generate fake and random data easily: https://github.com/bchavez/Bogus Now I need to generate some Person's. They have age, weight, height, so here is my code: internal class Person { public int Age { get; set; } public…
Inside Man
  • 4,194
  • 12
  • 59
  • 119
1
vote
1 answer

Bogus - Faker to pick a random custom type

Have this: var SampleNames = new PersianName[] { new XName("Sara","Dianov"), new XName("Eliza","Raas"), new XName("Robert","Smith") }; var theFaker = new Faker() …
Kasrak
  • 1,509
  • 4
  • 24
  • 48
1
vote
1 answer

Mock dynamic properties in expression, for use with Bogus

I want to configure a Bogus rule that sets a dynamic property on an otherwise straight forward model. N.B. I'm aware this is very much related to the C# compiler/runtime in general and would very much welcome a solution in that context. However, I…
Juliën
  • 9,047
  • 7
  • 49
  • 80
1
vote
1 answer

Is there a test data builder that works with classes without default constructor?

Due to introducing C# 8's non-nullable reference types to my codebase, I'm changing my domain classes to have constructors that accept parameters to initialize values of their non-nullable properties. In unit tests I don't want to bother with…
Павле
  • 800
  • 5
  • 20
1
vote
1 answer

Generate a random number of Addresses each with a unique Type-value with Bogus Faker

Im using Bogus https://github.com/bchavez/Bogus/ for generating testdata. I have a Person-object that has properties: firstName, lastName addresses (list) The Address-Object has properties: streetAddress, zipCode, city addressType,…
jZen
  • 13
  • 1
  • 4
1
vote
0 answers

AutoBogus configuration and Bogus Determinism

When using the AutoBogus builder configurations with either the Create or Generate methods, I can't seem to find the way I can provide the deterministic way to seed random. UseSeed is not available. For example: var orderFaker =…
rspring1975
  • 103
  • 1
  • 9
1
vote
1 answer

String of fixed length digits in Bogus

I did this: var f = new Faker(); String.Join("", f.Random.Digits(10) However, is there another method that would eliminate the 'Join' call?
b_levitt
  • 7,059
  • 2
  • 41
  • 56