Bogus faked strings length in range between values

Im writing rule for my string property generated by Bogus:

var fakeThings= new Faker<Thing>()
   .RuleFor(x => x.Name, f => f.Company.CompanyName());

How to generate string property in Bogus between specified values? Something like:

.RuleFor(x => x.Name, f => f.Company.CompanyName().Length(1, 30);
// returns CompanyName with min 1 char and max 30 chars

Answer

It depends on which version you are using, really. I would suggest you try String2 or Utf16String depending on your desired character set.

.RuleFor(x => x.Name, f => f.Random.String2(1, 30);

Leave a Reply

Your email address will not be published. Required fields are marked *