public async Task TestRunVoidScript() { using (var redirect = new OutputRedirect(CultureInfo.InvariantCulture)) { var state = await CSharpScript.RunAsync("System.Console.WriteLine(0);"); Assert.Null(state.ReturnValue); } }
public async Task StreamWithOffset() { var resolver = new StreamOffsetResolver(); var options = ScriptOptions.Default.WithSourceResolver(resolver); var script = CSharpScript.Create(@"#load ""a.csx""", options); using (var redirect = new OutputRedirect(CultureInfo.InvariantCulture)) { await script.EvaluateAsync(); } }
public async Task ReturnInNestedScopeWithTrailingVoidExpressionAsInt() { var script = CSharpScript.Create<int>(@" bool condition = false; if (condition) { return 1; } System.Console.WriteLine();"); var result = await script.EvaluateAsync(); Assert.Equal(0, result); script = CSharpScript.Create<int>(@" bool condition = false; if (condition) { return 1; } System.Console.WriteLine()"); using (var redirect = new OutputRedirect(CultureInfo.InvariantCulture)) { result = await script.EvaluateAsync(); Assert.Equal(0, result); } }
public async Task ReturnInLoadedFileTrailingVoidExpression() { using (var redirect = new OutputRedirect(CultureInfo.InvariantCulture)) { var resolver = TestSourceReferenceResolver.Create( KeyValuePair.Create("a.csx", @" if (false) { return 1; } System.Console.WriteLine(42)")); var options = ScriptOptions.Default.WithSourceResolver(resolver); var script = CSharpScript.Create("#load \"a.csx\"", options); var result = await script.EvaluateAsync(); Assert.Null(result); script = CSharpScript.Create(@" #load ""a.csx"" 2", options); result = await script.EvaluateAsync(); Assert.Equal(2, result); } }
public async Task NoReturn() { using (var redirect = new OutputRedirect(CultureInfo.InvariantCulture)) { var script = CSharpScript.Create<object>("System.Console.WriteLine();"); var result = await script.EvaluateAsync(); Assert.Null(result); } }