Automatic construction

When you extend the TestDataBuilder as part of creating a custom builder you will be forced to override the abstract BuildObject method. You have full flexibility to call the constructor of your class directly as shown above, but you can also invoke some convention-based factories to speed up the creation of your builder (also shown above) using the BuildUsing method.

The BuildUsing method takes an instance of IFactory, of which you can create your own factory implementation that takes into account your own conventions or you can use one of the built-in ones:

  • AllPropertiesFactory - Calls the longest constructor with builder values (or anonymous values if none set) based on case-insensitive match of constructor parameter names against property names and then calls the setter on all properties (public or private) with builder values (or anonymous values if none set)
  • PublicPropertySettersFactory - Calls the longest constructor with builder values (or anonymous values if none set) based on case-insensitive match of constructor parameter names against property names and then calls the setter on all properties with public setters with builder values (or anonymous values if none set)
  • CallConstructorFactory - Calls the longest constructor with builder values (or anonymous values if none set) based on case-insensitive match of constructor parameter names against property names
  • AutoFixtureFactory - Asks AutoFixture to create an anonymous instance of the class (note: does not use any builder values or anonymous values from Dossier)

Did this page help you?