244 references to CSharpScript
InteractiveHost.UnitTests (1)
InteractiveHostCoreInitTests.cs (1)
44var 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); 519var state = CSharpScript.RunAsync("", ScriptOptions); 533CSharpScript.Create("using System;", ScriptOptions). 541CSharpScript.Create("int Environment = 1;", ScriptOptions). 553CSharpScript.Create("int System = 1;", ScriptOptions). 573CSharpScript.RunAsync("System", options: ScriptOptions, globals: new C1()). 583CSharpScript.RunAsync("using System;", options: ScriptOptions, globals: new C1()). 594CSharpScript.RunAsync("int System = 2;", options: ScriptOptions, globals: new C1()). 604var s0 = CSharpScript.Create("int x = 1;", ScriptOptions); 623var s0 = await CSharpScript.RunAsync("int x = 1;", ScriptOptions); 650var state0 = await CSharpScript.RunAsync("", options: ScriptOptions, globals: new HostObjectWithOverrides()); 665var state0 = await CSharpScript.RunAsync("", options: ScriptOptions, globals: new object()); 683var state0 = CSharpScript.RunAsync("", ScriptOptions); 717var script = CSharpScript.Create(@" 734CSharpScript.EvaluateAsync(@" 743var s0 = CSharpScript.Create(@" 762var state = CSharpScript.RunAsync(@" 795var state = CSharpScript.RunAsync(@" 830var result = CSharpScript.EvaluateAsync<int>(@" 852Assert.Equal(18, CSharpScript.EvaluateAsync<int>("(4 + 5) * 2", ScriptOptions).Result); 853Assert.Equal(1, CSharpScript.EvaluateAsync<long>("6 / (2 * 3)", ScriptOptions).Result); 859var s = CSharpScript.RunAsync(@" 874var f = CSharpScript.EvaluateAsync<Func<int, int>>(@" 890var result = CSharpScript.EvaluateAsync<List<string>>(@" 907var f = CSharpScript.RunAsync("using System;", ScriptOptions). 917var s = CSharpScript.RunAsync(@" 933var result = CSharpScript.EvaluateAsync<List<int>>(@" 957var result = CSharpScript.EvaluateAsync<List<int>>(@" 984var result = CSharpScript.RunAsync(@" 1004var result = CSharpScript.EvaluateAsync<int>(@" 1015var result = CSharpScript.EvaluateAsync<object[]>(@" 1038var result1 = await CSharpScript.EvaluateAsync<int[]>("new int[] { 1,2,3,4 }", ScriptOptions); 1041var result2 = await CSharpScript.EvaluateAsync<int[]>("new int[] { 1,2,3,4,5 }", ScriptOptions); 1044var s1 = await CSharpScript.RunAsync<int[]>("new int[] { 1,2,3,4,5,6 }", ScriptOptions); 1058var result = CSharpScript.EvaluateAsync("System.Threading.Tasks.Task.FromResult(1)", ScriptOptions).Result; 1068Assert.Equal(2, CSharpScript.EvaluateAsync("await System.Threading.Tasks.Task.FromResult(2)", ScriptOptions).Result); 1077Assert.Equal(3, CSharpScript.EvaluateAsync<int>("0 + await System.Threading.Tasks.Task.FromResult(3)", ScriptOptions).Result); 1083var task = CSharpScript.EvaluateAsync<object>("await System.Threading.Tasks.Task.Run(() => { })", ScriptOptions); 1094var s0 = await CSharpScript.RunAsync(@" 1121CSharpScript.RunAsync("int i = 0;", options). 1139CSharpScript.Create("int i = 0;", options). 1153var state = await CSharpScript.RunAsync("var x = (false, 4);", ScriptOptions); 1162var state = await CSharpScript.RunAsync("object x = 1;", options: options); 1176var script = CSharpScript.Create(@" 1224object result = CSharpScript.EvaluateAsync($@" 1243var script = CSharpScript.Create( 1263var script = CSharpScript.Create( 1296var r2 = CSharpScript.Create($@"#r ""{fileMain.Path}""", ScriptOptions).ContinueWith($@"M.X.F").RunAsync().Result.ReturnValue; 1327var r2 = CSharpScript.Create($@"#r ""{fileMain.Path}""", ScriptOptions).ContinueWith($@"M.X.F").RunAsync().Result.ReturnValue; 1342var script = CSharpScript.Create(@"new C()", 1355object result = CSharpScript.EvaluateAsync(@" 1371object result = CSharpScript.EvaluateAsync("new int[] { 1, 2, 3 }.First()", options).Result; 1382var s1 = CSharpScript.RunAsync("new int[] { 1, 2, 3 }.First()", options); 1395ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1403ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1409ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1415ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("1", options), 1431Assert.Equal(2, CSharpScript.EvaluateAsync<int>("1+1", ScriptOptions).Result); 1433Assert.Null(CSharpScript.EvaluateAsync<string>("null", ScriptOptions).Result); 1437CSharpScript.RunAsync<C<int>>("null", ScriptOptions); 1449var cint = CSharpScript.EvaluateAsync<C<int>>("null", options).Result; 1452Assert.Null(CSharpScript.EvaluateAsync<int?>("null", options).Result); 1456CSharpScript.RunAsync<int>("null", ScriptOptions); 1469CSharpScript.RunAsync<string>("1+1", ScriptOptions); 1484var value = CSharpScript.EvaluateAsync<IEnumerable<Exception>>(@" 1532var s0 = CSharpScript.RunAsync<int>("x + Y + Z()", options: ScriptOptions, globals: c); 1548var result = CSharpScript.EvaluateAsync<string>("G()", options: ScriptOptions, globals: m); 1557var s0 = await CSharpScript.RunAsync<int>("Z()", options: ScriptOptions, globals: c, globalsType: typeof(I)); 1574ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("Z()", options: ScriptOptions, globals: c), 1584ScriptingTestHelpers.AssertCompilationError(() => CSharpScript.EvaluateAsync("Z()", options: ScriptOptions, globals: c), 1593var result = CSharpScript.EvaluateAsync<int>("Z()", options: ScriptOptions, globals: c, globalsType: typeof(I)); 1600var s0 = CSharpScript.RunAsync("static int goo = StaticField;", options: ScriptOptions, globals: new C()); 1619var s0 = CSharpScript.RunAsync("int goo(double a) { return 2; }", options: ScriptOptions, globals: new D()); 1631var r0 = CSharpScript.EvaluateAsync<int>("X + Y + Z", options: ScriptOptions, globals: obj); 1635var r1 = CSharpScript.EvaluateAsync<int>("X", options: ScriptOptions, globals: obj); 1642var scriptCompilation = CSharpScript.Create( 1699var scriptCompilation = CSharpScript.Create( 1703WithReferences(typeof(CSharpScript).GetTypeInfo().Assembly), 1764#r ""{typeof(CSharpScript).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName}"" 1767var scriptCompilation = CSharpScript.Create( 1845var result = await CSharpScript.EvaluateAsync<bool>(code, options: ScriptOptions, globalsType: typeof(E), globals: new E()); 1865var script = CSharpScript.Create<bool>(code, options: ScriptOptions, globalsType: typeof(F)); 1887var script = CSharpScript.Create<bool>(code, options: ScriptOptions, globalsType: typeof(F)); 1909var result = await CSharpScript.EvaluateAsync<bool>(code, options: ScriptOptions, globalsType: typeof(F), globals: new F()); 1921var s0 = CSharpScript.Create(@" 1944var s0 = CSharpScript.Create(@" 1971var s0 = CSharpScript.Create(@" 1999var state0 = await CSharpScript.RunAsync(@" 2032var s0 = CSharpScript.Create(@" 2066var s0 = CSharpScript.Create(@" 2100var s0 = CSharpScript.Create(@" 2129CSharpScript.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();