You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature: Enable call forwarding and substitution for non virtual methods or sealed classes implementing an interface. (#700)
How to use:
var substitute = Substitute.ForTypeForwardingTo <ISomeInterface,SomeImplementation>(argsList);
In this case, it doesn't matter if methods are virtual or not; it will intercept all calls since we will be working with an interface all the time.
For
Limitations:
Overriding virtual methods effectively replaces its implementation both for internal and external calls. With this implementation NSubstitute will only intercept calls made by client classes using the interface. Calls made from inside the object itself to its own method, will hit the actual implementation.
/// Creates a proxy for a class that implements an interface, forwarding methods and properties to an instance of the class, effectively mimicking a real instance.
95
+
/// Both the interface and the class must be provided as parameters.
96
+
/// The proxy will log calls made to the interface members and delegate them to an instance of the class. Specific members can be substituted
97
+
/// by using <see cref="WhenCalled{T}.DoNotCallBase()">When(() => call).DoNotCallBase()</see> or by
98
+
/// <see cref="SubstituteExtensions.Returns{T}(T,T,T[])">setting a value to return value</see> for that member.
99
+
/// This extension supports sealed classes and non-virtual members, with some limitations. Since the substituted method is non-virtual, internal calls within the object will invoke the original implementation and will not be logged.
100
+
/// </summary>
101
+
/// <typeparam name="TInterface">The interface the substitute will implement.</typeparam>
102
+
/// <typeparam name="TClass">The class type implementing the interface. Must be a class; not a delegate or interface. </typeparam>
103
+
/// <param name="constructorArguments"></param>
104
+
/// <returns>An object implementing the selected interface. Calls will be forwarded to the actuall methods, but allows parts to be selectively
105
+
/// overridden via `Returns` and `When..DoNotCallBase`.</returns>
0 commit comments