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

Prefix accepts gender but doesn't correctly use it #572

Open
stampmelk opened this issue Nov 14, 2024 · 0 comments
Open

Prefix accepts gender but doesn't correctly use it #572

stampmelk opened this issue Nov 14, 2024 · 0 comments

Comments

@stampmelk
Copy link

Bogus NuGet Package

35.6.1

.NET Version

.net 8

Visual Studio Version

17.11.3

What operating system are you using?

Windows

What locale are you using with Bogus?

default

Problem Description

When instantiating a new instance of test data, I pass the gender to the FirstName and Lastname where it seems to be used successfully. The Prefix also accepts it, but gives an inconsistent description. For male, I might get Ms and Mrs, for example. See code snippets for example below.

LINQPad Example or Reproduction Steps

 public class FakePerson
 {
     public Gender Gender { get; set; }
     public string FirstName { get; set; }
     public string LastName { get; set; }
     public string MiddleName { get; set; }
     public string FullName { get; set; }

     public string Prefix { get; set; }

     public string StreetAddress { get; set; }

     public string City { get; set; }

     public DateTime DateOfBirth { get; set; }

     public bool SupportsGenderPrefixes { get; set; }

 }   

    // get fake patient info:
    var personFaker = new Faker<FakePerson>()
        .RuleFor(p => p.Gender, f => f.PickRandom<Gender>())
        .RuleFor(p => p.FirstName, (f, p) => f.Name.FirstName(p.Gender))
        .RuleFor(p => p.LastName, (f, p) => f.Name.LastName(p.Gender))
        .RuleFor(p => p.MiddleName, (f, p) => f.Name.FirstName(p.Gender))
        .RuleFor(p => p.Prefix, (f, p) => f.Name.Prefix(p.Gender))
        .RuleFor(p => p.StreetAddress, (f, p) => f.Address.StreetAddress())
        .RuleFor(p => p.City, (f, p) => f.Address.City())
        .RuleFor(p => p.DateOfBirth, (f, p) => f.Person.DateOfBirth)
        .RuleFor(p => p.SupportsGenderPrefixes, (f, p) => f.Name.SupportsGenderPrefixes)

        .RuleFor(p => p.FullName, (f, p)
            => p.FirstName + " " + p.LastName);

    var person = personFaker.Generate();

Expected Behavior

Prefix should work like the first and last name and return a gendered version.

Actual Behavior

A random prefix is returned, independent of the passed gender.

Known Workarounds

Implemented my own method to map to something sensible to call from the rules:

///


/// The package is broken, doing this myself.
///

///
///
static string GetGenderPrefix(Gender gender)
{
return gender switch
{
Gender.Male => "Mr.",
Gender.Female => "Ms.", // or "Mrs." if you need to specify further
_ => "Mx." // Option for non-binary or unspecified
};
}

Could you help with a pull-request?

Yes

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