示例#1
0
        public void TestMethod5()
        {
            var originalClass = typeof(Class5);

            Assert.IsNotNull(originalClass);
            var originalMethod = originalClass.GetMethod("Method5");

            Assert.IsNotNull(originalMethod);

            var patchClass = typeof(Class5Patch);
            var prefix     = patchClass.GetMethod("Prefix");

            Assert.IsNotNull(prefix);
            var postfix = patchClass.GetMethod("Postfix");

            Assert.IsNotNull(postfix);

            Class5Patch.ResetTest();

            var instance = new Harmony("test");

            Assert.IsNotNull(instance);

            var patcher = instance.CreateProcessor(originalMethod);

            Assert.IsNotNull(patcher);
            patcher.AddPrefix(prefix);
            patcher.AddPostfix(postfix);
            patcher.Patch();

            (new Class5()).Method5("foo");
            Assert.IsTrue(Class5Patch.prefixed, "Prefix was not executed");
            Assert.IsTrue(Class5Patch.postfixed, "Prefix was not executed");
        }
示例#2
0
        public void TestMethod5()
        {
            var originalClass = typeof(Class5);

            Assert.IsNotNull(originalClass);
            var originalMethod = originalClass.GetMethod("Method5");

            Assert.IsNotNull(originalMethod);

            var patchClass = typeof(Class5Patch);
            var prefix     = patchClass.GetMethod("Prefix");

            Assert.IsNotNull(prefix);
            var postfix = patchClass.GetMethod("Postfix");

            Assert.IsNotNull(postfix);

            Class5Patch._reset();

            var instance = HarmonyInstance.Create("test");

            Assert.IsNotNull(instance);

            var patcher = new PatchProcessor(instance, new List <MethodBase> {
                originalMethod
            }, new HarmonyMethod(prefix), new HarmonyMethod(postfix));

            Assert.IsNotNull(patcher);
            patcher.Patch();

            (new Class5()).Method5("foo");
            Assert.IsTrue(Class5Patch.prefixed, "Prefix was not executed");
            Assert.IsTrue(Class5Patch.postfixed, "Prefix was not executed");
        }