Class NSubstituteVirtualMethodsCommand

Namespace: AutoFixture.AutoNSubstitute
Assembly: AutoFixture.AutoNSubstitute.dll

Sets up a substitute object's methods so that the return values will be retrieved from a fixture, instead of being created directly by NSubstitute.

This will setup any non-void virtual methods.

[Obsolete("This class belongs to the legacy integration approach. Use the NSubstituteRegisterCallHandlerCommand class and its dependencies instead.")]
public class NSubstituteVirtualMethodsCommand : ISpecimenCommand

Inheritance

objectNSubstituteVirtualMethodsCommand

Implements

ISpecimenCommand

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

This will setup any non-void virtual methods. This includes:

  • interface's methods/property getters;
  • class's abstract/virtual/overridden/non-sealed methods/property getters.

Notes:

  • Automatic mocking of generic methods isn't feasible - we'd have to antecipate any type parameters that this method could be called with.
  • Void methods are not set up due to a limitation in NSubstitute that When..Do setups can't be overriden
  • Calling a method more than once with the same parameters will always return the same value
  • Methods inherited from Object are not set up due to a limitation in NSubstitute (http://stackoverflow.com/a/21787891).

Constructors

NSubstituteVirtualMethodsCommand()

public NSubstituteVirtualMethodsCommand()

Methods

Execute(object, ISpecimenContext)

Sets up a substitute object's methods so that the return values will be retrieved from a fixture, instead of being created directly by NSubstitute.

public void Execute(object specimen, ISpecimenContext context)

Parameters

specimen object

The substitute to setup.

context ISpecimenContext

The context of the specimen.