void CheckConsistency() { if (m_scope == null) { InitScope(); } if (script.updateCount != scriptUpdateCount || !scopeInitializedWithScript) { script.Execute(m_scope); InitMethod("Update", ref update); InitMethod("Awake", ref awake); InitMethod("Start", ref start); InitMethod("OnEnable", ref onEnable); InitMethod("OnDisable", ref onDisable); InitMethod("OnDestroy", ref onDestroy); InitMethod("OnCollisionEnter", ref onCollisionEnter); InitMethod("OnCollisionStay", ref onCollisionStay); InitMethod("OnCollisionExit", ref onCollisionExit); scriptUpdateCount = script.updateCount; scopeInitializedWithScript = true; CallOnScopeUpdated(); } }
public void TypeConversion() { Mock <IConfigurationSection> typeconfig = new Mock <IConfigurationSection>(); typeconfig.SetupGet(s => s.Key).Returns("NamedCode"); typeconfig.SetupGet(s => s.Value).Returns("ScriptService.Dto.NamedCode,ScriptService"); Mock <IConfigurationSection> typesconfig = new Mock <IConfigurationSection>(); typesconfig.Setup(s => s.GetChildren()).Returns(new[] { typeconfig.Object }); Mock <IConfiguration> config = new Mock <IConfiguration>(); config.Setup(s => s.GetSection("Types")).Returns(typesconfig.Object); TypeCreator creator = new TypeCreator(new NullLogger <TypeCreator>(), config.Object); PythonService pythonservice = new PythonService(new Mock <IScriptImportService>().Object, creator); PythonScript script = new PythonScript(pythonservice, "import NamedCode\ncode=NamedCode()\ncode.Name='Test'\ntest.TestMethod(code)"); Assert.AreEqual("Test", script.Execute(new Dictionary <string, object> { ["log"] = new WorkableLogger(new NullLogger <JavascriptTests>(), null), ["test"] = this })); }
public void CallNCScript() { ScriptParser parser = new ScriptParser(); parser.Types.AddType <Script>(); IScript ncscript = parser.Parse("parameter($data, script) return($data.name)"); Mock <IScriptCompiler> scriptcompiler = new Mock <IScriptCompiler>(); scriptcompiler.Setup(s => s.CompileScriptAsync(It.IsAny <string>(), It.IsAny <int?>())).ReturnsAsync(new CompiledScript { Instance = ncscript }); Mock <IScriptImportService> importservice = new Mock <IScriptImportService>(); importservice.Setup(s => s.Script(It.IsAny <string>(), It.IsAny <int?>())).Returns(new ScriptExecutor(new WorkableLogger(new NullLogger <JavascriptTests>(), null), scriptcompiler.Object, "Test", 1)); importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object); PythonService pythonservice = new PythonService(importservice.Object, null); PythonScript script = new PythonScript(pythonservice, "script=load.Script('Test', None)\nscript.Execute({'data':{'Name':'Test'}})"); Assert.AreEqual("Test", script.Execute(new Dictionary <string, object> { ["log"] = null })); }
public void ReturnConstant() { PythonService pythonservice = new PythonService(new Mock <IScriptImportService>().Object, null); PythonScript script = new PythonScript(pythonservice, "7"); Assert.AreEqual(7, script.Execute(new Dictionary <string, object> { ["test"] = this })); }
public void AwaitTask() { PythonService pythonservice = new PythonService(new Mock <IScriptImportService>().Object, null); PythonScript script = new PythonScript(pythonservice, "await(test.TestTask())"); Assert.AreEqual("test", script.Execute(new Dictionary <string, object> { ["test"] = this })); }
public void IntCall() { PythonService pythonservice = new PythonService(new Mock <IScriptImportService>().Object, null); PythonScript script = new PythonScript(pythonservice, "test.TestNumber(7)"); Assert.AreEqual(7, script.Execute(new Dictionary <string, object> { ["test"] = this })); }