public void TestCall() { CForCallTest.callStatic = 0; var c = new CForCallTest(); HackHelpers.CallMethod(c, test => test.CallInstance(-1), null, new object[] { 2 }); Assert.AreEqual(2, c.callInstance); Assert.AreEqual(0, CForCallTest.callStatic); }
public void TestCallWithRet() { CForCallTest.callStatic = 0; var c = new CForCallTest(); Assert.AreEqual(3, HackHelpers.CallMethod(c, test => test.CallInstanceRet(-1), null, new object[] { 3 })); Assert.AreEqual(3, c.callInstance); Assert.AreEqual(0, CForCallTest.callStatic); }
public void TestConstructMethodDefinition() { Assert.AreEqual(GetMethod(typeof(ClassWithMethods), "Method", new[] { typeof(long) }), HackHelpers.ConstructMethodDefinition <ClassWithMethods>(o => o.Method <int>(), new[] { typeof(long) })); Assert.AreEqual(GetMethod(typeof(ClassWithMethods), "NonGenericMeth", null), HackHelpers.ConstructMethodDefinition <ClassWithMethods>(o => o.NonGenericMeth(), null)); Assert.AreEqual( GetMethod(typeof(ClassWithMethods), "Method2", new[] { typeof(long), typeof(object) }), HackHelpers.ConstructMethodDefinition <ClassWithMethods>(o => o.Method2 <int, string>(default(string)), new[] { typeof(long), typeof(object) })); Assert.AreEqual(GetMethod(typeof(CForCallTest), "CallStatic", null), HackHelpers.ConstructStaticMethodDefinition(() => CForCallTest.CallStatic(11), null)); }
public void TestCallStatic() { CForCallTest.callStatic = 0; var c = new CForCallTest(); HackHelpers.CallStaticMethod(() => CForCallTest.CallStatic(-1), null, new object[] { 2 }); Assert.AreEqual(0, c.callInstance); Assert.AreEqual(2, CForCallTest.callStatic); Assert.AreEqual(20, (int) HackHelpers.CallStaticMethod(() => CForCallTest.CallStaticGeneric(""), new[] { typeof(int) }, new object[] { 20 })); Assert.AreEqual(22, (int) HackHelpers.CallStaticMethod(() => CForCallTest.CallStaticGeneric2 <string>(-1), new[] { typeof(int) }, new object[] { 21 })); Assert.AreEqual(null, HackHelpers.CallStaticMethod(() => CForCallTest.EmitInjectServices <int>(null), new[] { typeof(HackHelpersTest) }, new object[] { null })); }