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;", ScriptOptions); 72var s0 = await CSharpScript.RunAsync("using System.Diagnostics;", ScriptOptions); 91CSharpScript.RunAsync("using System;", ScriptOptions). 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", ScriptOptions); 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.AddReferences(portableLibRef), assemblyLoader: loader).RunAsync(); 580var script = CSharpScript.Create<int>( 632var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 690var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 756var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 824var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 892var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 960var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 1028var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 1096var s0 = await CSharpScript.RunAsync($@"#r ""{file1.Path}""", ScriptOptions); 1122var s0 = await CSharpScript.RunAsync("C c;", ScriptOptions.WithReferences(libFile.Path));
Microsoft.CodeAnalysis.CSharp.Scripting.UnitTests (205)
InteractiveSessionReferencesTests.cs (3)
41var s0 = CSharpScript.Create($@" 99var s0 = CSharpScript.Create($@" 138var 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 (90)
39var script = CSharpScript.Create("1 + 2", ScriptOptions); 46Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((string)null)); 52var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")), ScriptOptions); 59Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((Stream)null, ScriptOptions)); 65var state = await CSharpScript.RunAsync("1 + 2", options: ScriptOptions, globals: new ScriptTests()); 73var state = await CSharpScript.RunAsync("1 + 2", options: ScriptOptions, globals: new ScriptTests()); 86var script = CSharpScript.Create("1 + 2", options: ScriptOptions.WithEmitDebugInformation(true)); 110var script = CSharpScript.Create("1 + 2", ScriptOptions); 121var script = CSharpScript.Create<int>("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 132var state = await CSharpScript.RunAsync("1 + 2", ScriptOptions); 139var script = CSharpScript.Create("1 + 2", ScriptOptions); 148var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")), ScriptOptions); 157var value = await CSharpScript.EvaluateAsync("1 + 2", ScriptOptions); 164var state = await CSharpScript.RunAsync("1 + 2", ScriptOptions); 172CSharpScript.Create("System.Console.WriteLine(0);", ScriptOptions), 180var state = await CSharpScript.RunAsync( 189await CSharpScript.RunAsync(@" 204await CSharpScript.RunAsync(@" 223var state = CSharpScript.RunAsync(@"if (true) 241var state = CSharpScript.RunAsync(@"if (true) 249var state = CSharpScript.RunAsync(@"System.Console.WriteLine(true) ", options: ScriptOptions, globals: new ScriptTests()); 256var state = CSharpScript.RunAsync(@" 270var state = CSharpScript.RunAsync(@"if (e) a = b 290var state = await CSharpScript.RunAsync("X + Y", options: ScriptOptions, globals: new Globals { X = 1, Y = 2 }); 297var script = CSharpScript.Create("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 306var script = CSharpScript.Create("X + Y", ScriptOptions); 315var script = CSharpScript.Create("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 324var script = CSharpScript.Create("X + Y", options: ScriptOptions, globalsType: typeof(Globals)); 333var state = await CSharpScript.RunAsync("X + Y", options: ScriptOptions, globals: new Globals()); 341var state1 = await CSharpScript.RunAsync("X + Y + 1", options: ScriptOptions, globals: new Globals()); 342var state2 = await CSharpScript.RunAsync("X + Y + 2", options: ScriptOptions, globals: new Globals()); 351var state = await CSharpScript.RunAsync("int X = 100;", ScriptOptions).ContinueWith("X + X"); 365var state = await CSharpScript.RunAsync("", ScriptOptions); 392CSharpScript.Create( 419var script = CSharpScript.Create("var x = 1;", ScriptOptions); 438var state = await CSharpScript.RunAsync(@" 459var state1 = await CSharpScript.RunAsync("int M(int x) { return x + x; }", ScriptOptions); 475var state0 = await CSharpScript.RunAsync("static int Add(int x, int y) => x + y;", options: ScriptOptions.WithLanguageVersion(LanguageVersion.Preview)); 484var state0 = await CSharpScript.RunAsync("class Id<T> { static T Core(T t) => t; public static System.Func<T, T> Get => Core; }", ScriptOptions); 492var state0 = await CSharpScript.RunAsync("class Id { static T Core<T>(T t) => t; public static System.Func<T, T> Get<T>() => Core; }", ScriptOptions); 501var script = CSharpScript.Create<object>($"return {expected};", ScriptOptions); 510CSharpScript.Create("System.Console.WriteLine();", ScriptOptions), "")); 516var script = CSharpScript.Create<int>("return await System.Threading.Tasks.Task.FromResult(42);", ScriptOptions); 524var script = CSharpScript.Create(@" 537var script = CSharpScript.Create(@" 547script = CSharpScript.Create(@" 561var script = CSharpScript.Create<int>(@" 571script = CSharpScript.Create<int>(@" 585var script = CSharpScript.Create(@" 595script = CSharpScript.Create(@" 609var script = CSharpScript.Create<IEnumerable<int>>(@" 617script = CSharpScript.Create<IEnumerable<int>>(@" 629var script = CSharpScript.Create<int?>(@" 637script = CSharpScript.Create<int?>(@" 653var script = CSharpScript.Create("#load \"a.csx\"", options); 657script = CSharpScript.Create(@" 676var script = CSharpScript.Create("#load \"a.csx\"", options); 680script = CSharpScript.Create(@" 699var script = CSharpScript.Create("#load \"a.csx\"", options); 703script = CSharpScript.Create(@" 719var script = CSharpScript.Create("#load \"b.csx\"", options); 727script = CSharpScript.Create(@" 737script = CSharpScript.Create(@" 754var script = CSharpScript.Create("#load \"b.csx\"", options); 762script = CSharpScript.Create(@" 772script = CSharpScript.Create(@" 792var script = CSharpScript.Create(@" 800script = CSharpScript.Create(@" 814var script = CSharpScript.Create("return;", ScriptOptions); 818script = CSharpScript.Create(@" 838var script = CSharpScript.Create<int>(@" 852var script = await CSharpScript.RunAsync(code, opts); 866return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), line: 1, column: 1, filename: "debug.csx"); 873return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 880return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 888return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), line: 1, column: 1, filename: "debug.csx"); 895return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts)); 903return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), line: 1, column: 1, filename: ""); 911return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), line: 1, column: 1, filename: ""); 918return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 925return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts)); 933return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), line: 1, column: 1, filename: ""); 940return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts)); 948var script = CSharpScript.Create(@"#load ""a.csx""", options); 955var script = CSharpScript.Create(@"string x = default;", ScriptOptions.WithLanguageVersion(LanguageVersion.CSharp7)); 968var script = CSharpScript.Create(@"#nullable enable 991var script = CSharpScript.Create(code, ScriptOptions.WithLanguageVersion(LanguageVersion.CSharp8)); 1007await CSharpScript.RunAsync(@"var data = notExistentVariable switch { _ => null };", options: ScriptOptions, globals: new ScriptTests()); 1029await CSharpScript.RunAsync(@"var data = ""data"" switch { < 5 => null };", options: ScriptOptions, globals: new ScriptTests()); 1054await CSharpScript.RunAsync(@"var data = ""test"" switch { _ => armError };", options: ScriptOptions, 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();