FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptTest/TypeRestrictionTest.cs at master · PascalMing/ClearScript · GitHub
PascalMing
/
ClearScript
Public
forked from
ClearFoundry/ClearScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScriptTest
/
TypeRestrictionTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
121 lines (95 loc) · 5.15 KB
Breadcrumbs
ClearScript
/
ClearScriptTest
/
TypeRestrictionTest.cs
Copy path
File metadata and controls
121 lines (95 loc) · 5.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
.
Diagnostics
.
CodeAnalysis
;
using
Microsoft
.
ClearScript
.
V8
;
using
Microsoft
.
VisualStudio
.
TestTools
.
UnitTesting
;
namespace
Microsoft
.
ClearScript
.
Test
{
[
TestClass
]
[
SuppressMessage
(
"Microsoft.Design"
,
"CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable"
,
Justification
=
"Test classes use TestCleanupAttribute for deterministic teardown."
)
]
public
class
TypeRestrictionTest
:
ClearScriptTest
{
#region setup / teardown
private
ScriptEngine
engine
;
[
TestInitialize
]
public
void
TestInitialize
(
)
{
engine
=
new
V8ScriptEngine
(
V8ScriptEngineFlags
.
EnableDebugging
)
;
engine
.
Script
.
testContainer
=
new
TestContainer
(
)
;
}
[
TestCleanup
]
public
void
TestCleanup
(
)
{
engine
.
Dispose
(
)
;
BaseTestCleanup
(
)
;
}
#endregion
#region test methods
// ReSharper disable InconsistentNaming
[
TestMethod
,
TestCategory
(
"TypeRestriction"
)
]
public
void
TypeRestriction_Field
(
)
{
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.Field)"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
InterfaceTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.InterfaceField)"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.ObjectField)"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.UnrestrictedField)"
)
)
;
engine
.
DisableTypeRestriction
=
true
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.InterfaceField)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"TypeRestriction"
)
]
public
void
TypeRestriction_Property
(
)
{
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.Property)"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
InterfaceTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.InterfaceProperty)"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.ObjectProperty)"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.UnrestrictedProperty)"
)
)
;
engine
.
DisableTypeRestriction
=
true
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.InterfaceProperty)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"TypeRestriction"
)
]
public
void
TypeRestriction_Method
(
)
{
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.Method())"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
InterfaceTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.InterfaceMethod())"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.ObjectMethod())"
)
)
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.UnrestrictedMethod())"
)
)
;
engine
.
DisableTypeRestriction
=
true
;
Assert
.
AreEqual
(
TestContainer
.
ObjectTestValue
,
engine
.
Evaluate
(
"testContainer.TestMethod(testContainer.InterfaceMethod())"
)
)
;
}
// ReSharper restore InconsistentNaming
#endregion
#region miscellaneous
public
interface
ITestInterface
{
}
public
class
TestObject
:
ITestInterface
{
}
public
class
TestContainer
{
public
const
int
ObjectTestValue
=
123456
;
public
const
string
InterfaceTestValue
=
"fooBARbazQUX"
;
public
TestObject
Field
=
new
TestObject
(
)
;
public
ITestInterface
InterfaceField
=
new
TestObject
(
)
;
public
object
ObjectField
=
new
TestObject
(
)
;
[
ScriptMember
(
ScriptMemberFlags
.
ExposeRuntimeType
)
]
public
ITestInterface
UnrestrictedField
=
new
TestObject
(
)
;
public
TestObject
Property
=>
Field
;
public
ITestInterface
InterfaceProperty
=>
InterfaceField
;
public
object
ObjectProperty
=>
ObjectField
;
[
ScriptMember
(
ScriptMemberFlags
.
ExposeRuntimeType
)
]
public
ITestInterface
UnrestrictedProperty
=>
UnrestrictedField
;
public
TestObject
Method
(
)
{
return
Property
;
}
public
ITestInterface
InterfaceMethod
(
)
{
return
InterfaceProperty
;
}
public
object
ObjectMethod
(
)
{
return
ObjectProperty
;
}
[
ScriptMember
(
ScriptMemberFlags
.
ExposeRuntimeType
)
]
public
ITestInterface
UnrestrictedMethod
(
)
{
return
UnrestrictedProperty
;
}
public
int
TestMethod
(
TestObject
testObject
)
{
return
ObjectTestValue
;
}
public
string
TestMethod
(
ITestInterface
testInterface
)
{
return
InterfaceTestValue
;
}
}
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL