Autofixture: Controlling number of elements that are created of type string[]

Martin picture Martin · Jul 1, 2014 · Viewed 10.2k times · Source

I have an issue with creating a string array of type string[], everytime it creates 3 values but i want to be able to control this.

I am using

 var tst = fixture.Create<string[]>();

I also looked into using CreateMany but that seemed to return a type of IEnumerable.

Anyone have any ideas ?

Answer

Nikos Baxevanis picture Nikos Baxevanis · Jul 1, 2014

Use the RepeatCount property:

var fixture = new Fixture { RepeatCount = 9 };
var actual = fixture.Create<string[]>();
// -> The 'actual' array is 9 items now.

or

fixture.CreateMany<string>(9).ToArray()