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.
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.
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