-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutoFixture always generate the same TimeZoneInfo #1097
Comments
Hi, This behavior happens because To get a random time zone for each time, add the following customization to your fixture: fixture.Customizations.Add(new ElementsBuilder<TimeZoneInfo>(TimeZoneInfo.GetSystemTimeZones())); That should help 😉 |
@zvirja do you think it would make sense to add registrations like this one to the base setup? I have this one fixture.Customizations.Add(new ElementsBuilder<Encoding>(Encoding.GetEncodings().Select(e => e.GetEncoding()))); If we look it from a mathematical point of view, we're telling AutoFixture what's the space of valid values of these types… |
@zvirja I didn't knew about the ElementsBuilder, the only difference i see from my implementation is that the ElementsBuilder returns a random TimeZoneInfo while I return sequentially, but for the sake of tests it doesn't really matter. I will use the ElementsBuilder, thanks! But my intention with this issue is more like what @Kralizek is asking, is this something that should already be configured in the base setup of AutoFixture? |
@Kralizek @TrymBeast I don't mind adding this to the library, so it's supported natively. The only concern I have whether it might break the existing tests, as people might already rely on the Additionally, we should consider implementing it in a way that it doesn't affect fixture construction performance. The call to |
@zvirja Aren't registrations already evaluated only in case of need? |
@zvirja, generated |
@moodmosaic Thanks for the feedback! Did as you suggested. Hope people don't rely on this behavior in their tests 🤞 |
I've rarely seen someone rely on a bug 😊 |
Hello,
I have found yesterday that AutoFixture always generates the same TimeZoneInfo, I had to implement one specimen builder to get a new one from the available TimeZoneInfos in the system.
Is this something that should be bundled in AutoFixture?
The text was updated successfully, but these errors were encountered: