FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptTest/StaticMemberAccessTest.cs at master · michaelcoxon/ClearScript · GitHub
michaelcoxon
/
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
/
StaticMemberAccessTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
300 lines (255 loc) · 13.2 KB
Breadcrumbs
ClearScript
/
ClearScriptTest
/
StaticMemberAccessTest.cs
Copy path
File metadata and controls
300 lines (255 loc) · 13.2 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
Diagnostics
.
CodeAnalysis
;
using
System
.
Linq
;
using
Microsoft
.
CSharp
.
RuntimeBinder
;
using
Microsoft
.
ClearScript
.
V8
;
using
Microsoft
.
VisualStudio
.
TestTools
.
UnitTesting
;
namespace
Microsoft
.
ClearScript
.
Test
{
[
TestClass
]
[
DeploymentItem
(
"ClearScriptV8-64.dll"
)
]
[
DeploymentItem
(
"ClearScriptV8-32.dll"
)
]
[
DeploymentItem
(
"v8-x64.dll"
)
]
[
DeploymentItem
(
"v8-ia32.dll"
)
]
[
DeploymentItem
(
"v8-base-x64.dll"
)
]
[
DeploymentItem
(
"v8-base-ia32.dll"
)
]
[
SuppressMessage
(
"Microsoft.Design"
,
"CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable"
,
Justification
=
"Test classes use TestCleanupAttribute for deterministic teardown."
)
]
public
class
StaticMemberAccessTest
:
ClearScriptTest
{
#region setup / teardown
private
ScriptEngine
engine
;
[
TestInitialize
]
public
void
TestInitialize
(
)
{
engine
=
new
V8ScriptEngine
(
V8ScriptEngineFlags
.
EnableDebugging
)
;
engine
.
AddHostObject
(
"host"
,
new
ExtendedHostFunctions
(
)
)
;
engine
.
AddHostObject
(
"mscorlib"
,
HostItemFlags
.
GlobalMembers
,
new
HostTypeCollection
(
"mscorlib"
)
)
;
engine
.
AddHostObject
(
"ClearScriptTest"
,
HostItemFlags
.
GlobalMembers
,
new
HostTypeCollection
(
"ClearScriptTest"
)
.
GetNamespaceNode
(
"Microsoft.ClearScript.Test"
)
)
;
}
[
TestCleanup
]
public
void
TestCleanup
(
)
{
engine
.
Dispose
(
)
;
BaseTestCleanup
(
)
;
}
#endregion
#region test methods
// ReSharper disable InconsistentNaming
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field
(
)
{
StaticTestClass
.
StaticField
=
Enumerable
.
Range
(
0
,
10
)
.
ToArray
(
)
;
Assert
.
AreEqual
(
10
,
engine
.
Evaluate
(
"StaticTestClass.StaticField.Length"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticField = host.newArr(System.Int32, 5)"
)
;
Assert
.
AreEqual
(
5
,
StaticTestClass
.
StaticField
.
Length
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Null
(
)
{
engine
.
Execute
(
"StaticTestClass.StaticField = null"
)
;
Assert
.
IsNull
(
StaticTestClass
.
StaticField
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticField = host.newArr(System.Double, 5)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Scalar
(
)
{
StaticTestClass
.
StaticScalarField
=
12345
;
Assert
.
AreEqual
(
12345
,
engine
.
Evaluate
(
"StaticTestClass.StaticScalarField"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticScalarField = 4321"
)
;
Assert
.
AreEqual
(
4321
,
StaticTestClass
.
StaticScalarField
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Scalar_Overflow
(
)
{
TestUtil
.
AssertException
<
OverflowException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticScalarField = 54321"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Scalar_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticScalarField = TestEnum.Second"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Enum
(
)
{
StaticTestClass
.
StaticEnumField
=
TestEnum
.
Second
;
Assert
.
AreEqual
(
TestEnum
.
Second
,
engine
.
Evaluate
(
"StaticTestClass.StaticEnumField"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticEnumField = TestEnum.Third"
)
;
Assert
.
AreEqual
(
TestEnum
.
Third
,
StaticTestClass
.
StaticEnumField
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Enum_Zero
(
)
{
engine
.
Execute
(
"StaticTestClass.StaticEnumField = 0"
)
;
Assert
.
AreEqual
(
(
TestEnum
)
0
,
StaticTestClass
.
StaticEnumField
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Enum_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticEnumField = 1"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Struct
(
)
{
StaticTestClass
.
StaticStructField
=
TimeSpan
.
FromDays
(
5
)
;
Assert
.
AreEqual
(
TimeSpan
.
FromDays
(
5
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticStructField"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticStructField = System.TimeSpan.FromSeconds(25)"
)
;
Assert
.
AreEqual
(
TimeSpan
.
FromSeconds
(
25
)
,
StaticTestClass
.
StaticStructField
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Field_Struct_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticStructField = System.DateTime.Now"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property
(
)
{
StaticTestClass
.
StaticProperty
=
Enumerable
.
Range
(
0
,
10
)
.
ToArray
(
)
;
Assert
.
AreEqual
(
10
,
engine
.
Evaluate
(
"StaticTestClass.StaticProperty.Length"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticProperty = host.newArr(System.Int32, 5)"
)
;
Assert
.
AreEqual
(
5
,
StaticTestClass
.
StaticProperty
.
Length
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Null
(
)
{
engine
.
Execute
(
"StaticTestClass.StaticProperty = null"
)
;
Assert
.
IsNull
(
StaticTestClass
.
StaticProperty
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticProperty = host.newArr(System.Double, 5)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Scalar
(
)
{
StaticTestClass
.
StaticScalarProperty
=
12345
;
Assert
.
AreEqual
(
12345
,
engine
.
Evaluate
(
"StaticTestClass.StaticScalarProperty"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticScalarProperty = 4321"
)
;
Assert
.
AreEqual
(
4321
,
StaticTestClass
.
StaticScalarProperty
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Scalar_Overflow
(
)
{
TestUtil
.
AssertException
<
OverflowException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticScalarProperty = 54321"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Scalar_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticScalarProperty = TestEnum.Second"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Enum
(
)
{
StaticTestClass
.
StaticEnumProperty
=
TestEnum
.
Second
;
Assert
.
AreEqual
(
TestEnum
.
Second
,
engine
.
Evaluate
(
"StaticTestClass.StaticEnumProperty"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticEnumProperty = TestEnum.Third"
)
;
Assert
.
AreEqual
(
TestEnum
.
Third
,
StaticTestClass
.
StaticEnumProperty
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Enum_Zero
(
)
{
engine
.
Execute
(
"StaticTestClass.StaticEnumProperty = 0"
)
;
Assert
.
AreEqual
(
(
TestEnum
)
0
,
StaticTestClass
.
StaticEnumProperty
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Enum_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticEnumProperty = 1"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Struct
(
)
{
StaticTestClass
.
StaticStructProperty
=
TimeSpan
.
FromDays
(
5
)
;
Assert
.
AreEqual
(
TimeSpan
.
FromDays
(
5
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticStructProperty"
)
)
;
engine
.
Execute
(
"StaticTestClass.StaticStructProperty = System.TimeSpan.FromSeconds(25)"
)
;
Assert
.
AreEqual
(
TimeSpan
.
FromSeconds
(
25
)
,
StaticTestClass
.
StaticStructProperty
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Property_Struct_BadAssignment
(
)
{
TestUtil
.
AssertException
<
ArgumentException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticStructProperty = System.DateTime.Now"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_ReadOnlyProperty
(
)
{
Assert
.
AreEqual
(
StaticTestClass
.
StaticReadOnlyProperty
,
(
int
)
engine
.
Evaluate
(
"StaticTestClass.StaticReadOnlyProperty"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_ReadOnlyProperty_Write
(
)
{
TestUtil
.
AssertException
<
UnauthorizedAccessException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticReadOnlyProperty = 2"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Event
(
)
{
engine
.
Execute
(
"var connection = StaticTestClass.StaticEvent.connect(function (sender, args) { host.type(sender).StaticScalarProperty = args.Arg; })"
)
;
StaticTestClass
.
StaticFireEvent
(
5432
)
;
Assert
.
AreEqual
(
5432
,
StaticTestClass
.
StaticScalarProperty
)
;
engine
.
Execute
(
"connection.disconnect()"
)
;
StaticTestClass
.
StaticFireEvent
(
2345
)
;
Assert
.
AreEqual
(
5432
,
StaticTestClass
.
StaticScalarProperty
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method
(
)
{
Assert
.
AreEqual
(
StaticTestClass
.
StaticMethod
(
"foo"
,
4
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticMethod('foo', 4)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_NoMatchingOverload
(
)
{
TestUtil
.
AssertException
<
RuntimeBinderException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticMethod('foo', TestEnum.Second)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_Generic
(
)
{
Assert
.
AreEqual
(
StaticTestClass
.
StaticMethod
(
"foo"
,
4
,
TestEnum
.
Second
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticMethod('foo', 4, TestEnum.Second)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_Generic_TypeArgConstraintFailure
(
)
{
TestUtil
.
AssertException
<
RuntimeBinderException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticMethod('foo', 4, StaticTestClass)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_GenericRedundant
(
)
{
Assert
.
AreEqual
(
StaticTestClass
.
StaticMethod
(
"foo"
,
4
,
TestEnum
.
Second
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticMethod(TestEnum, 'foo', 4, TestEnum.Second)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_GenericRedundant_MismatchedTypeArg
(
)
{
TestUtil
.
AssertException
<
RuntimeBinderException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticMethod(System.Int32, 'foo', 4, TestEnum.Second)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_GenericExplicit
(
)
{
Assert
.
AreEqual
(
StaticTestClass
.
StaticMethod
<
TestEnum
>
(
4
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticMethod(TestEnum, 4)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_Method_GenericExplicit_MissingTypeArg
(
)
{
TestUtil
.
AssertException
<
RuntimeBinderException
>
(
(
)
=>
engine
.
Execute
(
"StaticTestClass.StaticMethod(4)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_BindTestMethod_BaseClass
(
)
{
var
arg
=
new
TestArg
(
)
as
BaseTestArg
;
engine
.
AddRestrictedHostObject
(
"arg"
,
arg
)
;
Assert
.
AreEqual
(
StaticTestClass
.
StaticBindTestMethod
(
arg
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticBindTestMethod(arg)"
)
)
;
}
[
TestMethod
,
TestCategory
(
"StaticMemberAccess"
)
]
public
void
StaticMemberAccess_BindTestMethod_Interface
(
)
{
var
arg
=
new
TestArg
(
)
as
ITestArg
;
engine
.
AddRestrictedHostObject
(
"arg"
,
arg
)
;
Assert
.
AreEqual
(
StaticTestClass
.
StaticBindTestMethod
(
arg
)
,
engine
.
Evaluate
(
"StaticTestClass.StaticBindTestMethod(arg)"
)
)
;
}
// ReSharper restore InconsistentNaming
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL