16

For a list, we can do

fixture.CreateMany<List<string>>(1000); // with 1000 elements

but how to do it with a dictionary? And to be able to specify the number of elements to be generated.

Pang
  • 9,564
  • 146
  • 81
  • 122
John
  • 4,351
  • 9
  • 41
  • 57

1 Answers1

29

You could simply create the items then build the dictionary, like this:

fixture
  .CreateMany<KeyValuePair<int, string>>(1000)
  .ToDictionary(x => x.Key, x => x.Value);

This is more-or-less what AutoFixture does internally.

Another alternative would be to create a new ICustomization, which intercepts requests for any Dictionary<,> and builds them. It could be implemented using code from existing classes.

Adam C
  • 431
  • 5
  • 3