AutoFixture currently seeks to create unique numbers, but does not guarantee it . For example, you can exhaust the range that is likely to happen for byte values. If, for example, you request 300 byte values, you will get duplicates, because there are only 256 values ββto choose from.
AutoFixture will happily use the values ββafter the original set has been exhausted; an alternative would be an exception.
If it is important for the test case that the numbers are unique, I would recommend making this explicit in the test case itself. You can combine Generator<T> with Distinct to do this:
var uniqueIntegers = new Generator<int>(new Fixture()).Distinct().Take(10);
If you use AutoFixture.Xunit2 , you can query Generator<T> using the argument of the test method:
[Theory, AutoData] public void MyTest(Generator<int> g, string foo) { var uniqueIntegers = g.Distinct().Take(10);
Mark seemann
source share