Isolate.Fake.Instance() Create a fake instance of a class. Example: var fakePerson = Isolate.Fake.Instance();
Isolate.Fake.AllInstances() Fake all current and future instances of a type. Example: var fakeLogger = Isolate.Fake.AllInstances();
ARRANGING BEHAVIOR
Isolate.WhenCalled(() => method).WillReturn(value) Set a return value for a method. Example: Isolate.WhenCalled(() => fake.Add(2, 3)).WillReturn(5);
Isolate.WhenCalled(() => method).CallOriginal() Call the original implementation. Example: Isolate.WhenCalled(() => fake.Method()).CallOriginal();
CONTROL BEHAVIOR BASED ON ARGUMENTS
Isolate.WhenCalled(() => method).WithExactArguments(args…) Set behavior only for specific arguments. Example: Isolate.WhenCalled(() => fake.Add(2, 3)).WithExactArguments(2, 3).WillReturn(10);
VERIFYING CALLS
Isolate.Verify.WasCalled(() => method) Verify that a method was called. Example: Isolate.Verify.WasCalled(() => fake.Add(2, 3));
FAKING LINQ AND COLLECTIONS
Isolate.WhenCalled(() => query).WillReturnCollectionValuesOf(collection) Fake LINQ queries returning IQueryable. Example: var fakedList = new List { new Person(“John”), new Person(“Jane”) }; Isolate.WhenCalled(() => repo.GetPeople()).WillReturnCollectionValuesOf(fakedList.AsQueryable());
Faking Collections and Indexers: Fake specific collection behavior. Example: Isolate.WhenCalled(() => fakeList[0]).WillReturn(“Item”); Isolate.WhenCalled(() => fakeDictionary[“key”]).WillReturn(“Value”);
KEY NOTES
Argument Matching: Use WithExactArguments for behavior control.
LINQ Queries: Use WillReturnCollectionValuesOf for IQueryable.