public void TestAddDetour() { // Add the detour _functionDetour.AddDetour(); Assert.Equal(50, _testClass.TestMethod(_testVariable1, _testVariable2)); // Remove the detour _functionDetour.RemoveDetour(); }
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(); }