forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvalTests.cs
More file actions
65 lines (53 loc) · 1.62 KB
/
EvalTests.cs
File metadata and controls
65 lines (53 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Xunit;
using JavaScriptEngineSwitcher.ChakraCore;
using JavaScriptEngineSwitcher.Core;
namespace JavaScriptEngineSwitcher.Tests.ChakraCore
{
public class EvalTests : EvalTestsBase
{
protected override string EngineName
{
get { return "ChakraCoreJsEngine"; }
}
private IJsEngine CreateJsEngine(bool disableEval)
{
var jsEngine = new ChakraCoreJsEngine(new ChakraCoreSettings
{
DisableEval = disableEval
});
return jsEngine;
}
public override void UsageOfEvalFunction()
{
// Arrange
int TestDisableEvalSetting(bool disableEval)
{
using (var jsEngine = CreateJsEngine(disableEval: disableEval))
{
return jsEngine.Evaluate<int>("eval('2*2');");
}
}
// Act and Assert
Assert.Equal(4, TestDisableEvalSetting(false));
JsRuntimeException exception = Assert.Throws<JsRuntimeException>(() => TestDisableEvalSetting(true));
Assert.Equal("Runtime error", exception.Category);
Assert.Equal("Eval of strings is disabled in this runtime.", exception.Description);
}
public override void UsageOfFunctionConstructor()
{
// Arrange
int TestDisableEvalSetting(bool disableEval)
{
using (var jsEngine = CreateJsEngine(disableEval: disableEval))
{
return jsEngine.Evaluate<int>("new Function('return 2*2;')();");
}
}
// Act and Assert
Assert.Equal(4, TestDisableEvalSetting(false));
JsRuntimeException exception = Assert.Throws<JsRuntimeException>(() => TestDisableEvalSetting(true));
Assert.Equal("Runtime error", exception.Category);
Assert.Equal("Eval of strings is disabled in this runtime.", exception.Description);
}
}
}