242 references to CSharpScript
InteractiveHost.UnitTests (1)
InteractiveHostCoreInitTests.cs (1)
43var scriptingAssemblyName = typeof(CSharpScript).Assembly.GetName().Name;
Microsoft.CodeAnalysis.CSharp.Scripting (1)
Hosting\CSharpReplServiceProvider.cs (1)
28=> CSharpScript.Create<T>(code, options, globalsTypeOpt, assemblyLoader);
Microsoft.CodeAnalysis.CSharp.Scripting.Desktop.UnitTests (30)
InteractiveSessionReferencesTests.cs (30)
45var s0 = await CSharpScript.RunAsync("", options); 60var s0 = await CSharpScript.RunAsync("using System.Diagnostics;"); 72var s0 = await CSharpScript.RunAsync("using System.Diagnostics;"); 91CSharpScript.RunAsync("using System;"). 123var result = CSharpScript.EvaluateAsync($@" 147ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync(source, options), 167var script = CSharpScript.Create(@" 186var s0 = await CSharpScript.RunAsync<Process>($@" 230var process = CSharpScript.EvaluateAsync<Process>($@" 253var script = CSharpScript.Create($@" 283var script0 = CSharpScript.Create($@" 346var result = CSharpScript.EvaluateAsync($@" 362var result = CSharpScript.Create($@" 382var result = CSharpScript.EvaluateAsync($@" 401var result = CSharpScript.Create($@" 421var script0 = CSharpScript.Create($@" 454var s0 = CSharpScript.RunAsync("var x = new { a = 3 }; x"); 482var script = CSharpScript.Create("new S1()", options); 501var s0 = await CSharpScript.RunAsync<int>("x", options, new C()); 537var s0 = await CSharpScript.Create("new C()", options: ScriptOptions.Default.AddReferences(portableLibRef), assemblyLoader: loader).RunAsync(); 580var script = CSharpScript.Create<int>( 632var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 690var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 756var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 824var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 892var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 960var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 1028var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 1096var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}"""); 1122var s0 = await CSharpScript.RunAsync("C c;", ScriptOptions.Default.WithReferences(libFile.Path));
Microsoft.CodeAnalysis.CSharp.Scripting.UnitTests (205)
InteractiveSessionReferencesTests.cs (3)
40var s0 = CSharpScript.Create($@" 98var s0 = CSharpScript.Create($@" 137var s0 = CSharpScript.Create($@"
InteractiveSessionTests.cs (112)
44var script = CSharpScript.Create(@" 65var script = CSharpScript.Create(@" 86var script = CSharpScript.Create(@" 103var script = CSharpScript.Create(@" 133var script = CSharpScript.Create(@" 153var script = CSharpScript.Create(@" 172var script = CSharpScript.Create(@" 187var script = CSharpScript.Create(@" 217var script = CSharpScript.Create(@" 233var script = CSharpScript.Create(@" 274Type c = CSharpScript.EvaluateAsync<Type>(source).Result; 300var script = CSharpScript.Create<int>(@" 327var script = CSharpScript.Create(@" 363var script = CSharpScript.Create(@" 388var script = CSharpScript.Create( 403var script = CSharpScript.Create("var x = 1;").ContinueWith("x"); 411CSharpScript.Create("using InteractiveFixtures.C;", ScriptOptions.Default.AddReferences(HostAssembly)). 422var s0 = CSharpScript.RunAsync("", ScriptOptions.Default.AddReferences(HostAssembly)); 446var script = CSharpScript.Create(@" 464var state = CSharpScript.RunAsync("Environment.ProcessorCount", options); 475var state1 = CSharpScript.RunAsync("internal class C1 { } protected int X; 1"); 517var state = CSharpScript.RunAsync(""); 531CSharpScript.Create("using System;"). 539CSharpScript.Create("int Environment = 1;"). 551CSharpScript.Create("int System = 1;"). 571CSharpScript.RunAsync("System", globals: new C1()). 581CSharpScript.RunAsync("using System;", globals: new C1()). 592CSharpScript.RunAsync("int System = 2;", globals: new C1()). 602var s0 = CSharpScript.Create("int x = 1;"); 621var s0 = await CSharpScript.RunAsync("int x = 1;"); 648var state0 = await CSharpScript.RunAsync("", globals: new HostObjectWithOverrides()); 663var state0 = await CSharpScript.RunAsync("", globals: new object()); 681var state0 = CSharpScript.RunAsync(""); 715var script = CSharpScript.Create(@" 732CSharpScript.EvaluateAsync(@" 741var s0 = CSharpScript.Create(@" 760var state = CSharpScript.RunAsync(@" 793var state = CSharpScript.RunAsync(@" 828var result = CSharpScript.EvaluateAsync<int>(@" 850Assert.Equal(18, CSharpScript.EvaluateAsync<int>("(4 + 5) * 2").Result); 851Assert.Equal(1, CSharpScript.EvaluateAsync<long>("6 / (2 * 3)").Result); 857var s = CSharpScript.RunAsync(@" 872var f = CSharpScript.EvaluateAsync<Func<int, int>>(@" 888var result = CSharpScript.EvaluateAsync<List<string>>(@" 905var f = CSharpScript.RunAsync("using System;"). 915var s = CSharpScript.RunAsync(@" 931var result = CSharpScript.EvaluateAsync<List<int>>(@" 955var result = CSharpScript.EvaluateAsync<List<int>>(@" 982var result = CSharpScript.RunAsync(@" 1002var result = CSharpScript.EvaluateAsync<int>(@" 1013var result = CSharpScript.EvaluateAsync<object[]>(@" 1036var result1 = await CSharpScript.EvaluateAsync<int[]>("new int[] { 1,2,3,4 }"); 1039var result2 = await CSharpScript.EvaluateAsync<int[]>("new int[] { 1,2,3,4,5 }"); 1042var s1 = await CSharpScript.RunAsync<int[]>("new int[] { 1,2,3,4,5,6 }"); 1056var result = CSharpScript.EvaluateAsync("System.Threading.Tasks.Task.FromResult(1)").Result; 1066Assert.Equal(2, CSharpScript.EvaluateAsync("await System.Threading.Tasks.Task.FromResult(2)").Result); 1075Assert.Equal(3, CSharpScript.EvaluateAsync<int>("0 + await System.Threading.Tasks.Task.FromResult(3)").Result); 1081var task = CSharpScript.EvaluateAsync<object>("await System.Threading.Tasks.Task.Run(() => { })"); 1092var s0 = await CSharpScript.RunAsync(@" 1119CSharpScript.RunAsync("int i = 0;", options). 1137CSharpScript.Create("int i = 0;", options). 1151var state = await CSharpScript.RunAsync("var x = (false, 4);"); 1160var state = await CSharpScript.RunAsync("object x = 1;", options: options); 1174var script = CSharpScript.Create(@" 1222object result = CSharpScript.EvaluateAsync($@" 1241var script = CSharpScript.Create( 1261var script = CSharpScript.Create( 1294var r2 = CSharpScript.Create($@"#r ""{fileMain.Path}""").ContinueWith($@"M.X.F").RunAsync().Result.ReturnValue; 1325var r2 = CSharpScript.Create($@"#r ""{fileMain.Path}""").ContinueWith($@"M.X.F").RunAsync().Result.ReturnValue; 1340var script = CSharpScript.Create(@"new C()", 1353object result = CSharpScript.EvaluateAsync(@" 1369object result = CSharpScript.EvaluateAsync("new int[] { 1, 2, 3 }.First()", options).Result; 1380var s1 = CSharpScript.RunAsync("new int[] { 1, 2, 3 }.First()", options); 1393ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1401ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1407ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1413ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1429Assert.Equal(2, CSharpScript.EvaluateAsync<int>("1+1").Result); 1431Assert.Null(CSharpScript.EvaluateAsync<string>("null").Result); 1435CSharpScript.RunAsync<C<int>>("null"); 1447var cint = CSharpScript.EvaluateAsync<C<int>>("null", options).Result; 1450Assert.Null(CSharpScript.EvaluateAsync<int?>("null", options).Result); 1454CSharpScript.RunAsync<int>("null"); 1467CSharpScript.RunAsync<string>("1+1"); 1482var value = CSharpScript.EvaluateAsync<IEnumerable<Exception>>(@" 1530var s0 = CSharpScript.RunAsync<int>("x + Y + Z()", globals: c); 1546var result = CSharpScript.EvaluateAsync<string>("G()", globals: m); 1555var s0 = await CSharpScript.RunAsync<int>("Z()", globals: c, globalsType: typeof(I)); 1572ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("Z()", globals: c), 1582ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("Z()", globals: c), 1591var result = CSharpScript.EvaluateAsync<int>("Z()", globals: c, globalsType: typeof(I)); 1598var s0 = CSharpScript.RunAsync("static int goo = StaticField;", globals: new C()); 1617var s0 = CSharpScript.RunAsync("int goo(double a) { return 2; }", globals: new D()); 1629var r0 = CSharpScript.EvaluateAsync<int>("X + Y + Z", globals: obj); 1633var r1 = CSharpScript.EvaluateAsync<int>("X", globals: obj); 1640var scriptCompilation = CSharpScript.Create( 1697var scriptCompilation = CSharpScript.Create( 1701WithReferences(typeof(CSharpScript).GetTypeInfo().Assembly), 1762#r ""{typeof(CSharpScript).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName}"" 1765var scriptCompilation = CSharpScript.Create( 1843var result = await CSharpScript.EvaluateAsync<bool>(code, globalsType: typeof(E), globals: new E()); 1863var script = CSharpScript.Create<bool>(code, globalsType: typeof(F)); 1885var script = CSharpScript.Create<bool>(code, globalsType: typeof(F)); 1907var result = await CSharpScript.EvaluateAsync<bool>(code, globalsType: typeof(F), globals: new F()); 1919var s0 = CSharpScript.Create(@" 1942var s0 = CSharpScript.Create(@" 1969var s0 = CSharpScript.Create(@" 1997var state0 = await CSharpScript.RunAsync(@" 2030var s0 = CSharpScript.Create(@" 2064var s0 = CSharpScript.Create(@" 2098var s0 = CSharpScript.Create(@" 2127CSharpScript.RunAsync(
ScriptTests.cs (90)
36var script = CSharpScript.Create("1 + 2"); 43Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((string)null)); 49var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2"))); 56Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((Stream)null)); 62var state = await CSharpScript.RunAsync("1 + 2", globals: new ScriptTests()); 70var state = await CSharpScript.RunAsync("1 + 2", globals: new ScriptTests()); 83var script = CSharpScript.Create("1 + 2", options: ScriptOptions.Default.WithEmitDebugInformation(true)); 107var script = CSharpScript.Create("1 + 2"); 118var script = CSharpScript.Create<int>("X + Y", globalsType: typeof(Globals)); 129var state = await CSharpScript.RunAsync("1 + 2"); 136var script = CSharpScript.Create("1 + 2"); 145var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2"))); 154var value = await CSharpScript.EvaluateAsync("1 + 2"); 161var state = await CSharpScript.RunAsync("1 + 2"); 169CSharpScript.Create("System.Console.WriteLine(0);"), 177var state = await CSharpScript.RunAsync( 186await CSharpScript.RunAsync(@" 201await CSharpScript.RunAsync(@" 220var state = CSharpScript.RunAsync(@"if (true) 238var state = CSharpScript.RunAsync(@"if (true) 246var state = CSharpScript.RunAsync(@"System.Console.WriteLine(true) ", globals: new ScriptTests()); 253var state = CSharpScript.RunAsync(@" 267var state = CSharpScript.RunAsync(@"if (e) a = b 287var state = await CSharpScript.RunAsync("X + Y", globals: new Globals { X = 1, Y = 2 }); 294var script = CSharpScript.Create("X + Y", globalsType: typeof(Globals)); 303var script = CSharpScript.Create("X + Y"); 312var script = CSharpScript.Create("X + Y", globalsType: typeof(Globals)); 321var script = CSharpScript.Create("X + Y", globalsType: typeof(Globals)); 330var state = await CSharpScript.RunAsync("X + Y", globals: new Globals()); 338var state1 = await CSharpScript.RunAsync("X + Y + 1", globals: new Globals()); 339var state2 = await CSharpScript.RunAsync("X + Y + 2", globals: new Globals()); 348var state = await CSharpScript.RunAsync("int X = 100;").ContinueWith("X + X"); 362var state = await CSharpScript.RunAsync(""); 389CSharpScript.Create( 415var script = CSharpScript.Create("var x = 1;"); 434var state = await CSharpScript.RunAsync(@" 455var state1 = await CSharpScript.RunAsync("int M(int x) { return x + x; }"); 471var state0 = await CSharpScript.RunAsync("static int Add(int x, int y) => x + y;", options: ScriptOptions.Default.WithLanguageVersion(LanguageVersion.Preview)); 480var state0 = await CSharpScript.RunAsync("class Id<T> { static T Core(T t) => t; public static System.Func<T, T> Get => Core; }"); 488var state0 = await CSharpScript.RunAsync("class Id { static T Core<T>(T t) => t; public static System.Func<T, T> Get<T>() => Core; }"); 497var script = CSharpScript.Create<object>($"return {expected};"); 506CSharpScript.Create("System.Console.WriteLine();"), "")); 512var script = CSharpScript.Create<int>("return await System.Threading.Tasks.Task.FromResult(42);"); 520var script = CSharpScript.Create(@" 533var script = CSharpScript.Create(@" 543script = CSharpScript.Create(@" 557var script = CSharpScript.Create<int>(@" 567script = CSharpScript.Create<int>(@" 581var script = CSharpScript.Create(@" 591script = CSharpScript.Create(@" 605var script = CSharpScript.Create<IEnumerable<int>>(@" 613script = CSharpScript.Create<IEnumerable<int>>(@" 625var script = CSharpScript.Create<int?>(@" 633script = CSharpScript.Create<int?>(@" 649var script = CSharpScript.Create("#load \"a.csx\"", options); 653script = CSharpScript.Create(@" 672var script = CSharpScript.Create("#load \"a.csx\"", options); 676script = CSharpScript.Create(@" 695var script = CSharpScript.Create("#load \"a.csx\"", options); 699script = CSharpScript.Create(@" 715var script = CSharpScript.Create("#load \"b.csx\"", options); 723script = CSharpScript.Create(@" 733script = CSharpScript.Create(@" 750var script = CSharpScript.Create("#load \"b.csx\"", options); 758script = CSharpScript.Create(@" 768script = CSharpScript.Create(@" 788var script = CSharpScript.Create(@" 796script = CSharpScript.Create(@" 810var script = CSharpScript.Create("return;"); 814script = CSharpScript.Create(@" 834var script = CSharpScript.Create<int>(@" 848var script = await CSharpScript.RunAsync(code, opts); 862return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), line: 1, column: 1, filename: "debug.csx"); 869return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 876return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 884return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), line: 1, column: 1, filename: "debug.csx"); 891return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts)); 899return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), line: 1, column: 1, filename: ""); 907return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), line: 1, column: 1, filename: ""); 914return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 921return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 929return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), line: 1, column: 1, filename: ""); 936return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts)); 944var script = CSharpScript.Create(@"#load ""a.csx""", options); 951var script = CSharpScript.Create(@"string x = default;", ScriptOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7)); 964var script = CSharpScript.Create(@"#nullable enable 987var script = CSharpScript.Create(code, ScriptOptions.Default.WithLanguageVersion(LanguageVersion.CSharp8)); 1003await CSharpScript.RunAsync(@"var data = notExistentVariable switch { _ => null };", globals: new ScriptTests()); 1025await CSharpScript.RunAsync(@"var data = ""data"" switch { < 5 => null };", globals: new ScriptTests()); 1050await CSharpScript.RunAsync(@"var data = ""test"" switch { _ => armError };", globals: new ScriptTests());
Microsoft.CodeAnalysis.Scripting.UnitTests (5)
ScriptOptionsTests.cs (5)
163var compilation = CSharpScript.Create(string.Empty, scriptOptions).GetCompilation(); 219var compilation = (CSharpCompilation)CSharpScript.Create(string.Empty, scriptOptions).GetCompilation(); 246var compilation = CSharpScript.Create(string.Empty, scriptOptions).GetCompilation(); 274var compilation = CSharpScript.Create(string.Empty, scriptOptions).GetCompilation(); 311var compilation = CSharpScript.Create(string.Empty, scriptOptions).GetCompilation();