public async Task InvalidScriptCode_ThrowsAnException() { var code = "vat a = 1;"; var runner = new ScriptCodeRunner(code, new Container()); await Assert.ThrowsAsync <CompilationErrorException>(() => runner.RunAsync()); }
public override async void ViewDidLoad() { base.ViewDidLoad(); var runner = new ScriptCodeRunner("var a = 1; var b = 2; var c = a + b;", new Container()); await runner.RunAsync(); }
public async Task CorrectScriptCode_ExecutionSucceed() { var code = "var a = 1; var b = 2; var c = a + b;"; var runner = new ScriptCodeRunner(code, new Container()); await runner.RunAsync(); }
static async Task Main(string[] args) { using var sr = new StreamReader("input.txt"); var script = await sr.ReadToEndAsync(); var scriptRunner = new ScriptCodeRunner <Globals>(script); await scriptRunner.RunAsync(); }
public async Task RunWithNotAllowedFunc_Fail() { var container = new Container(); var code = "var w = new System.IO.StreamWriter(\"a.txt\"); w.WriteLine(\"Hello\"); w.Close();"; var runner = new ScriptCodeRunner(code, container); await Assert.ThrowsAsync <CompilationErrorException>(() => runner.RunAsync()); }
public async Task RunWithGlobalVariables_Succeed() { var container = new Container(); var t = new HelperObject(); container.Register(t, "t"); var code = "t.x++;"; var runner = new ScriptCodeRunner(code, container); await runner.RunAsync(); Assert.Equal(1, t.x); }
public async Task ResolveFromContainer_Succeed() { var cnt = 0; Action f = () => cnt++; var container = new Container(); container.Register(f, "f"); var code = "f();"; var runner = new ScriptCodeRunner(code, container); await runner.RunAsync(); Assert.AreEqual(1, cnt); }
public async Task RunWithFuncFromContainer_Succeed() { var container = new Container(); int x = 0; container.Register <Action>(() => { x++; }, "t"); //container.Register<Console>("api"); var code = "t();"; var runner = new ScriptCodeRunner(code, container); await runner.RunAsync(); Assert.Equal(1, x); }
public async Task Pass() { var runner = new ScriptCodeRunner("var a = 1;", new Container()); await runner.RunAsync(); }