Skip to content

Commit d6cb6f0

Browse files
committed
Move TestClass into file
Invoke TestClass using reflection
1 parent 0e91e7c commit d6cb6f0

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,15 @@ public void ShouldSupportInlineNugetReferencesWithTrailingSemicoloninEvaluatedCo
203203
[Fact]
204204
public static void ShouldHandleIssue235()
205205
{
206-
var code = @"#r ""nuget: AgileObjects.AgileMapper, 0.23.0""
207-
using AgileObjects.AgileMapper;
208-
public class TestClass
209-
{
210-
public TestClass()
211-
{
212-
IMapper mapper = Mapper.CreateNew();
213-
}
214-
}";
215206
var logger = new ScriptLogger(Console.Error, true);
216207
var runtimeDependencyResolver = new RuntimeDependencyResolver(type => ((level, message) => {}));
217208
var compiler = new ScriptCompiler(logger, runtimeDependencyResolver);
218209
//Copied from Execute(string fixture, params string[] arguments)
219210
//Probably there should be a better place for this
220211
var workingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "TestFixtures", "Issue235");
221-
var scriptContext = new ScriptContext(SourceText.From(code), workingDirectory, Enumerable.Empty<string>(), scriptMode: ScriptMode.REPL);
212+
var scriptContext = new ScriptContext(SourceText.From(File.ReadAllText(Path.Combine(workingDirectory, "TestClass.csx"))), workingDirectory, Enumerable.Empty<string>(), scriptMode: ScriptMode.REPL);
222213
var compilationResult = compiler.CreateCompilationContext<object, InteractiveScriptGlobals>(scriptContext);
223-
using(var ms = File.OpenWrite(Path.Combine(workingDirectory, "Issue235.dll")))
214+
using(var ms = File.OpenWrite(Path.Combine(workingDirectory, "TestClass.dll")))
224215
{
225216
compilationResult.Script.GetCompilation().Emit(ms);
226217
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#! "netcoreapp2.0"
22
#r "nuget: AgileObjects.AgileMapper, 0.23.1"
3-
#r "Issue235.dll"
3+
#r "TestClass.dll"
44

5+
using System.Reflection;
6+
using System.Runtime.CompilerServices;
57
using AgileObjects.AgileMapper;
6-
8+
static string GetScriptPath([CallerFilePath] string path = null) => path;
79
IMapper mapper = Mapper.CreateNew();
8-
new Submission#0.TestClass();
10+
//TODO: Temporary workaround until I figure out how to change TestClass Submission#0 class name
11+
var testClassAssembly = Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(GetScriptPath()),"TestClass.dll"));
12+
var testClass = testClassAssembly.GetType("Submission#0").GetNestedType("TestClass");
13+
var instance = Activator.CreateInstance(testClass);
914
Console.WriteLine("Hello World!");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#r "nuget: AgileObjects.AgileMapper, 0.23.0"
2+
using AgileObjects.AgileMapper;
3+
public class TestClass
4+
{
5+
public TestClass()
6+
{
7+
IMapper mapper = Mapper.CreateNew();
8+
}
9+
}

0 commit comments

Comments
 (0)