Changing the Method Behavior

Method

Description

Isolate.WhenCalled(() => fake.Increment()).<behavior>;

Modifies the behavior of a method.

Isolate.WhenCalled(()=>dependency.<method>).<behavior>;

Fakes the behavior for a live object.

Isolate.WhenCalled(() => fakeDependency.GetID()).<behavior>;

Isolate.WhenCalled(() => fakeDependency.GetID()).<behavior>;

...

Fakes a sequenced behavior.

Isolate.WhenCalled(() => <fake>.<method1>.<method2>…).<behavior>;

Fakes a chain of methods.

WhenCalled(() => <method>).WithExactArguments().<behavior>;

Fakes a method based on call arguments.

Isolate.WhenCalled((<type arg1>, <type arg1>) => fake.<method>

(<arg1>, <arg2>))

.AndArgumentsMatch((<arg1>, <arg2>) => <check>

.<behavior>;

Uses a custom checker on arguments.

Isolate.WhenCalled((<type arg1>, <type arg1>) => fake.<method>

(<arg1>, <arg2>, <additional_arguments>))

.AndArgumentsMatch((<arg1>, <arg2>) => <check>

.<behavior>;

Mixes WithExactArguments and custom checkers.

var fakeDependency = Isolate.Fake.Instance<Dependency>();

fakeDependency.Number=<value>; // sets the property to return the value

Controls the behavior of a property using true properties.

Isolate.WhenCalled(() => <property>).WillReturn(<value>);

Controls the behavior of a property using Isolate.WhenCalled().

Isolate.WhenCalled(() => <pInvoke-method()>).<behavior>);

Controls PInvoke methods.

Isolate.Fake.StaticMethods<Dependency>();

Defines the default behavior for a static method.

Isolate.Fake.StaticMethods(typeof(Dependency));

Fakes all static methods of a type.

Isolate.WhenCalled(() => myObject.<extention>()).<behavior>;

Fakes an extension method.

Isolate.NonPublic.WhenCalled(<instance>, "<methodname>").<behavior>

Fakes a private method.

Isolate.NonPublic.WhenCalled<type>("<methodname>").<behavior>

Fakes a private static method.

Isolate.NonPublic.Property.WhenGetCalled(fakeDependency, "PrivateProp")

Isolate.NonPublic.Property.WhenSetCalled(fakeDependency, "PrivateProp")

Fakes a private property or indexer.

var outValue = <value>;

Isolate.WhenCalled(() => fake.SomeMethod(ref outValue)).<behavior>

Fakes a Ref and Out parameter.

var fakeParam = <result>;

Isolate.NonPublic.WhenCalled<Dependency>("method").AssignRefOut(fakeParam).<bahavior>;

Fakes a non-public Ref and Out parameter.

Isolate.WhenCalled(() =>

<your_collection>).WillReturnCollectionValuesOf(<items>);

Controls collections and indexers.

Isolate.WhenCalled(()=> <fake>[<key>]).<behavior>;

Fakes an indexer.

Isolate.WhenCalled(()=><linq_query>.WillReturnCollectionValuesOf(fakedList);

Fakes a LINQ query.

Isolate.WhenCalled(() => fake.<method>).OnBase().<behavior>;

faking method of first implementing base class

Isolate.WhenCalled(() => fake.<method>).OnBase(type).<behavior>;

faking method of specific base class