예제 #1
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(TinyXdto.XdtoFactory)));
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(OneScript.Soap.Definitions)));

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

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

            var testRunner = new UserScriptContextInstance(testrunnerModule);

            testRunner.AddProperty("ЭтотОбъект", "ThisObject", testRunner);
            testRunner.InitOwnData();
            testRunner.Initialize();

            TestRunner = ValueFactory.Create(testRunner);

            var testRootDir = ValueFactory.Create(TestContext.CurrentContext.TestDirectory);

            engine.InjectGlobalProperty("TestDataDirectory", testRootDir, readOnly: true);
            engine.InjectGlobalProperty("КаталогТестовыхДанных", testRootDir, readOnly: true);

            return(engine);
        }
예제 #2
0
        public ScriptDrivenObject CreateUninitializedSDO(LoadedModule module, ExternalContextData externalContext = null)
        {
            var scriptContext = new UserScriptContextInstance(module);

            scriptContext.AddProperty("ЭтотОбъект", "ThisObject", scriptContext);
            if (externalContext != null)
            {
                foreach (var item in externalContext)
                {
                    scriptContext.AddProperty(item.Key, item.Value);
                }
            }

            scriptContext.InitOwnData();
            return(scriptContext);
        }
예제 #3
0
        public void RunTestScript(string resourceName)
        {
            var source   = LoadFromAssemblyResource(resourceName);
            var byteCode = engine.GetCompilerService().Compile(source);
            var module   = engine.EngineInstance.LoadModuleImage(byteCode);

            var test = new UserScriptContextInstance(module);

            test.AddProperty("ЭтотОбъект", "ThisObject", test);
            test.InitOwnData();
            test.Initialize();

            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 [] { });
            }
        }