Open jeremyhayes opened 4 years ago
Hey @jeremyhayes
Interesting concept. I will see what I can cook up.
Nick.
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)
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:
AutoBogus.Serialization
AutoBogus.Serialization.Json.System
AutoBogus.Serialization.Json.Newtonsoft
AutoBogus.Serialization.Xml.System
Here is a non-exhaustive list of some example use cases:
System.Text.Json
attributes
JsonSerializerOptions
to be able to set conventionsJsonNamingPolicy
JsonRequiredAttribute
to detect the nullability of a propertyJsonIgnoreAttribute
to ignore a property, including conditionally with JsonIgnoreCondition
JsonDerivedTypeAttribute
and JsonPolymorphicAttribute
to support polymorphismNewtonsoft.Json
attributesSystem.Xml.Serialization
XmlArrayAttribute
for detecting nullabilityXmlArrayItemAttribute
for detecting nullability and allowed typesXmlAttributeAttribute
to populate a concrete type when the property is based on an abstract type or to specify the type of data (for example [XmlAttribute(DataType = "base64Binary")] public byte[] Image;
)XmlElement(Type = typeof(Manager))
XmlElement(DataType = "base64Binary")
XmlElementAttribute
to populate a concrete type when the property is based on an abstract typeXmlElement(Type = typeof(Manager))
XmlElement(DataType = "base64Binary")
XmlIgnoreAttribute
to not populate a field with dataXmlIncludeAttribute
to populate a concrete type when the property is based on an abstract typeXmlChoiceIdentifierAttribute
to populate strings/objects that can be set to a specific set of types/valuesVery 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.
Very interested in this feature too, and completely agree with @DarkDibblez, it will be a big time saver!
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:
[Required]
[Range]
[StringLength]
[MinLength]
[MaxLength]
[DataType]
(and/or it's specific implementations)