bchavez / bchavez/Bogus

Add Vehicle, Music, and Person to Parse method

Open
#565 2 comments 0 reactions 0 assignees Claimed by @Perks-of-Being-a-Cauliflower View on GitHub
Dominant language
C#
Stars
9.7k
Forks
538
PR merge metrics
No merged PRs in 30d

Description

### Description

I am using Faker dynamically and it would be helpful if the Vehicle, Music, and Person methods were added to the Parse method. Vehicle and Music are simple, they just need to be added to the list of MustsacheMethods passed into the Parse method. Person appears to be a bit more complex. When it is added to Parse it seems to mess up the seed which causes some of the randomizer parse tests to fail. I assume this is because Person takes Randomizer as a parameter itself.

I have attempted the changes on a feature branch with Vehicle and Music working fine but seems a bit redundant if I can't get Person working. Person would also require methods for each of its properties so they can be registered as MustacheMethods.

### LINQPad Code Example

Bogus Version="35.6.1"

```
using Bogus;

void Main()
{
var faker = new Faker();
var manufacturer = faker.Parse("{{vehicle.manufacturer}}");
var genre = faker.Parse("{{music.genre}}");
var firstname = faker.Parse("{{person.getfirstname}}");
var lastname = faker.Parse("{{person.getlastname}}");
var fullname = faker.Parse("{{person.getfullname}}");

if (manufacturer == null)
{
throw new Exception("Parse failed manufacturer is null");
}

if (genre == null)
{
throw new Exception("Parse failed genre is null");
}

if (firstname == null || lastname == null || fullname == null)
{
throw new Exception("Parse failed Person values are null");
}

if ($"{firstname} {lastname}" != fullname)
{
throw new Exception("Person values not generated correctly with Parse");
}
}
```

### What alternatives have you considered?

For Person I tried using a switch statement but this is messy and not ideal for my use case.

### Could you help with a pull-request?

Yes

Contributor guide

Open the contributing guide

Research direction

Start at the Parse method and the MustacheMethods list, then inspect the randomizer parse tests mentioned in the issue. Compare the existing Vehicle and Music registrations with Person and its properties, paying attention to the seed behavior. Done means all requested Parse examples produce values correctly and the randomizer parse tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.