I have a test case where I need 4 distinct dates to build my objects.
Everything I found seem to tell that AutoFixture always generate unique elements but the thing is when it generates dates, it does so considering everything down to ticks. The result is that when I do .ToShortDateString()
on the result, I may end up with duplicated results.
I know I could loop until I get only distinct values but it doesn't feel right.
For now, what I have is:
string[] dates;
do
{
dates = _fixture.CreateMany<DateTime>(4).Select(d => d.ToShortDateString()).ToArray();
} while (dates.Distinct().Count() != 4);