@@ -20,7 +20,7 @@ public class ScriptExecutionTests
20
20
{
21
21
[ Fact ]
22
22
public void ShouldExecuteHelloWorld ( )
23
- {
23
+ {
24
24
var result = ExecuteInProcess ( Path . Combine ( "HelloWorld" , "HelloWorld.csx" ) ) ;
25
25
//Assert.Contains("Hello World", result.output);
26
26
}
@@ -47,9 +47,9 @@ public void ShouldHandlePackageWithNativeLibraries()
47
47
{
48
48
var result = Execute ( Path . Combine ( "NativeLibrary" , "NativeLibrary.csx" ) ) ;
49
49
Assert . Contains ( "Connection successful" , result . output ) ;
50
- }
50
+ }
51
51
}
52
-
52
+
53
53
[ Fact ]
54
54
public static void ShouldReturnExitCodeOnenWhenScriptFails ( )
55
55
{
@@ -88,7 +88,7 @@ public static void ShouldHandleIssue166()
88
88
{
89
89
var result = Execute ( Path . Combine ( "Issue166" , "Issue166.csx" ) ) ;
90
90
Assert . Contains ( "Connection successful" , result . output ) ;
91
- }
91
+ }
92
92
}
93
93
94
94
[ Fact ]
@@ -109,7 +109,7 @@ public static void ShouldPassKnownArgumentToScriptWhenEscapedByDoubleHyphen()
109
109
public static void ShouldNotPassUnEscapedKnownArgumentToScript ( )
110
110
{
111
111
var result = Execute ( $ "{ Path . Combine ( "Arguments" , "Arguments.csx" ) } ", "-v" ) ;
112
- Assert . DoesNotContain ( "-v" , result . output ) ;
112
+ Assert . DoesNotContain ( "-v" , result . output ) ;
113
113
}
114
114
115
115
[ Fact ]
@@ -128,15 +128,15 @@ public static void ShouldHandleIssue181()
128
128
129
129
[ Fact ]
130
130
public static void ShouldHandleIssue198 ( )
131
- {
131
+ {
132
132
var result = Execute ( Path . Combine ( "Issue198" , "Issue198.csx" ) ) ;
133
133
Assert . Contains ( "NuGet.Client" , result . output ) ;
134
134
}
135
135
136
136
137
137
[ Fact ]
138
138
public static void ShouldHandleIssue204 ( )
139
- {
139
+ {
140
140
var result = Execute ( Path . Combine ( "Issue204" , "Issue204.csx" ) ) ;
141
141
Assert . Contains ( "System.Net.WebProxy" , result . output ) ;
142
142
}
@@ -203,22 +203,42 @@ public void ShouldSupportInlineNugetReferencesWithTrailingSemicoloninEvaluatedCo
203
203
[ Fact ]
204
204
public static void ShouldHandleIssue235 ( )
205
205
{
206
- var logger = new ScriptLogger ( Console . Error , true ) ;
207
- var runtimeDependencyResolver = new RuntimeDependencyResolver ( type => ( ( level , message ) => { } ) ) ;
208
- var compiler = new ScriptCompiler ( logger , runtimeDependencyResolver ) ;
209
- //Copied from Execute(string fixture, params string[] arguments)
210
- //Probably there should be a better place for this
211
- var workingDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , ".." , ".." , ".." , "TestFixtures" , "Issue235" ) ;
212
- var scriptContext = new ScriptContext ( SourceText . From ( File . ReadAllText ( Path . Combine ( workingDirectory , "TestClass.csx" ) ) ) , workingDirectory , Enumerable . Empty < string > ( ) , scriptMode : ScriptMode . REPL ) ;
213
- var compilationResult = compiler . CreateCompilationContext < object , InteractiveScriptGlobals > ( scriptContext ) ;
214
- using ( var ms = File . OpenWrite ( Path . Combine ( workingDirectory , "TestClass.dll" ) ) )
206
+ string code =
207
+ @"using AgileObjects.AgileMapper;
208
+ public class TestClass
209
+ {
210
+ public TestClass()
211
+ {
212
+ IMapper mapper = Mapper.CreateNew();
213
+ }
214
+ }" ;
215
+
216
+ string script =
217
+ @"#! ""netcoreapp2.0""
218
+ #r ""nuget: AgileObjects.AgileMapper, 0.23.1""
219
+ #r ""TestLibrary.dll""
220
+
221
+ using AgileObjects.AgileMapper;
222
+
223
+ IMapper mapper = Mapper.CreateNew();
224
+ var testClass = new TestClass();
225
+ Console.WriteLine(""Hello World!"");" ;
226
+
227
+
228
+ using ( var disposableFolder = new DisposableFolder ( ) )
215
229
{
216
- compilationResult . Script . GetCompilation ( ) . Emit ( ms ) ;
230
+ var projectFolder = Path . Combine ( disposableFolder . Path , "TestLibrary" ) ;
231
+ ProcessHelper . RunAndCaptureOutput ( "dotnet" , new [ ] { "new classlib -n TestLibrary" } , disposableFolder . Path ) ;
232
+ ProcessHelper . RunAndCaptureOutput ( "dotnet" , new [ ] { "add TestLibrary.csproj package AgileObjects.AgileMapper -v 0.23.0" } , projectFolder ) ;
233
+ File . WriteAllText ( Path . Combine ( projectFolder , "Class1.cs" ) , code ) ;
234
+ File . WriteAllText ( Path . Combine ( projectFolder , "script.csx" ) , script ) ;
235
+ ProcessHelper . RunAndCaptureOutput ( "dotnet" , new [ ] { "build -c release -o ./" } , projectFolder ) ;
236
+
237
+ var dotnetScriptArguments = GetDotnetScriptArguments ( Path . Combine ( projectFolder , "script.csx" ) ) ;
238
+ var result = ProcessHelper . RunAndCaptureOutput ( "dotnet" , dotnetScriptArguments ) ;
239
+ Assert . Contains ( "Hello World!" , result . output ) ;
217
240
}
218
- var result = Execute ( Path . Combine ( "Issue235" , "Issue235.csx" ) ) ;
219
- Assert . Contains ( "Hello World!" , result . output ) ;
220
241
}
221
-
222
242
private static ( string output , int exitCode ) Execute ( string fixture , params string [ ] arguments )
223
243
{
224
244
var result = ProcessHelper . RunAndCaptureOutput ( "dotnet" , GetDotnetScriptArguments ( Path . Combine ( ".." , ".." , ".." , "TestFixtures" , fixture ) , arguments ) ) ;
@@ -236,8 +256,8 @@ private static (string output, int exitCode) ExecuteCode(string code)
236
256
/// </summary>
237
257
private static int ExecuteInProcess ( string fixture , params string [ ] arguments )
238
258
{
239
- var pathToFixture = Path . Combine ( ".." , ".." , ".." , "TestFixtures" , fixture ) ;
240
- var allArguments = new List < string > ( new [ ] { pathToFixture } ) ;
259
+ var pathToFixture = Path . Combine ( ".." , ".." , ".." , "TestFixtures" , fixture ) ;
260
+ var allArguments = new List < string > ( new [ ] { pathToFixture } ) ;
241
261
if ( arguments != null )
242
262
{
243
263
allArguments . AddRange ( arguments ) ;
0 commit comments