Skip to content
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

Option to filter out en_AU_ocker #490

Open
Drnkmstr opened this issue Aug 11, 2023 · 0 comments
Open

Option to filter out en_AU_ocker #490

Drnkmstr opened this issue Aug 11, 2023 · 0 comments

Comments

@Drnkmstr
Copy link

Drnkmstr commented Aug 11, 2023

Version Information

Software Version(s)
Bogus NuGet Package 34.0.2
.NET Core?
.NET Full Framework?
Windows OS?
Linux OS? MacOS
Visual Studio? JetBrains Rider

What locale are you using with Bogus?

I'm running unit tests using Random.RandomLocale(), so I want to test all of them

What is the expected behavior?

Not to have en_AU_ocker popping in my tests, as it throws an error when creating a new System.Globalization.CultureInfo

What is the actual behavior?

When I run my tests (until failure), the locale en_AU_ocker pops out and make my tests fail.

Please provide a stack trace.

System.Globalization.CultureNotFoundException : Culture is not supported. (Parameter 'name')
en_AU_ocker is an invalid culture identifier.
at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
at Domain.Tests.Tests.<>c.b__6_13(Faker f) in /Users/taarybr1/Developer/Swisscom/Gitlab/bws/dispatch/Matrona/tests/Domain.Tests/Tenant.cs:line 53
at Bogus.Faker1.<>c__DisplayClass34_01.b__0(Faker f, T t)
at Bogus.Faker1.PopulateProperty(T instance, PopulateAction1 action)
at Bogus.Faker1.PopulateInternal(T instance, String[] ruleSets) at Bogus.Faker1.Generate(String ruleSets)
at Domain.Tests.Tests.Dummy() in /Users/taarybr1/Developer/Swisscom/Gitlab/bws/dispatch/Matrona/tests/Domain.Tests/Tenant.cs:line 97
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

Any possible solutions?

I created an extension to filter the locale out:

public static class Extension
{
public static string RandomLocale(this Randomizer randomizer, bool excludeOcker = false)
{
var result = randomizer.RandomLocale();
if (!excludeOcker) return result;
while (Equals(result, "en_AU_ocker"))
{
result = randomizer.RandomLocale();
}
return result;
}
}

How do you reproduce the issue?

Running tests until failure when using Randomizer Faker.Random.RandomLocale

Do you have a unit test that can demonstrate the bug?

Using NUnit

[Test]
public void DamnOcker()
{
Assert.DoesNotThrow(() =>
{
var dummy = new CultureInfo(_testFaker.Random.RandomLocale());
});
}

Can you identify the location in Bogus' source code where the problem exists?

I'm not sure

If the bug is confirmed, would you be willing to submit a PR?

I'm affraid it's too much for me... 😱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant