Is it possible to write a TestDataBuilder which follows a given syntax?
So for example:
I know how to write a basic builder for a car that's not the problem.
But how can I achieve, that I can only add new windows to a door?
So this is allowed:
var car = CarBuilderWithSyntax.Create()
.WithDoor()
.HavingSide(Sides.Left)
.WithWindow()
.HavingWidth(50)
.HavingHeight(50)
.Build();
But this is not allowed:
var car = CarBuilderWithSyntax.Create()
.WithWindow()
.HavingWidth(50)
.HavingHeight(50)
.Build();
Is there a possibility to enforce this syntax-rule?
Can this be achieved by using an additional door builder which inherits car builder?
Should the car builder implement different interfaces like IDoorBuilderWithSyntax which defines the methods ICarBuilderWithSyntax WithWindow()
and ICarBuilderWithSyntax HavingSide();
ICarBuilderWithSyntax HavingColor()
?