Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a long string in AutoFixture

Tags:

c#

autofixture

I want to generate a random string of - say length 80.

I'm thinking something like Fixture.Create<string>(length: 80); or Fixture.Create<string>(minimumLength: 60, maximumLenth: 100);. Both would work perfectly fine.

Creating a Customization seems overkill, but maybe that's the correct approach. There are plenty of questions regarding getting a shorter string than the default, which can be achieved with substring, but I need a longer one.

like image 852
Jim Aho Avatar asked Sep 19 '25 08:09

Jim Aho


1 Answers

Try this:

string.Join(string.Empty,Fixture.CreateMany<char>(stringLength))

stringLength is how long you wanted your generated string to be.

or

By default Fixture.Create<string>() creates a string of length 36.
So if you want a string length more than 36, this code will generate a string of length 72:

string.Join(string.Empty,Fixture.CreateMany<string>(2))  
like image 166
Hina Ahuja Avatar answered Sep 20 '25 21:09

Hina Ahuja