nickdodd79 / AutoBogus

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

Convention to generate based on Data Annotations #43

Open jeremyhayes opened 4 years ago

jeremyhayes commented 4 years ago

Could we leverage the Conventions support to inspect properties annotated with subclasses of ValidationAttribute?

This would provide a low-config way to generate instances which satisfy declarative model validations. A common pattern I see and use is to generate a random (valid) instance, then update one or more properties to exercise a particular validation.

Not all of these would fit well into a generic convention, but certainly some of the more agnostic would be fairly straight-forward:

nickdodd79 commented 4 years ago

Hey @jeremyhayes

Interesting concept. I will see what I can cook up.

Nick.

304NotModified commented 2 years ago

See also supported items on AutoFixture:

https://github.com/AutoFixture/AutoFixture/tree/master/Src/AutoFixture/DataAnnotations

This is important for creating valid objects (and extra important when writing to a database)

ChristopherHaws commented 1 year ago

I am also interested in the feature. Some other attributes that I would like to see supported on top of the ones already listed are attributes related to serialization. I feel like this would be super useful for generating fake data for web api's in particular. It might be a lot for the base library, but maybe:

Here is a non-exhaustive list of some example use cases:

DarkDibblez commented 1 year ago

Very interested in this feature. We do a lot of testing using database contexts and have a rather large (but properly annotated) amount of entities. Currently this means that even though we've already annotated everything we'd still need to add rules duplicating these to the fakers and keep them updated if the data model changes for whatever reason.

gitown commented 7 months ago

Very interested in this feature too, and completely agree with @DarkDibblez, it will be a big time saver!