Пример #1
0
 public async Task TestRunVoidScript()
 {
     using (var redirect = new OutputRedirect(CultureInfo.InvariantCulture))
     {
         var state = await CSharpScript.RunAsync("System.Console.WriteLine(0);");
         Assert.Null(state.ReturnValue);
     }
 }
Пример #2
0
 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();
     }
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
 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);
     }
 }