Public API Fakes
Fields
FakedField<TValue>
sealedA fake of a field: a stored value stands in for the member, one per instance. Reads in the code under test return it and its writes replace it; the test reads and writes it through Value. A selection through a chain follows the instance the chain reaches at each access; when it comes from a table, it covers its own instance only.
Every member throws InvalidOperationException once the test or fixture this fake belongs to has finished.
| AccessList<TValue> Reads { get; } | The reads recorded, in the order the code under test made them. |
|---|---|
| AccessList<TValue> Writes { get; } | The writes recorded, in the order the code under test made them. |
| TValue Value { get; set; } | The stored value for the instance this fake reaches now: the initial value until the code under test or the test writes it. Throws InvalidOperationException when the selection points to no instance now. |
FakedFieldTable<TInstance, TValue>
sealedFakes a field on any instance: one fake per instance, reached by the instance, each with its own stored value starting at the declaration's initial value.
Every member throws InvalidOperationException once the test or fixture this fake belongs to has finished.
| FakedField<TValue> this[TInstance instance] | The fake of one instance. Throws ArgumentNullException when the instance is null. |
|---|---|
| AccessList<TValue> Reads { get; } | The reads recorded on every instance, in the order the code under test made them, each with its instance. |
| AccessList<TValue> Writes { get; } | The writes recorded on every instance, in the order the code under test made them, each with its instance. |
Properties
FakedProperty<TValue>
sealedA fake of a property: a stored value stands in for the member, one per instance. Reads in the code under test return it and its writes replace it; the test reads and writes it through Value. A selection through a chain follows the instance the chain reaches at each access; when it comes from a table, it covers its own instance only.
Every member throws InvalidOperationException once the test or fixture this fake belongs to has finished.
| AccessList<TValue> Reads { get; } | The reads recorded, in the order the code under test made them. |
|---|---|
| AccessList<TValue> Writes { get; } | The writes recorded, in the order the code under test made them. |
| TValue Value { get; set; } | The stored value for the instance this fake reaches now: the initial value until the code under test or the test writes it. Throws InvalidOperationException when the selection points to no instance now. |
FakedPropertyTable<TInstance, TValue>
sealedFakes a property on any instance: one fake per instance, reached by the instance, each with its own stored value starting at the declaration's initial value.
Every member throws InvalidOperationException once the test or fixture this fake belongs to has finished.
| FakedProperty<TValue> this[TInstance instance] | The fake of one instance. Throws ArgumentNullException when the instance is null. |
|---|---|
| AccessList<TValue> Reads { get; } | The reads recorded on every instance, in the order the code under test made them, each with its instance. |
| AccessList<TValue> Writes { get; } | The writes recorded on every instance, in the order the code under test made them, each with its instance. |
Events
FakedEvent
sealedA fake of an event: subscriptions from the code under test land in it and never reach the real event, a raise by the code under test invokes the handlers it holds, and the test raises it with Raise. It starts with no handlers. Handlers are kept per instance: a selection through a chain follows the instance the chain reaches at each access; when it comes from a table, it covers its own instance only.
Every member throws InvalidOperationException once the test or fixture this fake belongs to has finished.
| IReadOnlyList<RecordedHandler> Handlers { get; } | The handlers the code under test subscribed while this fake exists and has not unsubscribed, in subscription order. |
|---|---|
| IReadOnlyList<RecordedInvocation> Invocations { get; } | The raises the code under test made, in order. |
| object Raise() | Raises the event of the instance this fake reaches, as its owner would: invokes the handlers the fake holds for it with the arguments you pass, and returns what the invocation returns, the last handler's result for a delegate with a result. With no handler, it does nothing and returns null. Overloads take up to 16 parameters. Throws ArgumentException when the arguments do not fit the event's delegate. Throws InvalidOperationException when the selection points to no instance now. |
FakedEventTable<TInstance>
sealedFakes an event on any instance: one fake per instance, reached by the instance, each holding the handlers the code under test subscribes to that instance's event.
Every member throws InvalidOperationException once the test or fixture this fake belongs to has finished.
| FakedEvent this[TInstance instance] | The fake of one instance's event. Throws ArgumentNullException when the instance is null. |
|---|---|
| IReadOnlyList<RecordedHandler> Handlers { get; } | The handlers the code under test subscribed on every instance and has not unsubscribed, in subscription order, each with its instance. |
| IReadOnlyList<RecordedInvocation> Invocations { get; } | The raises the code under test made on every instance, in order, each with its instance. |
| FakedEventTable<TInstance> EachRaise() | Raises the event of every instance whose fake holds handlers, as each owner would, with the arguments you pass. Overloads take up to 16 parameters. Throws ArgumentException when the arguments do not fit the event's delegate. |