Ejemplo n.º 1
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            // Тут можно указать любой класс из компоненты
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(Bracker.BrackerWriterImpl)));

            // Если проектов компонент несколько, то надо взять по классу из каждой из них
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_2.MyClass_2)));
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_3.MyClass_3)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().CreateModule(testrunnerSource);

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Module = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
Ejemplo n.º 2
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            // Тут можно указать любой класс из компоненты
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptFtp.FtpConnection)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().CreateModule(testrunnerSource);

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Module = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
Ejemplo n.º 3
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();


            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(OMyGodEco)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService()
                                   .Compile(testrunnerSource);

            {
                var mi = engine.GetType().GetMethod("SetGlobalEnvironment",
                                                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
                mi.Invoke(engine, new object[] { this, testrunnerSource });
            }

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
        public void RunTestScript(string resourceName)
        {
            var source        = LoadFromAssemblyResource(resourceName);
            var bytecodeImage = engine.GetCompilerService().Compile(source);

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = bytecodeImage,
                Symbol = resourceName
            });

            var       test = AttachedScriptsFactory.ScriptFactory(resourceName, new IValue[] { });
            ArrayImpl testArray;

            {
                int methodIndex = test.FindMethod("ПолучитьСписокТестов");

                {
                    IValue ivTests;
                    test.CallAsFunction(methodIndex, new IValue[] { TestRunner }, out ivTests);
                    testArray = ivTests as ArrayImpl;
                }
            }

            foreach (var ivTestName in testArray)
            {
                string testName    = ivTestName.AsString();
                int    methodIndex = test.FindMethod(testName);
                if (methodIndex == -1)
                {
                    // Тест указан, но процедуры нет или она не экспортирована
                    continue;
                }

                test.CallAsProcedure(methodIndex, new IValue[] { });
            }
        }
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            // Тут можно указать любой класс из компоненты
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent.MyClass)));

            // Если проектов компонент несколько, то надо взять по классу из каждой из них
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_2.MyClass_2)));
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_3.MyClass_3)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().Compile(testrunnerSource);

            {
                var mi = engine.GetType().GetMethod("SetGlobalEnvironment",
                                                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
                mi.Invoke(engine, new object[] { this, testrunnerSource });
            }

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }