bchavez / bchavez/Bogus

Option to filter out en_AU_ocker

Open
#490 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
9.7k
Forks
538
PR merge metrics
No merged PRs in 30d

Description

### 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.Faker`1.<>c__DisplayClass34_0`1.b__0(Faker f, T t)
at Bogus.Faker`1.PopulateProperty(T instance, PopulateAction`1 action)
at Bogus.Faker`1.PopulateInternal(T instance, String[] ruleSets)
at Bogus.Faker`1.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... 😱

Contributor guide

Open the contributing guide

Research direction

Start at the Randomizer.RandomLocale entry point and reproduce the issue with the NUnit DamnOcker test shown in the report. Trace how en_AU_ocker is selected, then verify that the requested filtering option prevents it from being returned and that constructing CultureInfo no longer fails for the test case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
internationalization, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.