244 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)
27=> CSharpScript.Create<T>(code, options, globalsTypeOpt, assemblyLoader);
Microsoft.CodeAnalysis.CSharp.Scripting.Desktop.UnitTests (30)
InteractiveSessionReferencesTests.cs (30)
43var s0 = await CSharpScript.RunAsync("", options); 58var s0 = await CSharpScript.RunAsync("using System.Diagnostics;", ScriptOptions); 70var s0 = await CSharpScript.RunAsync("using System.Diagnostics;", ScriptOptions); 89CSharpScript.RunAsync("using System;", ScriptOptions). 121var result = CSharpScript.EvaluateAsync($@" 145ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync(source, options), 165var script = CSharpScript.Create(@" 184var s0 = await CSharpScript.RunAsync<Process>($@" 228var process = CSharpScript.EvaluateAsync<Process>($@" 251var script = CSharpScript.Create($@" 281var script0 = CSharpScript.Create($@" 344var result = CSharpScript.EvaluateAsync($@" 360var result = CSharpScript.Create($@" 380var result = CSharpScript.EvaluateAsync($@" 399var result = CSharpScript.Create($@" 419var script0 = CSharpScript.Create($@" 452var s0 = CSharpScript.RunAsync("var x = new { a = 3 }; x", ScriptOptions); 480var script = CSharpScript.Create("new S1()", options); 499var s0 = await CSharpScript.RunAsync<int>("x", options, new C()); 535var s0 = await CSharpScript.Create("new C()", options: ScriptOptions.AddReferences(portableLibRef), assemblyLoader: loader).RunAsync(); 578var script = CSharpScript.Create<int>( 630var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 688var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 754var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 822var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 890var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 958var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 1026var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 1094var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 1120var s0 = await CSharpScript.RunAsync("C c;", ScriptOptions.WithReferences(libFile.Path));
Microsoft.CodeAnalysis.CSharp.Scripting.UnitTests (207)
InteractiveSessionReferencesTests.cs (3)
39var s0 = CSharpScript.Create($@" 97var s0 = CSharpScript.Create($@" 136var s0 = CSharpScript.Create($@"
InteractiveSessionTests.cs (112)
45var script = CSharpScript.Create(@" 66var script = CSharpScript.Create(@" 87var script = CSharpScript.Create(@" 104var script = CSharpScript.Create(@" 134var script = CSharpScript.Create(@" 154var script = CSharpScript.Create(@" 173var script = CSharpScript.Create(@" 188var script = CSharpScript.Create(@" 218var script = CSharpScript.Create(@" 234var script = CSharpScript.Create(@" 275Type c = CSharpScript.EvaluateAsync<Type>(source, ScriptOptions).Result; 301var script = CSharpScript.Create<int>(@" 328var script = CSharpScript.Create(@" 364var script = CSharpScript.Create(@" 389var script = CSharpScript.Create( 404var script = CSharpScript.Create("var x = 1;", ScriptOptions).ContinueWith("x"); 412CSharpScript.Create("using InteractiveFixtures.C;", ScriptOptions.AddReferences(HostAssembly)). 423var s0 = CSharpScript.RunAsync("", ScriptOptions.AddReferences(HostAssembly)); 447var script = CSharpScript.Create(@" 465var state = CSharpScript.RunAsync("Environment.ProcessorCount", options); 476var state1 = CSharpScript.RunAsync("internal class C1 { } protected int X; 1", ScriptOptions); 518var state = CSharpScript.RunAsync("", ScriptOptions); 532CSharpScript.Create("using System;", ScriptOptions). 540CSharpScript.Create("int Environment = 1;", ScriptOptions). 552CSharpScript.Create("int System = 1;", ScriptOptions). 572CSharpScript.RunAsync("System", options: ScriptOptions, globals: new C1()). 582CSharpScript.RunAsync("using System;", options: ScriptOptions, globals: new C1()). 593CSharpScript.RunAsync("int System = 2;", options: ScriptOptions, globals: new C1()). 603var s0 = CSharpScript.Create("int x = 1;", ScriptOptions); 622var s0 = await CSharpScript.RunAsync("int x = 1;", ScriptOptions); 649var state0 = await CSharpScript.RunAsync("", options: ScriptOptions, globals: new HostObjectWithOverrides()); 664var state0 = await CSharpScript.RunAsync("", options: ScriptOptions, globals: new object()); 682var state0 = CSharpScript.RunAsync("", ScriptOptions); 716var script = CSharpScript.Create(@" 733CSharpScript.EvaluateAsync(@" 742var s0 = CSharpScript.Create(@" 761var state = CSharpScript.RunAsync(@" 794var state = CSharpScript.RunAsync(@" 829var result = CSharpScript.EvaluateAsync<int>(@" 851Assert.Equal(18, CSharpScript.EvaluateAsync<int>("(4 + 5) * 2", ScriptOptions).Result); 852Assert.Equal(1, CSharpScript.EvaluateAsync<long>("6 / (2 * 3)", ScriptOptions).Result); 858var s = CSharpScript.RunAsync(@" 873var f = CSharpScript.EvaluateAsync<Func<int, int>>(@" 889var result = CSharpScript.EvaluateAsync<List<string>>(@" 906var f = CSharpScript.RunAsync("using System;", ScriptOptions). 916var s = CSharpScript.RunAsync(@" 932var result = CSharpScript.EvaluateAsync<List<int>>(@" 956var result = CSharpScript.EvaluateAsync<List<int>>(@" 983var result = CSharpScript.RunAsync(@" 1003var result = CSharpScript.EvaluateAsync<int>(@" 1014var result = CSharpScript.EvaluateAsync<object[]>(@" 1037var result1 = await CSharpScript.EvaluateAsync<int[]>("new int[] { 1,2,3,4 }", ScriptOptions); 1040var result2 = await CSharpScript.EvaluateAsync<int[]>("new int[] { 1,2,3,4,5 }", ScriptOptions); 1043var s1 = await CSharpScript.RunAsync<int[]>("new int[] { 1,2,3,4,5,6 }", ScriptOptions); 1057var result = CSharpScript.EvaluateAsync("System.Threading.Tasks.Task.FromResult(1)", ScriptOptions).Result; 1067Assert.Equal(2, CSharpScript.EvaluateAsync("await System.Threading.Tasks.Task.FromResult(2)", ScriptOptions).Result); 1076Assert.Equal(3, CSharpScript.EvaluateAsync<int>("0 + await System.Threading.Tasks.Task.FromResult(3)", ScriptOptions).Result); 1082var task = CSharpScript.EvaluateAsync<object>("await System.Threading.Tasks.Task.Run(() => { })", ScriptOptions); 1093var s0 = await CSharpScript.RunAsync(@" 1120CSharpScript.RunAsync("int i = 0;", options). 1138CSharpScript.Create("int i = 0;", options). 1152var state = await CSharpScript.RunAsync("var x = (false, 4);", ScriptOptions); 1161var state = await CSharpScript.RunAsync("object x = 1;", options: options); 1175var script = CSharpScript.Create(@" 1223object result = CSharpScript.EvaluateAsync($@" 1242var script = CSharpScript.Create( 1262var script = CSharpScript.Create( 1295var r2 = CSharpScript.Create($@"#r ""{fileMain.Path}""", ScriptOptions).ContinueWith($@"M.X.F").RunAsync().Result.ReturnValue; 1326var r2 = CSharpScript.Create($@"#r ""{fileMain.Path}""", ScriptOptions).ContinueWith($@"M.X.F").RunAsync().Result.ReturnValue; 1341var script = CSharpScript.Create(@"new C()", 1354object result = CSharpScript.EvaluateAsync(@" 1370object result = CSharpScript.EvaluateAsync("new int[] { 1, 2, 3 }.First()", options).Result; 1381var s1 = CSharpScript.RunAsync("new int[] { 1, 2, 3 }.First()", options); 1394ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1402ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1408ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1414ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1430Assert.Equal(2, CSharpScript.EvaluateAsync<int>("1+1", ScriptOptions).Result); 1432Assert.Null(CSharpScript.EvaluateAsync<string>("null", ScriptOptions).Result); 1436CSharpScript.RunAsync<C<int>>("null", ScriptOptions); 1448var cint = CSharpScript.EvaluateAsync<C<int>>("null", options).Result; 1451Assert.Null(CSharpScript.EvaluateAsync<int?>("null", options).Result); 1455CSharpScript.RunAsync<int>("null", ScriptOptions); 1468CSharpScript.RunAsync<string>("1+1", ScriptOptions); 1483var value = CSharpScript.EvaluateAsync<IEnumerable<Exception>>(@" 1531var s0 = CSharpScript.RunAsync<int>("x + Y + Z()", options: ScriptOptions, globals: c); 1547var result = CSharpScript.EvaluateAsync<string>("G()", options: ScriptOptions, globals: m); 1556var s0 = await CSharpScript.RunAsync<int>("Z()", options: ScriptOptions, globals: c, globalsType: typeof(I)); 1573ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("Z()", options: ScriptOptions, globals: c), 1583ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("Z()", options: ScriptOptions, globals: c), 1592var result = CSharpScript.EvaluateAsync<int>("Z()", options: ScriptOptions, globals: c, globalsType: typeof(I)); 1599var s0 = CSharpScript.RunAsync("static int goo = StaticField;", options: ScriptOptions, globals: new C()); 1618var s0 = CSharpScript.RunAsync("int goo(double a) { return 2; }", options: ScriptOptions, globals: new D()); 1630var r0 = CSharpScript.EvaluateAsync<int>("X + Y + Z", options: ScriptOptions, globals: obj); 1634var r1 = CSharpScript.EvaluateAsync<int>("X", options: ScriptOptions, globals: obj); 1641var scriptCompilation = CSharpScript.Create( 1698var scriptCompilation = CSharpScript.Create( 1702WithReferences(typeof(CSharpScript).GetTypeInfo().Assembly), 1763#r ""{typeof(CSharpScript).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName}"" 1766var scriptCompilation = CSharpScript.Create( 1844var result = await CSharpScript.EvaluateAsync<bool>(code, options: ScriptOptions, globalsType: typeof(E), globals: new E()); 1864var script = CSharpScript.Create<bool>(code, options: ScriptOptions, globalsType: typeof(F)); 1886var script = CSharpScript.Create<bool>(code, options: ScriptOptions, globalsType: typeof(F)); 1908var result = await CSharpScript.EvaluateAsync<bool>(code, options: ScriptOptions, globalsType: typeof(F), globals: new F()); 1920var s0 = CSharpScript.Create(@" 1943var s0 = CSharpScript.Create(@" 1970var s0 = CSharpScript.Create(@" 1998var state0 = await CSharpScript.RunAsync(@" 2031var s0 = CSharpScript.Create(@" 2065var s0 = CSharpScript.Create(@" 2099var s0 = CSharpScript.Create(@" 2128CSharpScript.RunAsync(
ScriptTests.cs (92)
35var script = CSharpScript.Create("1 + 2", ScriptOptions); 42Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((string)null)); 48var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")), ScriptOptions); 55Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((Stream)null, ScriptOptions)); 61var state = await CSharpScript.RunAsync("1 + 2", options: ScriptOptions, globals: new ScriptTests()); 69var state = await CSharpScript.RunAsync("1 + 2", options: ScriptOptions, globals: new ScriptTests()); 82var script = CSharpScript.Create("1 + 2", options: ScriptOptions.WithEmitDebugInformation(true)); 106var script = CSharpScript.Create("1 + 2", ScriptOptions); 117var script = CSharpScript.Create<int>("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 128var state = await CSharpScript.RunAsync("1 + 2", ScriptOptions); 135var script = CSharpScript.Create("1 + 2", ScriptOptions); 144var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")), ScriptOptions); 153var value = await CSharpScript.EvaluateAsync("1 + 2", ScriptOptions); 160var state = await CSharpScript.RunAsync("1 + 2", ScriptOptions); 168CSharpScript.Create("System.Console.WriteLine(0);", ScriptOptions), 176var state = await CSharpScript.RunAsync( 185await CSharpScript.RunAsync(@" 200await CSharpScript.RunAsync(@" 219var state = CSharpScript.RunAsync(@"if (true) 237var state = CSharpScript.RunAsync(@"if (true) 245var state = CSharpScript.RunAsync(@"System.Console.WriteLine(true) ", options: ScriptOptions, globals: new ScriptTests()); 252var state = CSharpScript.RunAsync(@" 266var state = CSharpScript.RunAsync(@"if (e) a = b 286var state = await CSharpScript.RunAsync("X + Y", options: ScriptOptions, globals: new Globals { X = 1, Y = 2 }); 293var script = CSharpScript.Create("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 302var script = CSharpScript.Create("X + Y", ScriptOptions); 311var script = CSharpScript.Create("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 320var script = CSharpScript.Create("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 329var state = await CSharpScript.RunAsync("X + Y", options: ScriptOptions, globals: new Globals()); 337var state1 = await CSharpScript.RunAsync("X + Y + 1", options: ScriptOptions, globals: new Globals()); 338var state2 = await CSharpScript.RunAsync("X + Y + 2", options: ScriptOptions, globals: new Globals()); 347var state = await CSharpScript.RunAsync("int X = 100;", ScriptOptions).ContinueWith("X + X"); 361var state = await CSharpScript.RunAsync("", ScriptOptions); 388CSharpScript.Create( 415var script = CSharpScript.Create("var x = 1;", ScriptOptions); 434var state = await CSharpScript.RunAsync(@" 455var state1 = await CSharpScript.RunAsync("int M(int x) { return x + x; }", ScriptOptions); 471var state0 = await CSharpScript.RunAsync("static int Add(int x, int y) => x + y;", options: ScriptOptions.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; }", ScriptOptions); 488var state0 = await CSharpScript.RunAsync("class Id { static T Core<T>(T t) => t; public static System.Func<T, T> Get<T>() => Core; }", ScriptOptions); 497var script = CSharpScript.Create<object>($"return {expected};", ScriptOptions); 506CSharpScript.Create("System.Console.WriteLine();", ScriptOptions), "")); 512var script = CSharpScript.Create<int>("return await System.Threading.Tasks.Task.FromResult(42);", ScriptOptions); 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;", ScriptOptions); 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.WithLanguageVersion(LanguageVersion.CSharp7)); 964var script = CSharpScript.Create(@"#nullable enable 987var script = CSharpScript.Create(code, ScriptOptions.WithLanguageVersion(LanguageVersion.CSharp8)); 1003await CSharpScript.RunAsync(@"var data = notExistentVariable switch { _ => null };", options: ScriptOptions, globals: new ScriptTests()); 1025await CSharpScript.RunAsync(@"var data = ""data"" switch { < 5 => null };", options: ScriptOptions, globals: new ScriptTests()); 1050await CSharpScript.RunAsync(@"var data = ""test"" switch { _ => armError };", options: ScriptOptions, globals: new ScriptTests()); 1069var script = CSharpScript.Create("class partial;", ScriptOptions.WithLanguageVersion(LanguageVersion.Preview)) 1089var script = CSharpScript.Create("class partial;", ScriptOptions.WithLanguageVersion(LanguageVersion.CSharp13))
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();