@@ -19,53 +19,43 @@ function IsCoreCLR { $PSVersionTable.ContainsKey('PSEdition') -and $PSVersionTab
1919
2020# region Install locations for modules and scripts
2121
22- if (IsInbox)
23- {
22+ if (IsInbox) {
2423 $script :ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path - Path $env: ProgramFiles - ChildPath " WindowsPowerShell"
2524}
26- elseif (IsCoreCLR){
27- if (IsWindows) {
25+ elseif (IsCoreCLR) {
26+ if (IsWindows) {
2827 $script :ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path - Path $env: ProgramFiles - ChildPath ' PowerShell'
2928 }
3029 else {
3130 $script :ProgramFilesPSPath = Split-Path - Path ([System.Management.Automation.Platform ]::SelectProductNameForDirectory(' SHARED_MODULES' )) - Parent
3231 }
3332}
3433
35- try
36- {
34+ try {
3735 $script :MyDocumentsFolderPath = [Environment ]::GetFolderPath(" MyDocuments" )
3836}
39- catch
40- {
37+ catch {
4138 $script :MyDocumentsFolderPath = $null
4239}
4340
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+ }
5448}
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 ) {
6052 Microsoft.PowerShell.Management\Join-Path - Path $script :MyDocumentsFolderPath - ChildPath ' PowerShell'
61- }
62- else
63- {
53+ }
54+ else {
6455 Microsoft.PowerShell.Management\Join-Path - Path $HOME - ChildPath " Documents\PowerShell"
6556 }
6657 }
67- else
68- {
58+ else {
6959 $script :MyDocumentsPSPath = Split-Path - Path ([System.Management.Automation.Platform ]::SelectProductNameForDirectory(' USER_MODULES' )) - Parent
7060 }
7161}
@@ -80,32 +70,57 @@ $script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path
8070
8171# region Register a test repository
8272
83- function Initialize
84- {
73+ function Initialize {
8574 # Cleaned up commands whose output to console by deleting or piping to Out-Null
8675 Import-Module PackageManagement
8776 Get-PackageProvider - ListAvailable | Out-Null
8877
8978 $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 ) {
9381 $script :RepositoryName = $repo.Name
9482 }
95- else
96- {
83+ else {
9784 Register-PSRepository - Name $RepositoryName - SourceLocation $SourceLocation - InstallationPolicy Trusted
9885 $script :RegisteredINTRepo = $true
9986 }
10087}
10188
10289# endregion
10390
104- function Remove-InstalledModules
105- {
91+ function Remove-InstalledModules {
10692 Get-InstalledModule - Name $ContosoServer - AllVersions - ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module - Force
10793}
10894
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+
109124Describe " PowerShellGet - Module tests" - tags " Feature" {
110125
111126 BeforeAll {
@@ -162,8 +177,7 @@ Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdmin
162177
163178 $installedModuleInfo | Should Not Be $null
164179 $installedModuleInfo.Name | Should Be $ContosoServer
165- if ($script :IsCoreCLR )
166- {
180+ if ($script :IsCoreCLR ) {
167181 $installedModuleInfo.InstalledLocation.StartsWith ($script :MyDocumentsModulesPath , [System.StringComparison ]::OrdinalIgnoreCase) | Should Be $true
168182 }
169183 else {
@@ -180,8 +194,7 @@ Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdmin
180194 }
181195}
182196
183- function Remove-InstalledScripts
184- {
197+ function Remove-InstalledScripts {
185198 Get-InstalledScript - Name $FabrikamServerScript - ErrorAction SilentlyContinue | Uninstall-Script - Force
186199}
187200
@@ -237,22 +250,20 @@ Describe "PowerShellGet - Script tests (Admin)" -tags @('Feature', 'RequireAdmin
237250
238251 $installedScriptInfo | Should Not Be $null
239252 $installedScriptInfo.Name | Should Be $FabrikamServerScript
240- if ($script :IsCoreCLR )
241- {
253+ if ($script :IsCoreCLR ) {
242254 $installedScriptInfo.InstalledLocation.StartsWith ($script :MyDocumentsScriptsPath , [System.StringComparison ]::OrdinalIgnoreCase) | Should Be $true
243255 }
244- else
245- {
256+ else {
246257 $installedScriptInfo.InstalledLocation.StartsWith ($script :ProgramFilesScriptsPath , [System.StringComparison ]::OrdinalIgnoreCase) | Should Be $true
247258 }
248- }
259+ }
249260
250261 AfterAll {
251262 Remove-InstalledScripts
252263 }
253264}
254265
255- Describe ' PowerShellGet Type tests' - tags @ (' BVT' , ' CI' ) {
266+ Describe ' PowerShellGet Type tests' - tags @ (' BVT' , ' CI' ) {
256267 BeforeAll {
257268 Import-Module PowerShellGet - Force
258269 }
@@ -263,15 +274,15 @@ Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
263274 InternalWebProxy = @ (' GetProxy' , ' IsBypassed' )
264275 }
265276
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' )
269280 $PowerShellGetTypeDetails [' InternalSafeHandleZeroOrMinusOneIsInvalid' ] = @ (' IsInvalid' )
270- $PowerShellGetTypeDetails [' InternalSafeX509ChainHandle' ] = @ (' CertFreeCertificateChain' , ' ReleaseHandle' , ' InvalidHandle' )
281+ $PowerShellGetTypeDetails [' InternalSafeX509ChainHandle' ] = @ (' CertFreeCertificateChain' , ' ReleaseHandle' , ' InvalidHandle' )
271282 $PowerShellGetTypeDetails [' Win32Helpers' ] = @ (' CertVerifyCertificateChainPolicy' , ' CertDuplicateCertificateChain' , ' IsMicrosoftCertificate' )
272283 }
273284
274- if (' Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' -as [Type ]) {
285+ if (' Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' -as [Type ]) {
275286 $PowerShellGetTypeDetails [' Telemetry' ] = @ (' TraceMessageArtifactsNotFound' , ' TraceMessageNonPSGalleryRegistration' )
276287 }
277288
@@ -284,7 +295,6 @@ Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
284295 }
285296}
286297
287- if ($RegisteredINTRepo )
288- {
298+ if ($RegisteredINTRepo ) {
289299 Get-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue | Unregister-PSRepository
290300}
0 commit comments