vendredi 22 mai 2015

Writing a test data builder with syntax

Is it possible to write a TestDataBuilder which follows a given syntax?

So for example:

Carbuilder

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?

Aucun commentaire:

Enregistrer un commentaire