How to get AutoFixture to create an integer> 0 and not another number?

I want AutoFixture to generate two integers, and for the second I don’t want it to be 0 or the previous generated number. Is there a way to tell AutoFixture to comply with this “requirement”.

Looking at the RandomNumericSequenceGenerator , I look like the lower limit is 1 , so I may not need to specify the first requirement. Then I looked at the “seeding” option, but as indicated in this answer , it will not be used for the default number.

Is there something I'm looking at here?

+6
source share
1 answer

Here you can do it with a simple automatic setup:

 [Fact] public void GenerateTwoDistinctNonZeroIntegersWithAutoFixture() { var fixture = new Fixture(); var generator = fixture.Create<Generator<int>>(); var numbers = generator.Where(x => x != 0).Distinct().Take(2); // -> 72, 117 } 

And here is a way to do it with AutoFixture.Xunit :

 [Theory, AutoData] public void GenerateTwoDistinctNonZeroIntegersWithAutoFixtureXunit( Generator<int> generator) { var numbers = generator.Where(x => x != 0).Distinct().Take(2); // -> 72, 117 } 
+7
source

All Articles