Isolator API for LLM
This is an API page for the use of LLM bots.
------------------------------------------------------------
PROMPT EXAMPLE
------------------------------------------------------------
You are an expert Typemock Developer with a deep understanding of NUnit and Typemock ArrangeActAssert APIs https://www.typemock.com/docs/?book=Isolator&page=HtmlDocs%2FTypemock_API_For_AI.htm
Generate C# unit tests that meet the following specifications:
Frameworks: Use NUnit for testing and Typemock for mocking.
Code Coverage: Include multiple tests for comprehensive coverage.
Structure: Provide full, compilable C# code, including necessary using statements.
Class Under Test: Ensure correct usage of the class under test.
------------------------------------------------------------
TYPEMOCK ISOLATOR API SUMMARY
------------------------------------------------------------
1. FAKING OBJECTS
- Isolate.Fake.Instance()
Create a fake instance of a class.
Example:
var fakePerson = Isolate.Fake.Instance();
- Isolate.Fake.Dependencies(object instance)
Fake all dependencies of a real instance.
Example:
var service = new Service();
Isolate.Fake.Dependencies(service);
- Isolate.Fake.StaticMethods(Type type)
Fake all static methods of a type.
Example:
Isolate.Fake.StaticMethods(typeof(Logger));
- Isolate.Fake.NextInstance()
Fake the next created instance of a type.
Example:
var fakeLogger = Isolate.Fake.NextInstance();
- Isolate.Fake.AllInstances()
Fake all current and future instances of a type.
Example:
var fakeLogger = Isolate.Fake.AllInstances();
2. 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).WillThrow(exception)
Throw an exception when the method is called.
Example:
Isolate.WhenCalled(() => fake.Method()).WillThrow(new Exception("Error"));
- Isolate.WhenCalled(() => method).CallOriginal()
Call the original implementation.
Example:
Isolate.WhenCalled(() => fake.Method()).CallOriginal();
- Isolate.WhenCalled(() => method).WillReturnRecursiveFakes()
Return recursive fakes for return objects.
Example:
Isolate.WhenCalled(() => fake.GetService()).WillReturnRecursiveFakes();
- Isolate.WhenCalled(() => method).DoInstead(context => logic)
Run custom logic instead of the method.
Access arguments via context.Parameters.
Example:
Isolate.WhenCalled(() => fake.Add(2, 3)).DoInstead(context =>
{
var x = (int)context.Parameters[0];
var y = (int)context.Parameters[1];
return x * y;
});
3. 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);
4. FAKING REF AND OUT PARAMETERS
Set values for ref and out parameters directly.
Example:
string outStr = "typemock";
List outList = new List() { 100 };
var fake = Isolate.Fake.Instance();
Isolate.WhenCalled(() => fake.SomeMethod(ref outStr, out outList));
5. VERIFYING CALLS
- Isolate.Verify.WasCalled(() => method)
Verify that a method was called.
Example:
Isolate.Verify.WasCalled(() => fake.Add(2, 3));
- Isolate.Verify.WasNotCalled(() => method)
Verify that a method was not called.
Example:
Isolate.Verify.WasNotCalled(() => fake.Subtract(5, 5));
- Isolate.Verify.GetInstancesOf()
Retrieve all real instances of a fake.
Example:
var instances = Isolate.Verify.GetInstancesOf();
6. FAKING LOCAL FUNCTIONS
- Isolate.NonPublic.WhenCalledLocal(instance, "method", "localMethod").WillReturn(value)
Fake local functions in an instance.
Example:
Isolate.NonPublic.WhenCalledLocal(fake, "UseIntLocal", "GetLocal").WillReturn(3);
- Isolate.NonPublic.WhenCalledLocal("method", "localMethod").WillReturn(value)
Fake static local functions.
Example:
Isolate.NonPublic.WhenCalledLocal("UseStaticLocal", "GetLocal").WillReturn(3);
7. FAKE STATIC CONSTRUCTORS
- Isolate.Fake.StaticConstructor(Type type)
Fake static constructors of a type.
Example:
Isolate.Fake.StaticConstructor(typeof(SomeClass));
8. 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");
9. KEY NOTES
- Fake Dependencies: Use Isolate.Fake.Dependencies to fake dependencies automatically.
- Custom Logic: Use DoInstead with context.Parameters for advanced overrides.
- Argument Matching: Use WithExactArguments for behavior control.
- Ref/Out Parameters: Set values directly before calling WhenCalled.
- Static and Non-Public Methods: Access using Isolate.NonPublic.WhenCalled.
- LINQ Queries: Use WillReturnCollectionValuesOf for IQueryable.
- Future Instances: Use NextInstance or AllInstances.
------------------------------------------------------------
END OF COMPLETE SUMMARY
------------------------------------------------------------