progala2 / Buildenator

A test data builders source generator for .net 5 and later.
MIT License
19 stars 1 forks source link

Generating subentites builders #18

Open progala2 opened 3 years ago

progala2 commented 3 years ago

The golden sample

the source generator should have possibility to generate as follows: Source:

public class Aggregate
{
     public Entity Entity  { get; set; }
}

public class Entity
{
    /*    */
}

[MakeBuilder(typeof(Aggregate), <NewOption?>)]
[<NewAttribute?>]
public partial class AggregateBuilder
{
}

Output:

public partial class AggregateBuilder
{
     /*    */
}

public partial class EntityBuilder
{
    /*   */
}

Detecting entities to generate builders

Namespace rule

To prevent generating wrongly builders for build-in types, or types from external libraries, the buildenator will detect subentities by the same root namespace of the parent entity.

e.x. this is correct:

NameSpaceRoot.Aggregate
NameSpaceRoot.SubNamespace.Entity

this is not correct:

NameSpaceRoot.Aggregate
SubNamespace.Entity

Filtering out value types

By default if the subentity has only one not sophisticated property/contr. parameter, it will be treated as a value type, so no additional builders will be created.

Configurability

Known problems and challenges

For the future

progala2 commented 8 months ago

To start simple - an entity is simple when has only one property/field. It's a false assumption, because this one property may be of a type that is sophisticated itself, but it'll be easy to implement and should cover most of the cases.