-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathScenario3_UnitTests.cs
36 lines (27 loc) · 1.46 KB
/
Scenario3_UnitTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MethodRedirect;
using System;
using System.Reflection;
namespace Scenarios_UT
{
[TestClass]
public class Scenario3_UnitTests
{
[TestMethod]
public void Redirect_InternalVirtualInstanceMethod_To_InternalStaticMethod_DifferentInstance()
{
Assembly assembly = Assembly.GetAssembly(typeof(Scenario3));
Type Scenario_Type = assembly.GetType("MethodRedirect.Scenario3");
Type ScenarioExt_Type = assembly.GetType("MethodRedirect.Scenario3Ext");
MethodInfo Scenario_InternalVirtualInstanceMethod = Scenario_Type.GetMethod("InternalVirtualInstanceMethod", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo ScenarioExt_InternalStaticMethod = ScenarioExt_Type.GetMethod("InternalStaticMethod", BindingFlags.Static | BindingFlags.NonPublic);
var token = Scenario_InternalVirtualInstanceMethod.RedirectTo(ScenarioExt_InternalStaticMethod);
var scenario = (Scenario3)Activator.CreateInstance(Scenario_Type);
string methodName = scenario.InternalVirtualInstanceMethod();
Assert.IsTrue(methodName == "MethodRedirect.Scenario3Ext.InternalStaticMethod");
token.Restore();
methodName = scenario.InternalVirtualInstanceMethod();
Assert.IsTrue(methodName == "MethodRedirect.Scenario3.InternalVirtualInstanceMethod");
}
}
}