nickdodd79 / AutoBogus

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

Question: Setup rules by type? #38

Closed weitzhandler closed 4 years ago

weitzhandler commented 4 years ago

Hi and thanks for this wonderful library!

nickdodd79 commented 4 years ago

Hey @weitzhandler

If I understand your request, there is a WithSkip config handler, but this is tied to members and not types. However you could look at the WithOverride handler to provide something more generic and type based.

With regards to the number of objects to be generated for all collections, there is a WithRepeatCount handler which specifies the number of items in a collection.

All these config handlers can be defined at a global, faker or generate level, and are all described in the readme file.

Nick.

weitzhandler commented 4 years ago

Thank you. A WithSkip<Type>(Type type) would be awesome. I can PR if needed.

nickdodd79 commented 4 years ago

Hey @weitzhandler

Just an update that I have something in place for this, just running it through some tests. I'll let you know when it is released.

Nick.

weitzhandler commented 4 years ago

Thanks for your input.

weitzhandler commented 4 years ago

Don't forget to include Closes #38 in your post.

nickdodd79 commented 4 years ago

Hey @weitzhandler

Apologies for the delay. I finally found some time to get a fix in place for another issue I wanted to release. You should find your requested WithSkip methods in v2.10.0.

An example usage is:

var instance = AutoFaker.Generate<MyClass>(builder =>
{
  builder
    .WithSkip<TypeToSkip>()
    .WithSkip(typeof(AnotherTypeToSkip));
});

All properties and constructor parameters of type TypeToSkip and AnotherTypeToSkip will be skipped during the auto generate.

weitzhandler commented 4 years ago

Wow, nice!