forked from nilproject/NiL.JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemberAlias.cs
76 lines (62 loc) · 2.36 KB
/
MemberAlias.cs
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS.BaseLibrary;
using NiL.JS.Core;
using System.Diagnostics;
using NiL.JS.Core.Interop;
namespace FunctionalTests
{
[TestClass]
public class MemberAlias
{
[TestMethod]
public void CreateInstanceOfGenericType()
{
var context = new Context();
context.DefineConstructor(typeof(List<>));
var result = context.Eval("new (List(Number))()").Value;
Assert.AreSame(typeof(List<Number>), result.GetType());
}
private static class ClassWithAliasedMember
{
[JavaScriptName("NameForJsSide")]
public static string NameForDotNetSide()
{
return new StackFrame().GetMethod().Name;
}
[JavaScriptName("@@MySymbol")]
public static string MethodBySymbol()
{
return new StackFrame().GetMethod().Name;
}
}
[TestMethod]
public void AliasForMember_ShouldChangePropertyName()
{
var context = new Context();
context.DefineConstructor(typeof(ClassWithAliasedMember));
var names = context.Eval("Object.getOwnPropertyNames(ClassWithAliasedMember)").Value as NiL.JS.BaseLibrary.Array;
Assert.IsTrue((bool)NiL.JS.BaseLibrary.Array.includes(names, new Arguments { "NameForJsSide" }));
Assert.IsFalse((bool)NiL.JS.BaseLibrary.Array.includes(names, new Arguments { "NameForDotNetSide" }));
}
[TestMethod]
public void AliasForMember_ShouldChangeNameOfFunction()
{
var context = new Context();
context.DefineConstructor(typeof(ClassWithAliasedMember));
var name = context.Eval("ClassWithAliasedMember.NameForJsSide.name").Value.ToString();
Assert.AreEqual("NameForJsSide", name);
}
[TestMethod]
public void AliasForMember_ShouldProcessSymbolName()
{
var context = new Context();
context.DefineConstructor(typeof(ClassWithAliasedMember));
var name = context.Eval("ClassWithAliasedMember[Symbol.for('MySymbol')].name").Value.ToString();
Assert.AreEqual("MySymbol", name);
}
}
}