Customization and Balance Collectors

I really don't understand the difference between settings and residue collectors.

According to the Documentation , if I register a custom construct that can build, ExampleClass , it processes requests for this type that were not handled by other collectors . If I register a Residue Collector for type ExampleClass , it will process requests that were not handled by any (other) collectors

Where is the difference?

+6
source share
1 answer

Tl dr
This is a very correct question. The difference between them is priority, that is, the order in which they are given the opportunity to process requests. Settings are made first, while Residue Collectors are the last.

AutoFixture, in essence, consists of Chain of Responsibility , where each node in the pipeline is called an instance creator. These builders are organized into three categories that determine their position in the chain:

  • Adaptations
  • Engine
  • Residue Collectors

Sample creators located higher in the chain first process incoming requests, in fact redefining those that are lower.

Settings are usually special sample collectors created by the user to process specific requests in a specific order. Therefore, they are given the highest priority.

The engine is the built-in samplers that come with AutoFixture. They handle all primitive types, such as strings, numbers, and dates.

Residue collectors are sample collectors with the lowest priority and will catch requests that cannot be handled by any other builder. They are commonly used as a return strategy.

+7
source

All Articles