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 6363 </ItemGroup >
6464 <ItemGroup >
6565 <Compile Include =" Es5TestsBase.cs" />
66+ <Compile Include =" FileSystemTestBase.cs" />
6667 <Compile Include =" Jint\CommonTests.cs" />
6768 <Compile Include =" Jint\Es5Tests.cs" />
6869 <Compile Include =" Jurassic\CommonTests.cs" />
Original file line number Diff line number Diff line change 11namespace JavaScriptEngineSwitcher . Tests . Jint
22{
3- using NUnit . Framework ;
4-
53 using Core ;
64
7- [ TestFixture ]
85 public class CommonTests : CommonTestsBase
96 {
10- [ TestFixtureSetUp ]
11- public override void SetUp ( )
7+ protected override IJsEngine CreateJsEngine ( )
128 {
13- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
9+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
10+
11+ return jsEngine ;
1412 }
1513 }
1614}
Original file line number Diff line number Diff line change 44
55 using Core ;
66
7- [ TestFixture ]
87 public class Es5Tests : Es5TestsBase
98 {
10- [ TestFixtureSetUp ]
11- public override void SetUp ( )
9+ protected override IJsEngine CreateJsEngine ( )
1210 {
13- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
11+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JintJsEngine" ) ;
12+
13+ return jsEngine ;
1414 }
1515
1616 #region Object methods
@@ -36,12 +36,20 @@ public override void ObjectKeysMethodIsSupported()
3636 const string targetOutput4 = "foo" ;
3737
3838 // 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+ }
4553
4654 // Assert
4755 Assert . AreEqual ( targetOutput1 , output1 ) ;
Original file line number Diff line number Diff line change 11namespace JavaScriptEngineSwitcher . Tests . Jurassic
22{
3- using NUnit . Framework ;
4-
53 using Core ;
64
7- [ TestFixture ]
85 public class CommonTests : CommonTestsBase
96 {
10- [ TestFixtureSetUp ]
11- public override void SetUp ( )
7+ protected override IJsEngine CreateJsEngine ( )
128 {
13- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
9+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
10+
11+ return jsEngine ;
1412 }
1513 }
1614}
Original file line number Diff line number Diff line change 44
55 using Core ;
66
7- [ TestFixture ]
87 public class Es5Tests : Es5TestsBase
98 {
10- [ TestFixtureSetUp ]
11- public override void SetUp ( )
9+ protected override IJsEngine CreateJsEngine ( )
1210 {
13- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
11+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "JurassicJsEngine" ) ;
12+
13+ return jsEngine ;
1414 }
1515
1616 #region Object methods
@@ -36,12 +36,20 @@ public override void ObjectKeysMethodIsSupported()
3636 const string targetOutput4 = "displayName,foo" ;
3737
3838 // 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+ }
4553
4654 // Assert
4755 Assert . AreEqual ( targetOutput1 , output1 ) ;
Original file line number Diff line number Diff line change 11namespace JavaScriptEngineSwitcher . Tests . Msie
22{
3- using NUnit . Framework ;
4-
53 using Core ;
64
7- [ TestFixture ]
85 public class CommonTests : CommonTestsBase
96 {
10- [ TestFixtureSetUp ]
11- public override void SetUp ( )
7+ protected override IJsEngine CreateJsEngine ( )
128 {
13- _jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "MsieJsEngine" ) ;
9+ var jsEngine = JsEngineSwitcher . Current . CreateJsEngineInstance ( "MsieJsEngine" ) ;
10+
11+ return jsEngine ;
1412 }
1513 }
1614}
You can’t perform that action at this time.
0 commit comments