NSubstitute Argument matchers used for specifying calls to substitutes. This type can be used with any matcher to match a generic type parameter. If the generic type parameter has constraints, you will have to create a derived class/struct that implements those constraints. Match any argument value compatible with type . Match argument that is equal to . Match argument that satisfies . If the throws an exception for an argument it will be treated as non-matching. Match argument that satisfies . If the throws an exception for an argument it will be treated as non-matching. Invoke any argument whenever a matching call is made to the substitute. Invoke any argument with specified argument whenever a matching call is made to the substitute. Invoke any argument with specified arguments whenever a matching call is made to the substitute. Invoke any argument with specified arguments whenever a matching call is made to the substitute. Invoke any argument with specified arguments whenever a matching call is made to the substitute. Invoke any argument with specified arguments whenever a matching call is made to the substitute. Arguments to pass to delegate. Capture any argument compatible with type and use it to call the function whenever a matching call is made to the substitute. Capture any argument compatible with type and use it to call the function whenever a matching call is made to the substitute. Alternate version of matchers for compatibility with pre-C#7 compilers which do not support ref return types. Do not use unless you are unable to use . For more information see Compatibility Argument Matchers in the NSubstitute documentation. Match any argument value compatible with type . This is provided for compatibility with older compilers -- if possible use instead. Match argument that is equal to . This is provided for compatibility with older compilers -- if possible use instead. Match argument that satisfies . If the throws an exception for an argument it will be treated as non-matching. This is provided for compatibility with older compilers -- if possible use instead. Match argument that satisfies . If the throws an exception for an argument it will be treated as non-matching. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified argument whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Arguments to pass to delegate. Capture any argument compatible with type and use it to call the function whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Capture any argument compatible with type and use it to call the function whenever a matching call is made to the substitute. Perform this chain of callbacks and/or always callback when called. Perform as first in chain of callback when called. Perform this action always when callback is called. Throw exception returned by function as first callback in chain of callback when called. Throw this exception as first callback in chain of callback when called. Throw exception returned by function always when callback is called. The type of the exception. The throw this. Throw this exception always when callback is called. The type of the exception. The exception. Perform this action once in chain of called callbacks. Keep doing this action after the other callbacks have run. Keep throwing this exception after the other callbacks have run. Keep throwing this exception after the other callbacks have run. Throw exception returned by function once when called in a chain of callbacks. The type of the exception Produce the exception to throw for a CallInfo Throw this exception once when called in a chain of callbacks. The type of the exception The exception to throw Perform the given action for every call. The action to perform for every call Clear all the received calls Clear all configured return results (including auto-substituted values). Clear all call actions configured for this substitute (via When..Do, Arg.Invoke, and Arg.Do) Clears all received calls and configured return values and callbacks. Alternate version of matchers for compatibility with pre-C#7 compilers which do not support ref return types. Do not use unless you are unable to use . provides a non-static version of , which can make it easier to use from an abstract base class. You can get a reference to this instance using the static field. For more information see Compatibility Argument Matchers in the NSubstitute documentation. Get the CompatArg instance. Match any argument value compatible with type . This is provided for compatibility with older compilers -- if possible use instead. Match argument that is equal to . This is provided for compatibility with older compilers -- if possible use instead. Match argument that satisfies . If the throws an exception for an argument it will be treated as non-matching. This is provided for compatibility with older compilers -- if possible use instead. Match argument that satisfies . If the throws an exception for an argument it will be treated as non-matching. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified argument whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Invoke any argument with specified arguments whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Arguments to pass to delegate. Capture any argument compatible with type and use it to call the function whenever a matching call is made to the substitute. This is provided for compatibility with older compilers -- if possible use instead. Capture any argument compatible with type and use it to call the function whenever a matching call is made to the substitute. Enqueues a matcher for the method argument in current position and returns the value which should be passed back to the method you invoke. Provides a specification for arguments for use with . Can additionally implement to give descriptions when arguments do not match. Checks whether the satisfies the condition of the matcher. If this throws an exception the argument will be treated as non-matching. Provides a specification for arguments for use with . Can additionally implement to give descriptions when arguments do not match. Matches arguments of type or compatible type. Checks whether the satisfies the condition of the matcher. If this throws an exception the argument will be treated as non-matching. Performance optimization. Allows to mark call as deleted without allocating extra wrapper. To play safely, we track ownership, so object can be re-used only once. Wrapper to track that particular entry was deleted. That is needed because concurrent collections don't have a Delete method. Notice, in most cases the original instance will be used as a wrapper itself. Gets the nth argument to this call. Index of argument The value of the argument at the given index Get the arguments passed to this call. Array of all arguments passed to this call Gets the types of all the arguments passed to this call. Array of types of all arguments passed to this call Gets the argument of type `T` passed to this call. This will throw if there are no arguments of this type, or if there is more than one matching argument. The type of the argument to retrieve The argument passed to the call, or throws if there is not exactly one argument of this type Gets the argument passed to this call at the specified zero-based position, converted to type `T`. This will throw if there are no arguments, if the argument is out of range or if it cannot be converted to the specified type. The type of the argument to retrieve The zero-based position of the argument to retrieve The argument passed to the call, or throws if there is not exactly one argument of this type Adds a callback to execute for matching calls. an action to call Creates a new container based on the current one, which can be configured to override the existing registrations without affecting the existing container. Create an explicit scope, so all dependencies with the lifetime are preserved for multiple resolve requests. Decorates the original implementation with a custom decorator. The factory method is provided with an original implementation instance. The lifetime of decorated implementation is used. Tiny and very limited implementation of the DI services. Container supports the following features required by NSubstitute: - Registration by type with automatic constructor injection - Registration of factory methods for the complex objects - Support of the most required lifetimes: - - - - Immutability (via interfaces) and customization by creating a nested container Value is created only once. Value is created only once per scope. Allows to share the same instance across the objects in the same graph. If no explicit scope is created, an implicit scope is created per single resolve request. New value is created for each time. The default NSubstitute registrations. Feel free to configure the existing container to customize and override NSubstitute parts. Checks if the instance can be used when a is expected. Join the using . Tries to cast sequence to array first before making a new array sequence. Gets or sets whether base method should be called by default. Specifies whether base method should be always ignored for the matching call. If method is both explicitly excluded and included, base method is _not_ called. Specifies whether base method should be called for the matching call. If method is both explicitly excluded and included, base method is _not_ called. Tests whether base method should be called for the call given the existing configuration. Specifies whether base method should be called by default. This configuration is considered only when base method exists (e.g. you created a substitute for the AbstractType with method implementation). Factory method which creates from the . Describes how the does not match the condition specified by this class, or if a detailed description can not be provided for the argument. Description of the non-match, or if no description can be provided. Performance optimization. Allows to not construct if configured result doesn't depend on it. A thread bound state of the NSubstitute context. Usually this API is used to provide the fluent features of the NSubstitute. Sets the route to use for the next call dispatch on the current thread for the specified . Returns the previously configured next route and resets the stored value. If route was configured for the different router, returns and persist the route info. Returns the previously set arguments factory and resets the stored value. Invokes the passed callback in a context of the specified query. Particularly poor implementation of Maybe/Option type. This is just filling an immediate need; use FSharpOption or XSharpx or similar for a real implementation. Delegates to ThreadLocal<T>, but wraps Value property access in try/catch to swallow ObjectDisposedExceptions. These can occur if the Value property is accessed from the finalizer thread. Because we can't detect this, we'll just swallow the exception (the finalizer thread won't be using any of the values from thread local storage anyway). Create a substitute for the given types. Create an instance of the given types, with calls configured to call the base implementation where possible. Parts of the instance can be substituted using Returns(). Perform this action when called. Perform this configured callback when called. Do not call the base implementation on future calls. For use with partial substitutes. Call the base implementation of future calls. For use with non-partial class substitutes. Throw the specified exception when called. Throw an exception of the given type when called. Throw an exception generated by the specified function when called. Clears received calls, configured return values and/or call actions for this substitute. Specifies what to clear on the substitute. Can be combined with | to clear multiple aspects at once. A hint for the NSubstitute that the subsequent method/property call is about to be configured. For example: substitute.Configure().GetValue().Returns(1,2,3); NOTICE, you _don't need_ to invoke this method for the basic configuration scenarios. Ensure you don't overuse this method and it is applied only if strictly required. Due to the NSubstitute configuration syntax it is often impossible to recognise during the method call dispatch whether this is a setup phase or a regular method call. Usually it doesn't matter, however sometimes method invocation could lead to undesired side effects (e.g. the previously configured value is returned, base method is invoked). In that case you might want to provide NSubstitute with a hint that you are configuring a method, so it handles the call in configuration mode. Configure default return value for all methods that return the specified type Configure default return value for all methods that return the specified type, calculated by a function Throw an exception for this call. Exception to throw Throw an exception of the given type for this call. Type of exception to throw Throw an exception for this call, as generated by the specified function. Func creating exception object Throw an exception for this call made with any arguments. Exception to throw Throws an exception of the given type for this call made with any arguments. Type of exception to throw Throws an exception for this call made with any arguments, as generated by the specified function. Func creating exception object Throw an exception for this call. Exception to throw Throw an exception for this call. Exception to throw Throw an exception of the given type for this call. Type of exception to throw Throw an exception for this call, as generated by the specified function. Func creating exception object Throw an exception for this call, as generated by the specified function. Func creating exception object Throw an exception for this call made with any arguments. Exception to throw Throw an exception for this call made with any arguments. Exception to throw Throws an exception of the given type for this call made with any arguments. Type of exception to throw Throws an exception for this call made with any arguments, as generated by the specified function. Func creating exception object Throws an exception for this call made with any arguments, as generated by the specified function. Func creating exception object Checks this substitute has received the following call the required number of times. Checks this substitute has received the following call with any arguments the required number of times. Represents a quantity. Primarily used for specifying a required amount of calls to a member. A non-zero quantity between the given minimum and maximum numbers (inclusive). Minimum quantity (inclusive). Must be greater than or equal to 0. Maximum quantity (inclusive). Must be greater than minInclusive. Returns whether the given collection contains the required quantity of items. true if the collection has the required quantity; otherwise false. Returns whether the given collections needs more items to satisfy the required quantity. true if the collection needs more items to match this quantity; otherwise false. Describe this quantity using the given noun variants. For example, `Describe("item", "items")` could return the description: "more than 1 item, but less than 10 items". A string describing the required quantity of items identified by the provided noun forms. Set null as returned value for this call. Set null as returned value for this call made with any arguments. Set null as returned value for this call. Set null as returned value for this call made with any arguments. Set null as returned value for this call. Set null as returned value for this call. Set null as returned value for this call made with any arguments. Set null as returned value for this call made with any arguments. Set null as returned value for this call. Set null as returned value for this call made with any arguments. Set null as returned value for this call. Set null as returned value for this call made with any arguments. Switches interceptor to dispatch calls via the full pipeline. Raise an event for an EventHandler<TEventArgs> event with the provided and . Raise an event for an EventHandler<TEventArgs> event with the substitute as the sender and the provided . Raise an event for an EventHandler<EventArgsT> event with the substitute as the sender and with a default instance of . Raise an event for an EventHandler or EventHandler<EventArgs> event with the substitute as the sender and with empty EventArgs. Raise an event of type with the provided arguments. If no arguments are provided NSubstitute will try to provide reasonable defaults. If delegate takes single parameter of array type, it's impossible to distinguish whether input array represents all arguments, or the first argument only. If we find that ambiguity might happen, we wrap user input in an extra array. Asserts the calls to the substitutes contained in the given Action were received by these substitutes in the same order. Calls to property getters are not included in the assertion. Action containing calls to substitutes in the expected order Clears last call router on SubstitutionContext for routes that do not require it. This is to help prevent static state bleeding over into future calls. Create a substitute for one or more types. For example: Substitute.For<ISomeType>() Substitute for an interface or class. Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members can be recorded or have return values specified. The type of interface or class to substitute. Arguments required to construct a class being substituted. Not required for interfaces or classes with default constructors. A substitute for the interface or class. Substitute for multiple interfaces or a class that implements an interface. At most one class can be specified. Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members can be recorded or have return values specified. The type of interface or class to substitute. An additional interface or class (maximum of one class) the substitute should implement. Arguments required to construct a class being substituted. Not required for interfaces or classes with default constructors. A substitute of type T1, that also implements T2. Substitute for multiple interfaces or a class that implements multiple interfaces. At most one class can be specified. If additional interfaces are required use the overload. Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members can be recorded or have return values specified. The type of interface or class to substitute. An additional interface or class (maximum of one class) the substitute should implement. An additional interface or class (maximum of one class) the substitute should implement. Arguments required to construct a class being substituted. Not required for interfaces or classes with default constructors. A substitute of type T1, that also implements T2 and T3. Substitute for multiple interfaces or a class that implements multiple interfaces. At most one class can be specified. Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members can be recorded or have return values specified. The types of interfaces or a type of class and multiple interfaces the substitute should implement. Arguments required to construct a class being substituted. Not required for interfaces or classes with default constructors. A substitute implementing the specified types. Create a substitute for a class that behaves just like a real instance of the class, but also records calls made to its virtual members and allows for specific members to be substituted by using When(() => call).DoNotCallBase() or by setting a value to return value for that member. The type to substitute for parts of. Must be a class; not a delegate or interface. An instance of the class that will execute real methods when called, but allows parts to be selectively overridden via `Returns` and `When..DoNotCallBase`. Checks this substitute has received the following call. Checks this substitute has received the following call the required number of times. Checks this substitute has not received the following call. Checks this substitute has received the following call with any arguments. Checks this substitute has received the following call with any arguments the required number of times. Checks this substitute has not received the following call with any arguments. Returns the calls received by this substitute. Forget all the calls this substitute has received. Note that this will not clear any results set up for the substitute using Returns(). See for more options with resetting a substitute. Set a return value for this call. Value to return Optionally return these values next Set a return value for this call, calculated by the provided function. Function to calculate the return value Optionally use these functions next Set a return value for this call made with any arguments. Value to return Optionally return these values next Set a return value for this call made with any arguments, calculated by the provided function. Function to calculate the return value Optionally use these functions next Set a return value for this call. The value(s) to be returned will be wrapped in Tasks. Value to return. Will be wrapped in a Task Optionally use these values next Set a return value for this call, calculated by the provided function. The value(s) to be returned will be wrapped in Tasks. Function to calculate the return value Optionally use these functions next Set a return value for this call made with any arguments. The value(s) to be returned will be wrapped in Tasks. Value to return Optionally return these values next Set a return value for this call made with any arguments, calculated by the provided function. The value(s) to be returned will be wrapped in Tasks. Function to calculate the return value Optionally use these functions next Set a return value for this call. The value(s) to be returned will be wrapped in ValueTasks. Value to return. Will be wrapped in a ValueTask Optionally use these values next Set a return value for this call, calculated by the provided function. The value(s) to be returned will be wrapped in ValueTasks. Function to calculate the return value Optionally use these functions next Set a return value for this call made with any arguments. The value(s) to be returned will be wrapped in ValueTasks. Value to return Optionally return these values next Set a return value for this call made with any arguments, calculated by the provided function. The value(s) to be returned will be wrapped in ValueTasks. Function to calculate the return value Optionally use these functions next Perform an action when this member is called. Must be followed by to provide the callback. Perform an action when this member is called with any arguments. Must be followed by to provide the callback. Perform an action when this member is called. Must be followed by to provide the callback. Perform an action when this member is called with any arguments. Must be followed by to provide the callback. Perform an action when this member is called. Must be followed by to provide the callback. Perform an action when this member is called with any arguments. Must be followed by to provide the callback. Specifies that null is allowed as an input even if the corresponding type disallows it. Specifies that null is disallowed as an input even if the corresponding type allows it. Specifies that an output may be null even if the corresponding type disallows it. Specifies that an output will not be null even if the corresponding type allows it. Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. Initializes the attribute with the specified return value condition. The return value condition. If the method returns this value, the associated parameter may be null. Gets the return value condition. Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. Initializes the attribute with the specified return value condition. The return value condition. If the method returns this value, the associated parameter will not be null. Gets the return value condition. Specifies that the output will be non-null if the named parameter is non-null. Initializes the attribute with the associated parameter name. The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. Gets the associated parameter name. Applied to a method that will never return under any circumstance. Specifies that the method will not return if the associated Boolean parameter is passed the specified value. Initializes the attribute with the specified parameter value. The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to the associated parameter matches this value. Gets the condition parameter value. Specifies that the method or property will ensure that the listed field and property members have not-null values. Initializes the attribute with a field or property member. The field or property member that is promised to be not-null. Initializes the attribute with the list of field and property members. The list of field and property members that are promised to be not-null. Gets field or property member names. Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition. Initializes the attribute with the specified return value condition and a field or property member. The return value condition. If the method returns this value, the associated parameter will not be null. The field or property member that is promised to be not-null. Initializes the attribute with the specified return value condition and list of field and property members. The return value condition. If the method returns this value, the associated parameter will not be null. The list of field and property members that are promised to be not-null. Gets the return value condition. Gets field or property member names.