forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingAssembly.Tests.ps1
More file actions
113 lines (90 loc) · 4.64 KB
/
Copy pathUsingAssembly.Tests.ps1
File metadata and controls
113 lines (90 loc) · 4.64 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
102
103
104
105
106
107
108
109
110
111
112
113
Describe "Using assembly" -Tags "CI" {
try
{
pushd $PSScriptRoot
$guid = [Guid]::NewGuid()
Add-Type -OutputAssembly $PSScriptRoot\UsingAssemblyTest$guid.dll -TypeDefinition @"
public class ABC {}
"@
It 'parse reports error on non-existing assembly by relative path' {
$err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly foo.dll", [ref]$null, [ref]$err)
$err.Count | Should Be 1
$err[0].ErrorId | Should Be ErrorLoadingAssembly
}
It 'parse reports error on assembly with non-existing fully qualified name' {
$err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly 'System.Management.Automation, Version=99.0.0.0'", [ref]$null, [ref]$err)
$err.Count | Should Be 1
$err[0].ErrorId | Should Be ErrorLoadingAssembly
}
It 'not allow UNC path' {
$err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly \\networkshare\foo.dll", [ref]$null, [ref]$err)
$err.Count | Should Be 1
$err[0].ErrorId | Should Be CannotLoadAssemblyFromUncPath
}
It 'not allow http path' {
$err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly http://microsoft.com/foo.dll", [ref]$null, [ref]$err)
$err.Count | Should Be 1
$err[0].ErrorId | Should Be CannotLoadAssemblyWithUriSchema
}
It "parse does not load the assembly" -pending {
$assemblies = [Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
$assemblies -contains "UsingAssemblyTest$guid" | Should Be $false
$err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly .\UsingAssemblyTest$guid.dll", [ref]$null, [ref]$err)
$assemblies = [Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
$assemblies -contains "UsingAssemblyTest$guid" | Should Be $false
$err.Count | Should Be 0
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly '$PSScriptRoot\UsingAssemblyTest$guid.dll'", [ref]$null, [ref]$err)
$assemblies = [Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
$assemblies -contains "UsingAssemblyTest$guid" | Should Be $false
$err.Count | Should Be 0
$ast = [System.Management.Automation.Language.Parser]::ParseInput("using assembly `"$PSScriptRoot\UsingAssemblyTest$guid.dll`"", [ref]$null, [ref]$err)
$assemblies = [Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
$assemblies -contains "UsingAssemblyTest$guid" | Should Be $false
$err.Count | Should Be 0
}
It "reports runtime error about non-existing assembly with relative path" {
$failed = $true
try {
[scriptblock]::Create("using assembly .\NonExistingAssembly.dll")
$failed = $false
} catch {
$_.FullyQualifiedErrorId | Should be 'ParseException'
$_.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should be 'ErrorLoadingAssembly'
}
$failed | Should be $true
}
#>
It "Assembly loaded at runtime" -pending {
$assemblies = powershell -noprofile -command @"
using assembly .\UsingAssemblyTest$guid.dll
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "UsingAssemblyTest$guid" | Should Be $true
$assemblies = powershell -noprofile -command @"
using assembly $PSScriptRoot\UsingAssemblyTest$guid.dll
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "UsingAssemblyTest$guid" | Should Be $true
$assemblies = powershell -noprofile -command @"
using assembly System.Drawing
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "System.Drawing" | Should Be $true
$assemblies = powershell -noprofile -command @"
using assembly 'System.Drawing, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[Appdomain]::CurrentDomain.GetAssemblies().GetName().Name
"@
$assemblies -contains "System.Drawing" | Should Be $true
}
}
finally
{
Remove-Item .\UsingAssemblyTest$guid.dll
popd
}
}