private static IScript CreateScript(string sourceCode, IEnumerable <ISourcePreprocessor> sourcePreprocessors, ITestApi testApi, bool scriptObjectWithInterface) { var scriptPackage = new ScriptPackage("Script0", "TestScript", new StringSourceCode(sourceCode)); var runtime = new CSharpScriptRuntime <TestScriptImplementation>(new TestScriptImplementation(sourcePreprocessors, testApi, scriptObjectWithInterface)) as IScriptRuntime; var runtimeSpace = runtime.CreateSpace("CreativeCoders.TestScripts"); var script = runtimeSpace.Build(scriptPackage); return(script); }
public void Build_IncorrectSyntax_ThrowsException() { var scriptSourceCode = "using CreativeCoders.Scripting.UnitTests.CSharp;" + Env.NewLine + "public void Exe cute() { Api.DoSomething(\"Method executed\"); }"; var testApi = A.Fake <ITestApi>(); var scriptPackage = new ScriptPackage("Script0", "TestScript", new StringSourceCode(scriptSourceCode)); var runtime = new CSharpScriptRuntime <TestScriptImplementation>(new TestScriptImplementation(Array.Empty <ISourcePreprocessor>(), testApi, false)) as IScriptRuntime; var runtimeSpace = runtime.CreateSpace("CreativeCoders.TestScripts"); var exception = Assert.Throws <ScriptCompilationFailedException>(() => runtimeSpace.Build(scriptPackage)); Assert.Same(scriptPackage, exception.ScriptPackage); Assert.NotEmpty(exception.CompilationResultMessages.Where(x => x.MessageType == CompilationMessageType.Error)); }
public ActionScriptCore(CSharpScriptRuntime <ActionScriptImplementation> scriptRuntime) { _scriptRuntime = scriptRuntime; _scriptSpace = CreateScriptSpace(); }