Prefix accepts gender but doesn't correctly use it
- Dominant language
- C#
- Stars
- 9.7k
- Forks
- 537
- PR merge metrics
- No merged PRs in 30d
Description
### 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()
.RuleFor(p => p.Gender, f => f.PickRandom())
.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
Contributor guide
Research direction
Start at the f.Name.Prefix(p.Gender) call and compare its behavior with the gender-aware FirstName and LastName calls shown in the reproduction. Verify generated prefixes for male and female inputs, and confirm that the result is no longer independent of the supplied Gender.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100