예제 #1
0
        public void PluginRuntimeHandler_Run_WhenClassIsStatic_ExpectRunsMethodsCorrectly()
        {
            //------------Setup for test--------------------------

            var type = typeof(StaticClass);
            var svc  = CreatePluginService(new List <IDev2MethodInfo> {
                new Dev2MethodInfo {
                    Method = "ToStringOnStatic", Parameters = new List <IMethodParameter>()
                }
            }, type, new ServiceConstructor());

            //------------Execute Test---------------------------
            using (var isolated = new Isolated <PluginRuntimeHandler>())
            {
                var pluginInvokeArgs = new PluginInvokeArgs
                {
                    MethodsToRun      = svc.MethodsToRun,
                    PluginConstructor = new PluginConstructor
                    {
                        ConstructorName = svc.Constructor.Name,
                        Inputs          = new List <IConstructorParameter>(),
                    },
                    AssemblyLocation = type.Assembly.Location,
                    AssemblyName     = type.Assembly.FullName,
                    Fullname         = type.FullName,
                };
                var instance = isolated.Value.CreateInstance(pluginInvokeArgs);
                instance.Args = pluginInvokeArgs;
                isolated.Value.Run(svc.MethodsToRun.First(), instance, out string str);
                Assert.IsTrue(string.IsNullOrEmpty(str));
                Assert.IsTrue(instance.IsStatic);
            }
        }
예제 #2
0
        public void PluginRuntimeHandler_ExecuteConstructor_WhenClassIsSealed_ExpectRunsCorrectly()
        {
            //------------Setup for test--------------------------

            var type = typeof(Human);
            var svc  = CreatePluginService(new List <IDev2MethodInfo> {
                new Dev2MethodInfo {
                    Method = "ToString", Parameters = new List <IMethodParameter>()
                }
            }, type, new ServiceConstructor());

            //------------Execute Test---------------------------
            using (var isolated = new Isolated <PluginRuntimeHandler>())
            {
                var pluginInvokeArgs = new PluginInvokeArgs
                {
                    MethodsToRun      = svc.MethodsToRun,
                    PluginConstructor = new PluginConstructor
                    {
                        ConstructorName = svc.Constructor.Name,
                        Inputs          = new List <IConstructorParameter>(),
                    },
                    AssemblyLocation = type.Assembly.Location,
                    AssemblyName     = type.Assembly.FullName,
                    Fullname         = type.FullName,
                };
                var instance = isolated.Value.ExecuteConstructor(new PluginExecutionDto(string.Empty)
                {
                    Args = pluginInvokeArgs
                });
                Assert.IsTrue(!string.IsNullOrEmpty(instance.ObjectString));
                Assert.IsFalse(instance.IsStatic);
            }
        }
        public void PluginRuntimeHandler_InvokePlugin_WhenValidDll_ExpectValidResults()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource();
            var svc    = CreatePluginService();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var args = new PluginInvokeArgs
                {
                    AssemblyLocation = source.AssemblyLocation
                    ,
                    AssemblyName = "Foo"
                    ,
                    Fullname = svc.Namespace
                    ,
                    Method = svc.Method.Name
                    ,
                    Parameters = svc.Method.Parameters
                };
                var result = PluginServiceExecutionFactory.InvokePlugin(args);
                //------------Assert Results-------------------------
                var castResult = JsonConvert.DeserializeObject(result.ToString()) as dynamic;
                if (castResult != null)
                {
                    StringAssert.Contains(castResult.Name.ToString(), "test data");
                }
                else
                {
                    Assert.Fail("Failed Conversion for Assert");
                }
            }
        }
예제 #4
0
        public void PluginRuntimeHandler_Run_WhenValidLocation_ExpectResult()
        {
            //------------Setup for test--------------------------
            var svc    = CreatePluginService();
            var source = CreatePluginSource();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                PluginInvokeArgs args = new PluginInvokeArgs {
                    AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters
                };
                var result     = isolated.Value.Run(args);
                var castResult = result as DummyClassForPluginTest;
                //------------Assert Results-------------------------
                if (castResult != null)
                {
                    StringAssert.Contains(castResult.Name, "test data");
                }
                else
                {
                    Assert.Fail("Failed Conversion for Assert");
                }
            }
        }
예제 #5
0
        public void PluginRuntimeHandler_CreateInstance_WhenHuman_ExpectHumanStringObject()
        {
            //------------Setup for test--------------------------

            var type = typeof(Human);
            var svc  = CreatePluginService(new List <IDev2MethodInfo> {
                new Dev2MethodInfo {
                    Method = "ToString"
                }
            }, type, new ServiceConstructor());

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var instance = isolated.Value.CreateInstance(new PluginInvokeArgs
                {
                    MethodsToRun      = svc.MethodsToRun,
                    PluginConstructor = new PluginConstructor
                    {
                        ConstructorName = svc.Constructor.Name,
                        Inputs          = new List <IConstructorParameter>(),
                    },
                    AssemblyLocation = type.Assembly.Location,
                    AssemblyName     = type.Assembly.FullName,
                    Fullname         = type.FullName,
                });

                var deserializeToObject = instance.ObjectString.DeserializeToObject(type, new KnownTypesBinder()
                {
                    KnownTypes = new List <Type>(type.Assembly.ExportedTypes)
                });
                Assert.IsNotNull(deserializeToObject);
            }
        }
예제 #6
0
 public void PluginRuntimeHandler_ValidatePlugin_WhenNullDll_ExpectErrorMessage()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         var result = isolated.Value.ValidatePlugin(null);
     }
 }
예제 #7
0
 public void PluginRuntimeHandler_CreateInstance_WhenNullParameters_ExpectException()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         isolated.Value.CreateInstance(null);
     }
 }
예제 #8
0
 public void PluginRuntimeHandler_ListNamespaces_WhenNullLocation_ExpectException()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         isolated.Value.ListNamespaces(null, "Foo");
     }
 }
예제 #9
0
        public void PluginRuntimeHandler_FetchNamespaceListObjectWithJsonObjects_WhenNullLocationAndInvalidSourceID_ExpectException()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource(typeof(DummyClassForPluginTest), true);

            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                isolated.Value.FetchNamespaceListObjectWithJsonObjects(source);
            }
        }
예제 #10
0
        public void PluginRuntimeHandler_FetchNamespaceListObject_WhenNullLocationAndInvalidSourceID_ExpectException()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource(true);

            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                isolated.Value.FetchNamespaceListObject(source);
            }
        }
예제 #11
0
 public void PluginRuntimeHandler_ListConstructors_WhenInvalidLocation_ExpectNoResults()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         var result = isolated.Value.ListConstructors("z:\foo\asm.dll", "asm.dll", "asm.dll");
         Assert.IsFalse(result.Any());
     }
 }
예제 #12
0
 public void PluginRuntimeHandler_FetchNamespaceListObjectWithJsonObjects_WhenNullDll_ExpectException()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         isolated.Value.FetchNamespaceListObjectWithJsonObjects(null);
         //------------Assert Results-------------------------
     }
 }
예제 #13
0
        public void PluginRuntimeHandler_ValidatePlugin_WhenInvalidGacDll_ExpectErrorMessage()
        {
            //------------Setup for test--------------------------
            var pluginRuntimeHandler = new PluginRuntimeHandler();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var result = isolated.Value.ValidatePlugin("GAC:mscorlib_foo, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
                StringAssert.Contains(result, "Could not load file or assembly 'mscorlib_foo");
            }
        }
예제 #14
0
        public void PluginRuntimeHandler_FetchNamespaceListObject_WhenNullDll_ExpectException()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var result = isolated.Value.FetchNamespaceListObject(null);
                //------------Assert Results-------------------------
            }
        }
예제 #15
0
        public void PluginRuntimeHandler_ListNamespaces_WhenValidLocation_ExpectNamespaces()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource(typeof(DummyClassForPluginTest));

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var result = isolated.Value.ListNamespaces(source.AssemblyLocation, "Foo");
                Assert.IsNotNull(result);
            }
        }
예제 #16
0
 public void PluginRuntimeHandler_ListMethodsWithReturns_WhenValidLocation_ExpectResults()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         var fullName = Assembly.GetExecutingAssembly().Location;
         var dllName  = Path.GetFileName(fullName);
         var result   = isolated.Value.ListMethodsWithReturns(fullName, dllName, typeof(Main).FullName);
         Assert.IsTrue(result.Any());
     }
 }
        public void PluginRuntimeHandler_GetNamespaces_WhenValidDll_ExpectNamespaces()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var result = PluginServiceExecutionFactory.GetNamespaces(source);
                //------------Assert Results-------------------------
                Assert.IsTrue(result.Count > 0);
            }
        }
예제 #18
0
        public void PluginRuntimeHandler_Run_WhenNullLocation_ExpectException()
        {
            //------------Setup for test--------------------------
            var svc = CreatePluginService();

            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                PluginInvokeArgs args = new PluginInvokeArgs {
                    AssemblyLocation = null, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters
                };
                var result = isolated.Value.Run(args);
            }
        }
예제 #19
0
        public void PluginRuntimeHandler_FetchNamespaceListObjectWithJsonObjects_WhenValidDll_ExpectNamespaces()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource(typeof(DummyClassForPluginTest));

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var result = isolated.Value.FetchNamespaceListObjectWithJsonObjects(source);
                //------------Assert Results-------------------------
                Assert.IsTrue(result.Count > 0);
            }
        }
예제 #20
0
        public void PluginRuntimeHandler_GetMethodsWithReturns_WhenValidDll_ExpectValidResults()
        {
            //------------Setup for test--------------------------
            var source  = CreatePluginSource();
            var service = CreatePluginService();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var result = PluginServiceExecutionFactory.GetMethodsWithReturns(source.AssemblyLocation, source.AssemblyName, service.Namespace);
                //------------Assert Results-------------------------
                Assert.IsTrue(result.Count > 0);
            }
        }
예제 #21
0
        public void PluginRuntimeHandler_Run_WhenInvalidMethod_ExpectException()
        {
            //------------Setup for test--------------------------
            var svc    = CreatePluginService();
            var source = CreatePluginSource();

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                PluginInvokeArgs args = new PluginInvokeArgs {
                    AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = "InvalidName", Parameters = svc.Method.Parameters
                };
                var result = isolated.Value.Run(args);
            }
        }
예제 #22
0
 public void PluginRuntimeHandler_ListMethodsWithReturns_WhenListFoods_ExpectJSonArrayReturnType()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
     {
         var fullName = Assembly.GetExecutingAssembly().Location;
         var dllName  = Path.GetFileName(fullName);
         var result   = isolated.Value.ListMethodsWithReturns(fullName, dllName, typeof(Main).FullName);
         Assert.IsTrue(result.Any());
         var serviceMethods = result.Where(method => !method.IsVoid);
         var condition      = serviceMethods.Any(method => method.Dev2ReturnType.Contains("["));
         Assert.IsTrue(condition);
     }
 }
        public void PluginRuntimeHandler_CreateInstance_WhenHumanWithInputs_ExpectHumanStringObjectWithInputs()
        {
            //------------Setup for test--------------------------

            var type = typeof(Human);
            var svc  = CreatePluginService(new List <IDev2MethodInfo> {
                new Dev2MethodInfo {
                    Method = "ToString"
                }
            }, type, new ServiceConstructor());

            //------------Execute Test---------------------------
            using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>())
            {
                var instance = isolated.Value.CreateInstance(new PluginInvokeArgs
                {
                    MethodsToRun      = svc.MethodsToRun,
                    PluginConstructor = new PluginConstructor
                    {
                        ConstructorName = svc.Constructor.Name,
                        Inputs          = new List <IConstructorParameter>()
                        {
                            new ConstructorParameter()
                            {
                                Name         = "name"
                                , Value      = "Jimmy"
                                , TypeName   = typeof(string).AssemblyQualifiedName
                                , IsRequired = true
                            }
                        },
                    },
                    AssemblyLocation = type.Assembly.Location,
                    AssemblyName     = type.Assembly.FullName,
                    Fullname         = type.FullName,
                });

                var deserializeToObject = instance.ObjectString.DeserializeToObject(type, new KnownTypesBinder()
                {
                    KnownTypes = new List <Type>(type.Assembly.ExportedTypes)
                });
                var firstOrDefault = deserializeToObject as Human;
                if (firstOrDefault != null)
                {
                    Assert.AreEqual("Jimmy", firstOrDefault.Name);
                }
                Assert.IsNotNull(deserializeToObject);
            }
        }
        public void PluginRuntimeHandler_Run_WhenObjectStringIsNotNull_ExpectRunsCorrectly()
        {
            //------------Setup for test--------------------------

            var type = typeof(Human);
            var svc  = CreatePluginService(new List <IDev2MethodInfo> {
                new Dev2MethodInfo {
                    Method = "set_Name", Parameters = new List <IMethodParameter>()
                    {
                        new ConstructorParameter()
                        {
                            Name = "value", Value = "Micky", TypeName = typeof(string).FullName, IsRequired = true
                        }
                    }
                }
            }, type, new ServiceConstructor());

            //------------Execute Test---------------------------
            using (var isolated = new Isolated <PluginRuntimeHandler>())
            {
                var pluginInvokeArgs = new PluginInvokeArgs
                {
                    MethodsToRun      = svc.MethodsToRun,
                    PluginConstructor = new PluginConstructor
                    {
                        ConstructorName = svc.Constructor.Name,
                        Inputs          = new List <IConstructorParameter>(),
                    },
                    AssemblyLocation = type.Assembly.Location,
                    AssemblyName     = type.Assembly.FullName,
                    Fullname         = type.FullName,
                };
                var instance = isolated.Value.CreateInstance(pluginInvokeArgs);

                var deserializeToObject = instance.ObjectString.DeserializeToObject(type, new KnownTypesBinder()
                {
                    KnownTypes = new List <Type>(type.Assembly.ExportedTypes)
                });
                Assert.IsNotNull(deserializeToObject);
                instance.Args = pluginInvokeArgs;
                var    dev2MethodInfo = instance.Args.MethodsToRun.First();
                string stringOBj;
                var    run = isolated.Value.Run(dev2MethodInfo, instance, out stringOBj);
                Assert.IsNotNull(run);
                StringAssert.Contains(stringOBj, "Default");
            }
        }