Customizations vs Residue collectors
Asked Answered
D

1

9

I don't really grasp the difference between Customizations and Residue Collectors.

According to Documentation, if I register a customization that can build, ExampleClass it will handle requests for that type that were not handled by other builders. If I register a Residue Collector for type ExampleClass it will handle requests, that were not handled by any (other) builders

Where's the difference?

Dawndawna answered 5/2, 2014 at 23:2 Comment(0)
S
13

tl;dr
That's a very valid question. The difference between the two is priority, that is the order in which they're given the chance to handle requests. Customizations are first, while Residue Collectors are last.

AutoFixture, at its core, consists of a Chain of Responsibility where each node in the pipeline is called a specimen builder. These builders are organized in three categories, which determine their position in the chain:

  1. Customizations
  2. Engine
  3. Residue collectors

Specimen builders higher up in the chain get to handle incoming requests first, effectively overriding those that are further down.

Customizations are typically ad-hoc specimen builders created by the user to handle certain kind of requests in a particular way. Hence, they're are given the highest priority.

Engine are the built-in specimen builders that come with AutoFixture. They handle all primitive types such as strings, numbers and dates.

Residue collectors are the specimen builders with the lowest priority and will catch requests that can't be handled by any other builder. They're typically used as fall-back strategy.

Sequence answered 6/2, 2014 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.