You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
After some more investigation, it looks like the issue with Person is that it is initialised when it's passed into Parse. When Populate() is called it generates a bunch of values for Person which in turn means that other values returned from Parse will not be returning the first expected value for the seed. I could just update the tests to use whatever the new value is but am hoping someone else has a more elegant solution. I was looking into doing a lazy load of person but it doesn't seem to work with the existing functionality.
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"
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
The text was updated successfully, but these errors were encountered: