@@ -19,53 +19,43 @@ function IsCoreCLR { $PSVersionTable.ContainsKey('PSEdition') -and $PSVersionTab
19
19
20
20
# region Install locations for modules and scripts
21
21
22
- if (IsInbox)
23
- {
22
+ if (IsInbox) {
24
23
$script :ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path - Path $env: ProgramFiles - ChildPath " WindowsPowerShell"
25
24
}
26
- elseif (IsCoreCLR){
27
- if (IsWindows) {
25
+ elseif (IsCoreCLR) {
26
+ if (IsWindows) {
28
27
$script :ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path - Path $env: ProgramFiles - ChildPath ' PowerShell'
29
28
}
30
29
else {
31
30
$script :ProgramFilesPSPath = Split-Path - Path ([System.Management.Automation.Platform ]::SelectProductNameForDirectory(' SHARED_MODULES' )) - Parent
32
31
}
33
32
}
34
33
35
- try
36
- {
34
+ try {
37
35
$script :MyDocumentsFolderPath = [Environment ]::GetFolderPath(" MyDocuments" )
38
36
}
39
- catch
40
- {
37
+ catch {
41
38
$script :MyDocumentsFolderPath = $null
42
39
}
43
40
44
- if (IsInbox)
45
- {
46
- $script :MyDocumentsPSPath = if ($script :MyDocumentsFolderPath )
47
- {
48
- Microsoft.PowerShell.Management\Join-Path - Path $script :MyDocumentsFolderPath - ChildPath " WindowsPowerShell"
49
- }
50
- else
51
- {
52
- Microsoft.PowerShell.Management\Join-Path - Path $env: USERPROFILE - ChildPath " Documents\WindowsPowerShell"
53
- }
41
+ if (IsInbox) {
42
+ $script :MyDocumentsPSPath = if ($script :MyDocumentsFolderPath ) {
43
+ Microsoft.PowerShell.Management\Join-Path - Path $script :MyDocumentsFolderPath - ChildPath " WindowsPowerShell"
44
+ }
45
+ else {
46
+ Microsoft.PowerShell.Management\Join-Path - Path $env: USERPROFILE - ChildPath " Documents\WindowsPowerShell"
47
+ }
54
48
}
55
- elseif (IsCoreCLR) {
56
- if (IsWindows)
57
- {
58
- $script :MyDocumentsPSPath = if ($script :MyDocumentsFolderPath )
59
- {
49
+ elseif (IsCoreCLR) {
50
+ if (IsWindows) {
51
+ $script :MyDocumentsPSPath = if ($script :MyDocumentsFolderPath ) {
60
52
Microsoft.PowerShell.Management\Join-Path - Path $script :MyDocumentsFolderPath - ChildPath ' PowerShell'
61
- }
62
- else
63
- {
53
+ }
54
+ else {
64
55
Microsoft.PowerShell.Management\Join-Path - Path $HOME - ChildPath " Documents\PowerShell"
65
56
}
66
57
}
67
- else
68
- {
58
+ else {
69
59
$script :MyDocumentsPSPath = Split-Path - Path ([System.Management.Automation.Platform ]::SelectProductNameForDirectory(' USER_MODULES' )) - Parent
70
60
}
71
61
}
@@ -80,32 +70,57 @@ $script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path
80
70
81
71
# region Register a test repository
82
72
83
- function Initialize
84
- {
73
+ function Initialize {
85
74
# Cleaned up commands whose output to console by deleting or piping to Out-Null
86
75
Import-Module PackageManagement
87
76
Get-PackageProvider - ListAvailable | Out-Null
88
77
89
78
$repo = Get-PSRepository - ErrorAction SilentlyContinue |
90
- Where-Object {$_.SourceLocation.StartsWith ($SourceLocation , [System.StringComparison ]::OrdinalIgnoreCase)}
91
- if ($repo )
92
- {
79
+ Where-Object { $_.SourceLocation.StartsWith ($SourceLocation , [System.StringComparison ]::OrdinalIgnoreCase) }
80
+ if ($repo ) {
93
81
$script :RepositoryName = $repo.Name
94
82
}
95
- else
96
- {
83
+ else {
97
84
Register-PSRepository - Name $RepositoryName - SourceLocation $SourceLocation - InstallationPolicy Trusted
98
85
$script :RegisteredINTRepo = $true
99
86
}
100
87
}
101
88
102
89
# endregion
103
90
104
- function Remove-InstalledModules
105
- {
91
+ function Remove-InstalledModules {
106
92
Get-InstalledModule - Name $ContosoServer - AllVersions - ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module - Force
107
93
}
108
94
95
+ Describe " PowerShellGet - Module public variable tests" {
96
+ BeforeAll {
97
+ if ($script :Initialized -eq $false ) {
98
+ Initialize
99
+ $script :Initialized = $true
100
+ }
101
+ }
102
+
103
+ It " PSGetPath variable should exist" {
104
+ Test-Path - Path variable:PSGetPath | Should - BeTrue
105
+ }
106
+
107
+ It " PSGetPath - AllUsersModules should be $ProgramFilesModulesPath " {
108
+ $PSGetPath.AllUsersModules | Should - Be $script :ProgramFilesModulesPath
109
+ }
110
+
111
+ It " PSGetPath - AllUsersScripts should be $ProgramFilesScriptsPath " {
112
+ $PSGetPath.AllUsersScripts | Should - Be $script :ProgramFilesScriptsPath
113
+ }
114
+
115
+ It " PSGetPath - CurrentUserModules should be $ProgramFilesModulesPath " {
116
+ $PSGetPath.CurrentUserModules | Should - Be $script :MyDocumentsModulesPath
117
+ }
118
+
119
+ It " PSGetPath - CurrentUserScripts should be $ProgramFilesScriptsPath " {
120
+ $PSGetPath.CurrentUserScripts | Should - Be $script :MyDocumentsScriptsPath
121
+ }
122
+ }
123
+
109
124
Describe " PowerShellGet - Module tests" - tags " Feature" {
110
125
111
126
BeforeAll {
@@ -162,8 +177,7 @@ Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdmin
162
177
163
178
$installedModuleInfo | Should Not Be $null
164
179
$installedModuleInfo.Name | Should Be $ContosoServer
165
- if ($script :IsCoreCLR )
166
- {
180
+ if ($script :IsCoreCLR ) {
167
181
$installedModuleInfo.InstalledLocation.StartsWith ($script :MyDocumentsModulesPath , [System.StringComparison ]::OrdinalIgnoreCase) | Should Be $true
168
182
}
169
183
else {
@@ -180,8 +194,7 @@ Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdmin
180
194
}
181
195
}
182
196
183
- function Remove-InstalledScripts
184
- {
197
+ function Remove-InstalledScripts {
185
198
Get-InstalledScript - Name $FabrikamServerScript - ErrorAction SilentlyContinue | Uninstall-Script - Force
186
199
}
187
200
@@ -237,22 +250,20 @@ Describe "PowerShellGet - Script tests (Admin)" -tags @('Feature', 'RequireAdmin
237
250
238
251
$installedScriptInfo | Should Not Be $null
239
252
$installedScriptInfo.Name | Should Be $FabrikamServerScript
240
- if ($script :IsCoreCLR )
241
- {
253
+ if ($script :IsCoreCLR ) {
242
254
$installedScriptInfo.InstalledLocation.StartsWith ($script :MyDocumentsScriptsPath , [System.StringComparison ]::OrdinalIgnoreCase) | Should Be $true
243
255
}
244
- else
245
- {
256
+ else {
246
257
$installedScriptInfo.InstalledLocation.StartsWith ($script :ProgramFilesScriptsPath , [System.StringComparison ]::OrdinalIgnoreCase) | Should Be $true
247
258
}
248
- }
259
+ }
249
260
250
261
AfterAll {
251
262
Remove-InstalledScripts
252
263
}
253
264
}
254
265
255
- Describe ' PowerShellGet Type tests' - tags @ (' BVT' , ' CI' ) {
266
+ Describe ' PowerShellGet Type tests' - tags @ (' BVT' , ' CI' ) {
256
267
BeforeAll {
257
268
Import-Module PowerShellGet - Force
258
269
}
@@ -263,15 +274,15 @@ Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
263
274
InternalWebProxy = @ (' GetProxy' , ' IsBypassed' )
264
275
}
265
276
266
- if ((IsWindows)) {
267
- $PowerShellGetTypeDetails [' CERT_CHAIN_POLICY_PARA' ] = @ (' cbSize' , ' dwFlags' , ' pvExtraPolicyPara' )
268
- $PowerShellGetTypeDetails [' CERT_CHAIN_POLICY_STATUS' ] = @ (' cbSize' , ' dwError' , ' lChainIndex' , ' lElementIndex' , ' pvExtraPolicyStatus' )
277
+ if ((IsWindows)) {
278
+ $PowerShellGetTypeDetails [' CERT_CHAIN_POLICY_PARA' ] = @ (' cbSize' , ' dwFlags' , ' pvExtraPolicyPara' )
279
+ $PowerShellGetTypeDetails [' CERT_CHAIN_POLICY_STATUS' ] = @ (' cbSize' , ' dwError' , ' lChainIndex' , ' lElementIndex' , ' pvExtraPolicyStatus' )
269
280
$PowerShellGetTypeDetails [' InternalSafeHandleZeroOrMinusOneIsInvalid' ] = @ (' IsInvalid' )
270
- $PowerShellGetTypeDetails [' InternalSafeX509ChainHandle' ] = @ (' CertFreeCertificateChain' , ' ReleaseHandle' , ' InvalidHandle' )
281
+ $PowerShellGetTypeDetails [' InternalSafeX509ChainHandle' ] = @ (' CertFreeCertificateChain' , ' ReleaseHandle' , ' InvalidHandle' )
271
282
$PowerShellGetTypeDetails [' Win32Helpers' ] = @ (' CertVerifyCertificateChainPolicy' , ' CertDuplicateCertificateChain' , ' IsMicrosoftCertificate' )
272
283
}
273
284
274
- if (' Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' -as [Type ]) {
285
+ if (' Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' -as [Type ]) {
275
286
$PowerShellGetTypeDetails [' Telemetry' ] = @ (' TraceMessageArtifactsNotFound' , ' TraceMessageNonPSGalleryRegistration' )
276
287
}
277
288
@@ -284,7 +295,6 @@ Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
284
295
}
285
296
}
286
297
287
- if ($RegisteredINTRepo )
288
- {
298
+ if ($RegisteredINTRepo ) {
289
299
Get-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue | Unregister-PSRepository
290
300
}
0 commit comments