예제 #1
0
        public void PluginRuntimeHandler_Run_WhenNullLocation_ExpectException()
        {
            //------------Setup for test--------------------------
            var svc = CreatePluginService();
            var pluginRuntimeHandler = new PluginRuntimeHandler();
            PluginInvokeArgs args    = new PluginInvokeArgs {
                AssemblyLocation = null, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters
            };

            //------------Execute Test---------------------------
            pluginRuntimeHandler.Run(args);
        }
        public void PluginRuntimeHandler_Run_WhenHasInnerError_ExpectInerErrors()
        {
            //------------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---------------------------
            var      mock = new Mock <IAssemblyLoader>();
            Assembly loadedAssembly;

            var handler = new PluginRuntimeHandler(mock.Object);

            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 pluginExecutionDto = new PluginExecutionDto(String.Empty)
            {
                Args = pluginInvokeArgs
            };
            var exception = new Exception("err", new Exception());

            mock.Setup(loader => loader.TryLoadAssembly(It.IsAny <string>(), It.IsAny <string>(), out loadedAssembly))
            .Throws(exception);

            var    dev2MethodInfo = pluginInvokeArgs.MethodsToRun.First();
            string stringOBj;
            var    run = handler.Run(dev2MethodInfo, pluginExecutionDto, out stringOBj);

            Assert.IsNotNull(run);
            Assert.IsTrue(run.HasError);
            Assert.IsFalse(string.IsNullOrEmpty(run.ErrorMessage));
        }
예제 #3
0
        public void PluginRuntimeHandler_Run_WhenValidLocation_ExpectResult()
        {
            //------------Setup for test--------------------------
            var svc    = CreatePluginService();
            var source = CreatePluginSource();
            var pluginRuntimeHandler = new PluginRuntimeHandler();
            PluginInvokeArgs args    = new PluginInvokeArgs {
                AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters
            };

            //------------Execute Test---------------------------
            var result     = pluginRuntimeHandler.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");
            }
        }