nickdodd79 / AutoBogus

A C# library complementing the Bogus generator by adding auto creation and population capabilities.
MIT License
423 stars 49 forks source link

AutoGenerateContext.ParentType #69

Closed pauldbentley closed 2 years ago

pauldbentley commented 3 years ago

I have an entity I would like to fake, which has a constructor parameter "code" - I need this to be 3 characters in length, the constructor provides validation for this, so any string not 3 charaters will throw an exception.

I was trying to use an AutoGeneratorOverride and checking if the GenerateName is "code" - but I only want to do this if the ParentType is the type I'm interested in. I note that the ParentType property is internal.

So anytime I do new AutoFaker<MyObject>().Generate() - the code parameter is 3 characters.

Am I going about this the wrong way?

nickdodd79 commented 3 years ago

Hey @pauldbentley

Apologies for the delayed response. Using an override is certainly a way of achieving what you need. Making the ParentType public is definitely something we can do and I see benefits it would add.

I will make the change and publish a new version.

Nick.

nickdodd79 commented 2 years ago

Hey @pauldbentley

I just realized I neglected to tell you a new version was released with the ParentType made public.

Nick.