As @NikosBaxevanis correctly points out in his answer, AutoFixture is able to create anonymous instances of any delegate type. These anonymous delegates take the form of dynamically generated methods.
The generation strategy, as it's currently implemented, follows these rules:
- If the delegate's signature is
void
, the created method will be a
no-op.
- If the delegate's signature has a return value
T
, the created method will return an anonymous instance of T
.
Given these rules, in the case of Func<TextWriter>
it would be enough to just customize the creation of anonymous TextWriter
objects with:
fixture.Register<TextWriter>(() => new StringWriter());