API Usage

We highly recommend to read the API Reference in our documentation for more information. 



Faking an Instance

 

Method
Description
SealedClass fake = Isolate.Fake.Instance<SealedClass>();
(use Members.ReturnRecursiveFakes or Members.CallOriginal)
Creates fake instances (can be used of interfaces, abstract, concrete and sealed types).
SealedClass fake = Isolate.Swap.NextInstance<SealedClass>().
WithRecursiveFake();
Fakes a future instance.
Isolate.Fake.AllInstances
Fakes all Instances.
UnderTest real = Isolate.Fake.Dependencies<UnderTest>([args])
var fake = Isolate.GetFake<F>(real);
Fakes all dependencies of a type.
Isolate.Fake.Instance<Derived>(Members.ReturnRecursiveFakes,
ConstructorWillBe.Called);
Fakes all methods except the constructor.
Isolate.Fake.Instance<Derived>(Members.CallOriginal,
ConstructorWillBe.Called, BaseConstructorWillBe.Ignored);
Calls the original method and ignores the constructor.
Isolate.Fake.Instance<Derived>(Members.CallOriginal,
ConstructorWillBe.Called, BaseConstructorWillBe.Ignored);
Ignores the base class constructor.
Isolate.Fake.StaticConstructor<Dependency>();
Fakes a static constructor.
var handle
=Isolate.Fake.NextInstance<Dependency>(Members.ReturnRecursiveFakes,
context=>
{
// action here
});
Runs a custom logic.
Isolate.Swap.NextInstance<Dependency>()
.ConstructorWillThrow(new OutOfMemoryException());
Fakes an error in a constructor.

 

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


Calling Tested Methods


Method
Description
Isolate.Invoke.Method(<instance>, "<method_name>", <list_of_arguments>);
Invokes a private method.
Isolate.Invoke.StaticConstructor(typeof(<type>));
Invokes a static constructor.
Isolate.Invoke.Event(() => <event> += <optional list of arguments>);
Fires an event.
var obj = Isolate.NonPublic.CreateInstance<type>(<list of arguments>);
Creates an instance of a type with a private constructor.


Validating


Method
Description
Isolate.Verify<Verification_Kind>(() => fakeDependancy.<method>);
Verifies a method call.
Isolate.Verify<Verification_Kind>(() => <static_method>);
Verifies a static method.
static Isolate.Verify.NonPublic.<WasCalled>(typeof(Dependency),
"PrivateMethodname");
instance Isolate.Verify.NonPublic.WasCalled(<instance>,
"PrivateMethodname");
property Isolate.Verify.NonPublic.Property.WasCalledGet(realDependency,
"PrivateProp");
Isolate.Verify.NonPublic.Indexer.WasCalledGet(realDependency);
Verifies a non-public method.
int count = Isolate.Verify.GetTimesCalled(() => <method>);
Verifies the number of times a method was called.
Isolate.Fake.NextInstances<type>();
Isolate.Verify.WasCalledWithAnyArguments (() => new Dependency());
Verifies that a future instance was created.
Isolate.Fake.AllInstances<type>();

Isolate.Verify.GetTimesCalled(() => new Dependency());
Verifies the number of created instances.
var fake = Isolate.Fake.NextInstances<type>();
var instance = Isolate.Verify.GetInstancesOf(fake)[index];
Retrieves the ith instance by creation order of type.
Isolate.Verify.OnBase().<Verification_Kind>(() => fake.<method>);
Isolate.Verify.OnBase(type).<Verification_Kind>(() => fake.<method>);
Verify that a method was called on a base.