-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathInteropTests.cs
More file actions
101 lines (79 loc) · 2.45 KB
/
InteropTests.cs
File metadata and controls
101 lines (79 loc) · 2.45 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.IO;
using NUnit.Framework;
using MsieJavaScriptEngine.Test.Common;
using MsieJavaScriptEngine.Test.Common.Interop.Animals;
namespace MsieJavaScriptEngine.Test.ChakraActiveScript
{
[TestFixture]
public class InteropTests : InteropTestsBase
{
protected override JsEngineMode EngineMode => JsEngineMode.ChakraActiveScript;
#region Embedding of objects
#region Delegates
[Test]
public override void EmbeddingOfInstanceOfDelegateAndCheckingItsPrototype()
{ }
[Test]
public override void EmbeddingOfInstanceOfDelegateAndGettingItsMethodProperty()
{
// Arrange
string TestAllowReflectionSetting(bool allowReflection)
{
var cat = new Cat();
var cryFunc = new Func<string>(cat.Cry);
using (var jsEngine = CreateJsEngine(allowReflection: allowReflection))
{
jsEngine.EmbedHostObject("cry", cryFunc);
return jsEngine.Evaluate<string>("cry.Method;");
}
}
// Act and Assert
Assert.AreEqual("System.String Cry()", TestAllowReflectionSetting(true));
Assert.AreEqual("undefined", TestAllowReflectionSetting(false));
}
#endregion
#region Recursive calls
#region Mapping of errors
[Test]
public void MappingRuntimeErrorDuringRecursiveEvaluationOfFiles()
{
// Arrange
string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError");
const string input = "require('index').calculateResult();";
// Act
JsRuntimeException exception = null;
using (var jsEngine = CreateJsEngine())
{
try
{
Func<string, object> loadModule = path => {
string absolutePath = Path.Combine(directoryPath, $"{path}.js");
string code = File.ReadAllText(absolutePath);
object result = jsEngine.Evaluate(code, absolutePath);
return result;
};
jsEngine.EmbedHostObject("require", loadModule);
double output = jsEngine.Evaluate<double>(input);
}
catch (JsRuntimeException e)
{
exception = e;
}
}
// Assert
Assert.NotNull(exception);
Assert.AreEqual("Runtime error", exception.Category);
Assert.AreEqual("'argumens' is undefined", exception.Description);
Assert.AreEqual("ReferenceError", exception.Type);
Assert.AreEqual("math.js", exception.DocumentName);
Assert.AreEqual(10, exception.LineNumber);
Assert.AreEqual(4, exception.ColumnNumber);
Assert.IsEmpty(exception.SourceFragment);
Assert.IsEmpty(exception.CallStack);
}
#endregion
#endregion
#endregion
}
}