Пример #1
0
        public void Test_WrapInstanceMethod_WithoutParameter()
        {
            var    assemblyToTest  = "WrapInstanceMethodWithoutParameter";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            string methodName = "TestMethod";

            var instance = Activator.CreateInstance(type);

            var testMethod = type.GetMethod(methodName);

            testMethod.Invoke(instance, new object[] { });

            Tracker.LastValue.Should().Be("default");

            Action <object> @delegate = (object obj) =>
            {
                Tracker.Call("new");
            };

            var parameters = new List <Core.Parameter>();

            SetupCodeChangeDelegate(type, @delegate, methodName, parameters);

            var instance2 = Activator.CreateInstance(type);

            testMethod.Invoke(instance2, new object[] { });

            Tracker.LastValue.Should().Be("new");
        }
        public void Test_WrapOverrideMethodWithGenericNested()
        {
            var    assemblyToTest  = "WrapOverrideMethodWithGenericNested";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            var methodName = "BaseMethod";

            var baseMethod = type.GetMethod(methodName);

            baseMethod = baseMethod.MakeGenericMethod(typeof(string));

            var instance = Activator.CreateInstance(type);

            Func <string> inputDelegate = () => "default";

            var result = baseMethod.Invoke(instance, new Func <string>[] { inputDelegate });

            result.Should().Be("default");

            Func <object, Func <string>, string> @delegate = (object obj, Func <string> str) =>
            {
                return(str() + 1);
            };

            var parameters = new List <Core.Parameter>()
            {
                new Core.Parameter
                {
                    Type = new Core.ClassType
                    {
                        IsGeneric = true,
                        Name      = "System.Func`1<T>"
                    }
                }
            };

            SetupCodeChangeDelegate(type, @delegate, methodName, parameters);

            var instance2 = Activator.CreateInstance(type);

            result = baseMethod.Invoke(instance2, new Func <string>[] { inputDelegate });

            result.Should().Be("default1");
        }
        public void Test_IInstanceClass_Implementation()
        {
            var    assemblyToTest  = "IInstanceClassInterfaceImplementationTest";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            var interfaces = type.GetInterfaces();

            var obj           = Activator.CreateInstance(type);
            var instanceClass = obj.Should().BeAssignableTo <IInstanceClass>().Subject;

            instanceClass.InstanceMethods.Count().Should().Be(0);
        }
        public void Test_WrapOverrideMethodGenericClass()
        {
            var    assemblyToTest  = "WrapOverrideMethodGenericClass";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest) + "`1");

            type = type.MakeGenericType(typeof(string));

            var methodName = "BaseMethod";

            var baseMethod = type.GetMethod(methodName);

            var instance = Activator.CreateInstance(type);

            var result = baseMethod.Invoke(instance, new string[] { "default" });

            result.Should().Be("default");

            Func <object, string, string> @delegate = (object obj, string str) =>
            {
                return(str + 1);
            };

            var parameters = new List <Core.Parameter>()
            {
                new Core.Parameter
                {
                    Type = new Core.ClassType
                    {
                        IsGeneric = true,
                        Name      = "T"
                    }
                }
            };

            SetupCodeChangeDelegate(type, @delegate, methodName, parameters);

            var instance2 = Activator.CreateInstance(type);

            result = baseMethod.Invoke(instance2, new string[] { "default" });

            result.Should().Be("default1");
        }
Пример #5
0
        public void Test_Constructor_WithParameter()
        {
            var    assemblyToTest  = "CaptureConstructorParameter";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            var defaultConstructor = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(int) }, null);

            var obj = defaultConstructor.Invoke(new object[] { 1 });

            var parametersFields = type.GetField("hotReloading_Ctor_Parameters", BindingFlags.Instance | BindingFlags.NonPublic);
            var parameters       = parametersFields.GetValue(obj) as ArrayList;

            parameters[0].Should().Be(1);
        }
Пример #6
0
        public void Test_WrapInstanceMethod_WithParameter()
        {
            var    assemblyToTest  = "WrapInstanceMethodWithParameter";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            string methodName = "TestMethod";

            var testMethod = type.GetMethod(methodName);

            var instance = Activator.CreateInstance(type);

            var result = testMethod.Invoke(instance, new object[] { "default" });

            result.Should().Be("default");

            Func <object, string, string> @delegate = (obj, str) =>
            {
                return(str + 1);
            };

            var parameters = new List <Core.Parameter>()
            {
                new Core.Parameter
                {
                    Type = new Core.ClassType
                    {
                        Name         = typeof(string).FullName,
                        AssemblyName = typeof(string).Assembly.GetName().Name
                    }
                }
            };

            SetupCodeChangeDelegate(type, @delegate, methodName, parameters);

            var instance2 = Activator.CreateInstance(type);

            result = testMethod.Invoke(instance2, new string[] { "default" });

            result.Should().Be("default1");
        }
        public void Test_BaseMethodCallTest2()
        {
            var    assemblyToTest  = "BaseMethodCallTest2";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            var methodName = "HotReloadingBase_BaseMethod";

            var baseMethod = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);

            var instance = Activator.CreateInstance(type);

            baseMethod.Invoke(instance, new object[] { });

            Tracker.LastValue.Should().Be("default");
        }
Пример #8
0
 public void Test_WrapInstanceMethod_WithoutParameter()
 {
     var    assemblyToTest  = "RandomGenericTest";
     string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);
 }
        public void Test_WrapOverrideMethod()
        {
            var    assemblyToTest  = "WrapOverrideMethodTest";
            string newAssemblyPath = Helper.GetInjectedAssembly(assemblyToTest);

            var assembly = Assembly.LoadFrom(newAssemblyPath);

            var type = assembly.GetType(Helper.GetFullClassname(assemblyToTest));

            var methodName = "BaseMethod";

            var baseMethod = type.GetMethod(methodName);

            var instance = Activator.CreateInstance(type);

            baseMethod.Invoke(instance, new object[] { });

            Tracker.LastValue.Should().Be("default");

            Action <object> @delegate = (object obj) =>
            {
                Tracker.Call("new");
            };

            var parameters = new List <Core.Parameter>();

            SetupCodeChangeDelegate(type, @delegate, methodName, parameters);

            var instance2 = Activator.CreateInstance(type);

            baseMethod.Invoke(instance2, new object[] { });

            Tracker.LastValue.Should().Be("new");

            methodName = "BaseMethod1";

            var baseMethod1 = type.GetMethod(methodName);

            var instance3 = Activator.CreateInstance(type);

            var result = baseMethod1.Invoke(instance3, new string[] { "default" });

            result.Should().Be("default");

            parameters = new List <Core.Parameter>()
            {
                new Core.Parameter
                {
                    Type = new Core.ClassType
                    {
                        Name         = typeof(string).FullName,
                        AssemblyName = typeof(string).Assembly.GetName().Name
                    }
                }
            };

            Func <object, string, string> @delegate1 = (obj, str) =>
            {
                return(str + 1);
            };

            SetupCodeChangeDelegate(type, @delegate1, methodName, parameters);

            var instance4 = Activator.CreateInstance(type);

            result = baseMethod1.Invoke(instance4, new string[] { "default" });

            result.Should().Be("default1");
        }