FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptTest/ExtendedHostFunctionsTest.cs at master · orudge/ClearScript · GitHub
orudge
/
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
/
ExtendedHostFunctionsTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
327 lines (280 loc) · 14 KB
Breadcrumbs
ClearScript
/
ClearScriptTest
/
ExtendedHostFunctionsTest.cs
Copy path
File metadata and controls
327 lines (280 loc) · 14 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Diagnostics
.
CodeAnalysis
;
using
System
.
Linq
;
using
Microsoft
.
ClearScript
.
Util
;
using
Microsoft
.
ClearScript
.
Windows
;
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
ExtendedHostFunctionsTest
:
ClearScriptTest
{
#region setup / teardown
private
ScriptEngine
engine
;
private
ExtendedHostFunctions
host
;
[
TestInitialize
]
public
void
TestInitialize
(
)
{
engine
=
new
JScriptEngine
(
WindowsScriptEngineFlags
.
EnableDebugging
)
;
engine
.
AddHostObject
(
"host"
,
host
=
new
ExtendedHostFunctions
(
)
)
;
}
[
TestCleanup
]
public
void
TestCleanup
(
)
{
engine
.
Dispose
(
)
;
BaseTestCleanup
(
)
;
}
#endregion
#region test methods
// ReSharper disable InconsistentNaming
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_arrType
(
)
{
VerifyArrType
<
Random
>
(
)
;
VerifyArrType
<
Random
>
(
3
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_arrType_Enum
(
)
{
VerifyArrType
<
DayOfWeek
>
(
)
;
VerifyArrType
<
DayOfWeek
>
(
3
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_arrType_Scalar
(
)
{
VerifyArrType
<
double
>
(
)
;
VerifyArrType
<
double
>
(
3
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_arrType_Struct
(
)
{
VerifyArrType
<
DateTime
>
(
)
;
VerifyArrType
<
DateTime
>
(
3
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
[
ExpectedException
(
typeof
(
IndexOutOfRangeException
)
)
]
public
void
ExtendedHostFunctions_arrType_BadRank
(
)
{
VerifyArrType
<
Random
>
(
0
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_lib_SingleAssembly
(
)
{
var
assemblyNames
=
new
[
]
{
"mscorlib"
}
;
HostTypeCollectionTest
.
Test
(
host
.
lib
(
assemblyNames
)
,
assemblyNames
,
null
,
(
first
,
second
)
=>
first
==
second
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_lib_MultiAssembly
(
)
{
var
assemblyNames
=
new
[
]
{
"mscorlib"
,
"System"
,
"System.Core"
}
;
HostTypeCollectionTest
.
Test
(
host
.
lib
(
assemblyNames
)
,
assemblyNames
,
null
,
(
first
,
second
)
=>
first
.
FullName
==
second
.
FullName
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_lib_Merge
(
)
{
var
assemblyNames
=
new
[
]
{
"mscorlib"
,
"System"
,
"System.Core"
}
;
var
typeCollection
=
assemblyNames
.
Aggregate
(
new
HostTypeCollection
(
)
,
(
tempTypeCollection
,
assemblyName
)
=>
host
.
lib
(
tempTypeCollection
,
assemblyName
)
)
;
HostTypeCollectionTest
.
Test
(
typeCollection
,
assemblyNames
,
null
,
(
first
,
second
)
=>
first
.
FullName
==
second
.
FullName
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"System.Random"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Random
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_Generic
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"System.Collections.Generic.Dictionary"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Dictionary
<
,
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_GenericWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
intHostType
=
host
.
type
(
"System.Int32"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"System.Collections.Generic.Dictionary"
,
stringHostType
,
intHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Dictionary
<
string
,
int
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_Overloaded
(
)
{
const
string
locator
=
"System.Action"
;
var
hostType
=
(
HostType
)
host
.
type
(
locator
)
;
Assert
.
IsTrue
(
hostType
.
Types
.
Length
>
1
)
;
Assert
.
IsTrue
(
hostType
.
Types
.
All
(
type
=>
type
.
GetLocator
(
)
==
locator
)
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_OverloadedWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
intHostType
=
host
.
type
(
"System.Int32"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"System.Func"
,
stringHostType
,
intHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Func
<
string
,
int
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_PartialAssemblyName
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"System.Linq.Enumerable"
,
"System.Core"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Enumerable
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_PartialAssemblyName_Generic
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"System.Collections.Generic.HashSet"
,
"System.Core"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
HashSet
<
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_PartialAssemblyName_GenericWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"System.Collections.Generic.HashSet"
,
"System.Core"
,
stringHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
HashSet
<
string
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_PartialAssemblyName_Overloaded
(
)
{
const
string
locator
=
"System.Action"
;
var
hostType
=
(
HostType
)
host
.
type
(
locator
,
"System.Core"
)
;
Assert
.
IsTrue
(
hostType
.
Types
.
Length
>
1
)
;
Assert
.
IsTrue
(
hostType
.
Types
.
All
(
type
=>
type
.
GetLocator
(
)
==
locator
)
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_PartialAssemblyName_OverloadedWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
intHostType
=
host
.
type
(
"System.Int32"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"System.Func"
,
"System.Core"
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
intHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Func
<
string
,
string
,
string
,
string
,
string
,
string
,
string
,
string
,
string
,
int
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_FullAssemblyName
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"System.Linq.Enumerable"
,
"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Enumerable
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_FullAssemblyName_Generic
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"System.Collections.Generic.HashSet"
,
"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
HashSet
<
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_FullAssemblyName_GenericWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"System.Collections.Generic.HashSet"
,
"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
,
stringHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
HashSet
<
string
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_FullAssemblyName_Overloaded
(
)
{
const
string
locator
=
"System.Action"
;
var
hostType
=
(
HostType
)
host
.
type
(
locator
,
"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
)
;
Assert
.
IsTrue
(
hostType
.
Types
.
Length
>
1
)
;
Assert
.
IsTrue
(
hostType
.
Types
.
All
(
type
=>
type
.
GetLocator
(
)
==
locator
)
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_FullAssemblyName_OverloadedWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
intHostType
=
host
.
type
(
"System.Int32"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"System.Func"
,
"System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
stringHostType
,
intHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
Func
<
string
,
string
,
string
,
string
,
string
,
string
,
string
,
string
,
string
,
int
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_NonSystem
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"Microsoft.ClearScript.ScriptEngine"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
ScriptEngine
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_NonSystem_Generic
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"Microsoft.ClearScript.OutArg"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
OutArg
<
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_NonSystem_GenericWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"Microsoft.ClearScript.OutArg"
,
stringHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
OutArg
<
string
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_NonSystem_PartialAssemblyName
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"Microsoft.ClearScript.ScriptEngine"
,
"ClearScript"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
ScriptEngine
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_NonSystem_PartialAssemblyName_Generic
(
)
{
var
hostType
=
(
HostType
)
host
.
type
(
"Microsoft.ClearScript.OutArg"
,
"ClearScript"
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
OutArg
<
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_NonSystem_PartialAssemblyName_GenericWithTypeArgs
(
)
{
var
stringHostType
=
host
.
type
(
"System.String"
)
;
var
hostType
=
(
HostType
)
host
.
type
(
"Microsoft.ClearScript.OutArg"
,
"ClearScript"
,
stringHostType
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
typeof
(
OutArg
<
string
>
)
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
public
void
ExtendedHostFunctions_type_FromType
(
)
{
var
type
=
typeof
(
Dictionary
<
string
,
int
>
)
;
var
hostType
=
(
HostType
)
host
.
type
(
type
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
Assert
.
AreEqual
(
type
,
hostType
.
Type
)
;
}
[
TestMethod
,
TestCategory
(
"ExtendedHostFunctions"
)
]
[
ExpectedException
(
typeof
(
TypeLoadException
)
)
]
public
void
ExtendedHostFunctions_type_BadAssemblyName
(
)
{
host
.
type
(
"Microsoft.ClearScript.ScriptEngine"
,
"Bogus"
)
;
}
// ReSharper restore InconsistentNaming
#endregion
#region miscellaneous
private
void
VerifyArrType
<
T
>
(
)
{
var
hostType
=
(
HostType
)
host
.
arrType
<
T
>
(
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
var
type
=
hostType
.
Types
[
0
]
;
Assert
.
IsTrue
(
type
.
IsArray
)
;
Assert
.
AreEqual
(
1
,
type
.
GetArrayRank
(
)
)
;
}
private
void
VerifyArrType
<
T
>
(
int
rank
)
{
var
hostType
=
(
HostType
)
host
.
arrType
<
T
>
(
rank
)
;
Assert
.
AreEqual
(
1
,
hostType
.
Types
.
Length
)
;
var
type
=
hostType
.
Types
[
0
]
;
Assert
.
IsTrue
(
type
.
IsArray
)
;
Assert
.
AreEqual
(
rank
,
type
.
GetArrayRank
(
)
)
;
}
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL