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 Bogus.Person();
Assert.AreEqual(person1.FullName, person2.FullName);
However, is there a way to reset the seed so that it wouldn't, ie:
Bogus.Config.SetSeed(1);
var person1 = new Bogus.Person();
Bogus.Config.SetSeed(1);
var person2 = new Bogus.Person();
Assert.AreEqual(person1.FullName, person2.FullName);
The other answer will change the global seed, which isn't really nice:
The recommend way is to change the seed of the Faker itself:
For the non-generic Faker:
var seed = 8675309;
var faker = new Faker()
faker.Random = new Randomizer(seed );
The generic Faker has a helper, UseSeed:
var seed = 8675309;
var faker = new Faker<MyClass>().UseSeed(seed);
The readme has an example of this:
//Set the randomzier seed if you wish to generate repeatable data sets.
Randomizer.Seed = new Random(8675309);
However, setting the seed means that the results of the random generator are consistent. To do what you want, you'll need to reset the seed before each call to get the same results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With