What can be faked
What types can be faked?
FakeItEasy uses Castle DynamicProxy to create fakes. Thus, it can fake just about anything that could normally be overridden, extended, or implemented. This means that the following entities can be faked:
- classes that
- are not sealed,
- are not static, and
- have at least one public or protected constructor whose arguments FakeItEasy can construct or obtain
Note that special steps will need to be taken to fake internal interfaces and classes.
Types whose methods have
Generic types that contain methods having a parameter modified by the
in keyword cannot be faked by FakeItEasy.
This limitation is tracked as issue 1382.
Where do the constructor arguments come from?
- they can be supplied via
WithArgumentsForConstructoras shown in creating fakes, or
- FakeItEasy will use dummies as arguments
What members can be overridden?
Once a fake has been constructed, its methods and properties can be overridden if they are:
- abstract, or
- an interface method when an interface is being faked
Note that this means that static members, including extension methods, cannot be overridden.
Methods that return values by reference
Methods that return values by reference (officially called "reference return values") cannot be invoked on a Fake. Any attempt to do so will result in a
NullReferenceException being thrown.