File tree Expand file tree Collapse file tree 13 files changed +504
-220
lines changed
test/JavaScriptEngineSwitcher.Tests Expand file tree Collapse file tree 13 files changed +504
-220
lines changed Load Diff Large diffs are not rendered by default.
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ namespace JavaScriptEngineSwitcher . Tests
2
+ {
3
+ using System ;
4
+ using System . IO ;
5
+ using System . Text . RegularExpressions ;
6
+
7
+ public abstract class FileSystemTestBase
8
+ {
9
+ /// <summary>
10
+ /// Regular expression for working with the `bin` directory path
11
+ /// </summary>
12
+ private readonly Regex _binDirRegex = new Regex ( @"\\bin\\(?:Debug|Release)\\?$" , RegexOptions . IgnoreCase ) ;
13
+
14
+ protected string _baseDirectoryPath ;
15
+
16
+
17
+ protected FileSystemTestBase ( )
18
+ {
19
+ string baseDirectoryPath = AppDomain . CurrentDomain . BaseDirectory ;
20
+ if ( _binDirRegex . IsMatch ( baseDirectoryPath ) )
21
+ {
22
+ baseDirectoryPath = Path . GetFullPath ( Path . Combine ( baseDirectoryPath , @"..\..\..\" ) ) ;
23
+ }
24
+
25
+ _baseDirectoryPath = baseDirectoryPath ;
26
+ }
27
+ }
28
+ }
File renamed without changes.
Original file line number Diff line number Diff line change 63
63
</ItemGroup >
64
64
<ItemGroup >
65
65
<Compile Include =" Es5TestsBase.cs" />
66
+ <Compile Include =" FileSystemTestBase.cs" />
66
67
<Compile Include =" Jint\CommonTests.cs" />
67
68
<Compile Include =" Jint\Es5Tests.cs" />
68
69
<Compile Include =" Jurassic\CommonTests.cs" />
Original file line number Diff line number Diff line change 1
1
namespace JavaScriptEngineSwitcher . Tests . Jint
2
2
{
3
- using NUnit . Framework ;
4
-
5
3
using Core ;
6
4
7
- [ TestFixture ]
8
5
public class CommonTests : CommonTestsBase
9
6
{
10
- [ TestFixtureSetUp ]
11
- public override void SetUp ( )
7
+ protected override IJsEngine CreateJsEngine ( )
12
8
{
13
- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
9
+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
10
+
11
+ return jsEngine ;
14
12
}
15
13
}
16
14
}
Original file line number Diff line number Diff line change 4
4
5
5
using Core ;
6
6
7
- [ TestFixture ]
8
7
public class Es5Tests : Es5TestsBase
9
8
{
10
- [ TestFixtureSetUp ]
11
- public override void SetUp ( )
9
+ protected override IJsEngine CreateJsEngine ( )
12
10
{
13
- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
11
+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
12
+
13
+ return jsEngine ;
14
14
}
15
15
16
16
#region Object methods
@@ -36,12 +36,20 @@ public override void ObjectKeysMethodIsSupported()
36
36
const string targetOutput4 = "foo" ;
37
37
38
38
// Act
39
- var output1 = _jsEngine . Evaluate < string > ( input1 ) ;
40
- var output2 = _jsEngine . Evaluate < string > ( input2 ) ;
41
- var output3 = _jsEngine . Evaluate < string > ( input3 ) ;
42
-
43
- _jsEngine . Execute ( input4A ) ;
44
- var output4 = _jsEngine . Evaluate < string > ( input4B ) ;
39
+ string output1 ;
40
+ string output2 ;
41
+ string output3 ;
42
+ string output4 ;
43
+
44
+ using ( var jsEngine = CreateJsEngine ( ) )
45
+ {
46
+ output1 = jsEngine . Evaluate < string > ( input1 ) ;
47
+ output2 = jsEngine . Evaluate < string > ( input2 ) ;
48
+ output3 = jsEngine . Evaluate < string > ( input3 ) ;
49
+
50
+ jsEngine . Execute ( input4A ) ;
51
+ output4 = jsEngine . Evaluate < string > ( input4B ) ;
52
+ }
45
53
46
54
// Assert
47
55
Assert . AreEqual ( targetOutput1 , output1 ) ;
Original file line number Diff line number Diff line change 1
1
namespace JavaScriptEngineSwitcher . Tests . Jurassic
2
2
{
3
- using NUnit . Framework ;
4
-
5
3
using Core ;
6
4
7
- [ TestFixture ]
8
5
public class CommonTests : CommonTestsBase
9
6
{
10
- [ TestFixtureSetUp ]
11
- public override void SetUp ( )
7
+ protected override IJsEngine CreateJsEngine ( )
12
8
{
13
- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
9
+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
10
+
11
+ return jsEngine ;
14
12
}
15
13
}
16
14
}
Original file line number Diff line number Diff line change 4
4
5
5
using Core ;
6
6
7
- [ TestFixture ]
8
7
public class Es5Tests : Es5TestsBase
9
8
{
10
- [ TestFixtureSetUp ]
11
- public override void SetUp ( )
9
+ protected override IJsEngine CreateJsEngine ( )
12
10
{
13
- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
11
+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
12
+
13
+ return jsEngine ;
14
14
}
15
15
16
16
#region Object methods
@@ -36,12 +36,20 @@ public override void ObjectKeysMethodIsSupported()
36
36
const string targetOutput4 = "displayName,foo" ;
37
37
38
38
// Act
39
- var output1 = _jsEngine . Evaluate < string > ( input1 ) ;
40
- var output2 = _jsEngine . Evaluate < string > ( input2 ) ;
41
- var output3 = _jsEngine . Evaluate < string > ( input3 ) ;
42
-
43
- _jsEngine . Execute ( input4A ) ;
44
- var output4 = _jsEngine . Evaluate < string > ( input4B ) ;
39
+ string output1 ;
40
+ string output2 ;
41
+ string output3 ;
42
+ string output4 ;
43
+
44
+ using ( var jsEngine = CreateJsEngine ( ) )
45
+ {
46
+ output1 = jsEngine . Evaluate < string > ( input1 ) ;
47
+ output2 = jsEngine . Evaluate < string > ( input2 ) ;
48
+ output3 = jsEngine . Evaluate < string > ( input3 ) ;
49
+
50
+ jsEngine . Execute ( input4A ) ;
51
+ output4 = jsEngine . Evaluate < string > ( input4B ) ;
52
+ }
45
53
46
54
// Assert
47
55
Assert . AreEqual ( targetOutput1 , output1 ) ;
Original file line number Diff line number Diff line change 1
1
namespace JavaScriptEngineSwitcher . Tests . Msie
2
2
{
3
- using NUnit . Framework ;
4
-
5
3
using Core ;
6
4
7
- [ TestFixture ]
8
5
public class CommonTests : CommonTestsBase
9
6
{
10
- [ TestFixtureSetUp ]
11
- public override void SetUp ( )
7
+ protected override IJsEngine CreateJsEngine ( )
12
8
{
13
- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "MsieJsEngine" ) ;
9
+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "MsieJsEngine" ) ;
10
+
11
+ return jsEngine ;
14
12
}
15
13
}
16
14
}
You can’t perform that action at this time.
0 commit comments