public DetourTests() { // Initialize a function detour instance _functionDetour = new FunctionDetour(typeof(TestClass1), "TestMethod", typeof(TestClass2), "TestMethod"); // Initialize a test class _testClass = new TestClass1(); // Initialise test variables _testVariable1 = 5; _testVariable2 = 10; }
public void TestAddDetourWithMethodInfo() { var originalMethodInfo = typeof(TestClass1).GetMethod("TestMethod", BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public); var targetMethodInfo = typeof(TestClass2).GetMethod("TestMethod", BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public); // Initialise a function detour var functionDetour = new FunctionDetour(originalMethodInfo, targetMethodInfo); // Initialize a test class var testClass1 = new TestClass1(); functionDetour.AddDetour(); Assert.Equal(2, testClass1.TestMethod(1, 2)); functionDetour.RemoveDetour(); }