MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" {5 BeforeAll {6 Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue7 8 New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\1.0\" -Force > $null9 New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\2.0\" -Force > $null10 New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null11 New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null12 13 New-ModuleManifest -Path "$testdrive\Modules\Foo\1.0\Foo.psd1" -ModuleVersion 1.014 New-ModuleManifest -Path "$testdrive\Modules\Foo\2.0\Foo.psd1" -ModuleVersion 2.015 New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -ModuleVersion 1.016 New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" -ModuleVersion 1.017 18 New-Item -ItemType File -Path "$testdrive\Modules\Foo\1.0\Foo.psm1" > $null19 New-Item -ItemType File -Path "$testdrive\Modules\Foo\2.0\Foo.psm1" > $null20 New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null21 22 $removeModuleByNameTestCases = @(23 # Simple patterns24 @{ PatternsToRemove = "Bar"; ShouldBeRemoved = "Bar"; ShouldBePresent = "Baz", "Foo", "Foo"}25 @{ PatternsToRemove = "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"}26 @{ PatternsToRemove = "Bar", "Foo"; ShouldBeRemoved = "Bar", "Foo"; ShouldBePresent = "Baz"}27 @{ PatternsToRemove = "Bar", "Baz", "Foo"; ShouldBeRemoved = "Bar", "Baz", "Foo"; ShouldBePresent = ""}28 @{ PatternsToRemove = "Foo", "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"}29 @{ PatternsToRemove = "Foo", "Foo", "Bar"; ShouldBeRemoved = "Bar", "Foo"; ShouldBePresent = "Baz"}30 @{ PatternsToRemove = "Fo", "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"}31 32 # Regex patterns33 #@{ PatternsToRemove = "*"; ShouldBeRemoved = "Bar", "Baz", "Foo"; ShouldBePresent = ""} -> this breaks pester for some reason34 @{ PatternsToRemove = "B*"; ShouldBeRemoved = "Bar", "Baz"; ShouldBePresent = "Foo", "Foo"}35 @{ PatternsToRemove = "F*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"}36 @{ PatternsToRemove = "Foo*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"}37 @{ PatternsToRemove = "F*", "Bar"; ShouldBeRemoved = "Foo", "Bar"; ShouldBePresent = "Baz"}38 @{ PatternsToRemove = "F*", "F*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"}39 @{ PatternsToRemove = "FF*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo", "Foo"}40 )41 42 $removeModuleByNameErrorTestCases = @(43 # Invalid patterns44 @{ PatternsToRemove = "Fo"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo", "Foo"}45 @{ PatternsToRemove = "Fo", "Ba"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo", "Foo"}46 )47 48 $removeModuleByFQNTestCases = @(49 @{50 FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "1.0"};51 ShouldBeRemoved = "Foo";52 ShouldBePresent = "Bar", "Baz";53 }54 @{55 FqnToRemove = @{ModuleName = "Foo"; RequiredVersion = "1.0"};56 ShouldBeRemoved = "";57 ShouldBePresent = "Bar", "Baz", "Foo";58 }59 @{60 FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "2.0"};61 ShouldBeRemoved = "";62 ShouldBePresent = "Bar", "Baz", "Foo";63 }64 @{65 FqnToRemove = @{ModuleName = "Foo"; RequiredVersion = "2.0"};66 ShouldBeRemoved = "";67 ShouldBePresent = "Bar", "Baz", "Foo";68 }69 @{70 FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "1.0"};71 ShouldBeRemoved = "Foo";72 ShouldBePresent = "Bar", "Baz";73 }74 @{75 FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "1.0"}, @{ModuleName = "Bar"; ModuleVersion = "1.0"};76 ShouldBeRemoved = "Foo", "Bar";77 ShouldBePresent = "Baz";78 }79 @{80 FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "3.0"}, @{ModuleName = "Bar"; ModuleVersion = "1.0"};81 ShouldBeRemoved = "Bar";82 ShouldBePresent = "Baz", "Foo", "Foo";83 }84 )85 86 $removeModuleByFQNErrorTestCases = @(87 @{88 FqnToRemove = @{ModuleName = "Fo"; ModuleVersion = "1.0"};89 ShouldBeRemoved = "";90 ShouldBePresent = "Bar", "Baz", "Foo", "Foo";91 }92 @{93 FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "3.0"};94 ShouldBeRemoved = "";95 ShouldBePresent = "Bar", "Baz", "Foo", "Foo";96 }97 @{98 FqnToRemove = @{ModuleName = "Baz"; RequiredVersion = "3.0"};99 ShouldBeRemoved = "";100 ShouldBePresent = "Bar", "Baz", "Foo", "Foo";101 }102 )103 }104 105 BeforeEach {106 Import-Module -Name "$testdrive\Modules\Foo\1.0\Foo.psd1" -Force107 Import-Module -Name "$testdrive\Modules\Foo\2.0\Foo.psd1" -Force108 Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force109 Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force110 }111 112 AfterAll {113 Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue114 }115 116 It "Remove-Module -Name <PatternsToRemove>" -TestCases $removeModuleByNameTestCases {117 param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)118 119 (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"120 121 { Remove-Module -Name $PatternsToRemove} | Should -Not -Throw122 123 if ($ShouldBeRemoved) {124 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty125 }126 127 if ($ShouldBePresent) {128 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent129 }130 }131 132 It "Remove-Module -Name <PatternsToRemove> (Error cases)" -TestCases $removeModuleByNameErrorTestCases {133 param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)134 135 (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"136 137 { Remove-Module -Name $PatternsToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand"138 139 if ($ShouldBeRemoved) {140 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty141 }142 143 if ($ShouldBePresent) {144 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent145 }146 }147 148 It "Remove-Module -FullyQualifiedName <FqnToRemove>" -TestCases $removeModuleByFQNTestCases {149 param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)150 151 (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"152 153 { Remove-Module -FullyQualifiedName $FqnToRemove } | Should -Not -Throw154 155 if ($ShouldBeRemoved) {156 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty157 }158 159 if ($ShouldBePresent) {160 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent161 }162 }163 164 It "Remove-Module -FullyQualifiedName <FqnToRemove> (Error cases)" -TestCases $removeModuleByFQNErrorTestCases {165 param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)166 167 (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"168 169 { Remove-Module -FullyQualifiedName $FqnToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand"170 171 if ($ShouldBeRemoved) {172 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty173 }174 175 if ($ShouldBePresent) {176 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent177 }178 }179 180 It "Remove-Module -ModuleInfo <FqnToRemove>" -TestCases $removeModuleByFQNTestCases {181 param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)182 183 (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"184 185 $modInfo = Get-Module -FullyQualifiedName $FqnToRemove186 { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw187 188 if ($ShouldBeRemoved) {189 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty190 }191 192 if ($ShouldBePresent) {193 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent194 }195 }196 197 It "Remove-Module -ModuleInfo (removing twice works)" {198 (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo"199 200 $modInfo = Get-Module -Name "Bar"201 # Contrary to -Name and -FullyQualifiedName removing a non imported module works using ModuleInfo202 { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw203 { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw204 }205}206 207Describe "Remove-Module : module is readOnly | Constant" -Tags "CI" {208 209 BeforeAll {210 Remove-Module -Force -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue211 212 New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null213 New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null214 New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null215 216 New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo_ro.psd1"217 New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo_rw.psd1"218 New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar_rw.psd1"219 New-ModuleManifest -Path "$testdrive\Modules\Baz\Const_module.psd1"220 221 New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo_ro.psm1" > $null222 New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo_rw.psm1" > $null223 New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar_rw.psm1" > $null224 New-Item -ItemType File -Path "$testdrive\Modules\Baz\Const_module.psm1" > $null225 226 $removeReadOnlyModulesTestCases = @(227 # Simple patterns228 @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Const_module", "Foo_ro", "Foo_rw"}229 @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Const_module", "Foo_ro"}230 @{ NamesToRemove = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Const_module", "Foo_ro"}231 232 # Regex patterns233 @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Const_module", "Foo_ro"}234 @{ NamesToRemove = "Foo_*", "Bar_*"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Const_module", "Foo_ro"}235 )236 237 $removeForceReadOnlyModulesTestCases = @(238 # Simple patterns239 @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = "Foo_ro"; ShouldBePresent = "Bar_rw", "Const_module", "Foo_rw"}240 @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Const_module"}241 @{ NamesToRemove = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBePresent = "Const_module"}242 243 # Regex patterns244 @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Const_module"}245 @{ NamesToRemove = "Foo_*", "Bar_*"; ShouldBeRemoved = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBePresent = "Const_module"}246 )247 248 $removeConstantModulesTestCases = @(249 # Simple patterns250 @{ NamesToRemove = "Const_module"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Const_module", "Foo_ro", "Foo_rw"}251 @{ NamesToRemove = "Const_module", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Const_module"}252 253 # Regex patterns254 @{ NamesToRemove = "Foo_*", "Ba*", "Const*"; ShouldBeRemoved = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBePresent = "Const_module"}255 )256 }257 258 AfterAll {259 Remove-Module -Force -Name "Foo_*", "Ba*" -ErrorAction SilentlyContinue260 }261 262 BeforeEach {263 Import-Module -Name "$testdrive\Modules\Foo\Foo_ro.psd1" -Force264 (Get-Module -Name "Foo_ro").AccessMode = "readOnly"265 Import-Module -Name "$testdrive\Modules\Foo\Foo_rw.psd1" -Force266 Import-Module -Name "$testdrive\Modules\Bar\Bar_rw.psd1" -Force267 268 # If this test is run again in the same session, this test module269 # will already be loaded and can't be removed because it sets270 # AccessMode to Constant, so only import this test module and271 # set AccessMode if it isn't already loaded272 if ($null -eq (Get-Module -Name "Const_module")) {273 Import-Module -Name "$testdrive\Modules\Baz\Const_module.psd1" -Force274 (Get-Module -Name "Const_module").AccessMode = "Constant"275 }276 }277 278 It "Remove-Module (ReadOnly modules): <NamesToRemove>" -TestCases $removeReadOnlyModulesTestCases {279 param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)280 281 (Get-Module -Name "Bar_rw", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Foo_ro", "Foo_rw"282 283 { Remove-Module -Name $NamesToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsReadOnly,Microsoft.PowerShell.Commands.RemoveModuleCommand"284 { Remove-Module -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw285 286 if ($ShouldBeRemoved) {287 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty288 }289 290 if ($ShouldBePresent) {291 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent292 }293 }294 295 It "Remove-Module -Force (ReadOnly modules): <NamesToRemove>" -TestCases $removeForceReadOnlyModulesTestCases {296 param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)297 298 (Get-Module -Name "Bar_rw", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Foo_ro", "Foo_rw"299 300 { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Not -Throw301 302 if ($ShouldBeRemoved) {303 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty304 }305 306 if ($ShouldBePresent) {307 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent308 }309 }310 311 It "Remove-Module -Force (Constant modules): <NamesToRemove>" -TestCases $removeConstantModulesTestCases {312 param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent)313 314 (Get-Module -Name "Bar_rw", "Const_module", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Const_module", "Foo_ro", "Foo_rw"315 316 { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsConstant,Microsoft.PowerShell.Commands.RemoveModuleCommand"317 { Remove-Module -Force -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw318 319 if ($ShouldBeRemoved) {320 (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty321 }322 323 if ($ShouldBePresent) {324 (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent325 }326 }327}328 329Describe "Remove-Module : module provides the PSDrive for current PS Session" -Tags "CI" {330 It "Remove-Module : module provides the PSDrive for current PS Session" {331 332 $module = Get-Module (Join-Path $PSHOME "System.Management.Automation.dll") -ListAvailable333 { Remove-Module $module -ErrorAction Stop } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.RemoveModuleCommand"334 }335}336 337Describe "Remove-Module : module contains nested modules" -Tags "CI" {338 339 BeforeAll {340 Remove-Module -Force -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue341 342 New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null343 New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null344 New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null345 346 New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo.psm1" > $null347 New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null348 New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz.psm1" > $null349 350 Set-Content -Path "$testdrive\Modules\Foo\Foo.psm1" -Value "function FooFunc {}"351 Set-Content -Path "$testdrive\Modules\Bar\Bar.psm1" -Value "function BarFunc {}"352 }353 354 It "Remove-Module : module contains nested modules" {355 New-ModuleManifest "$testdrive\Modules\Bar\Bar.psd1" -RootModule "./Bar.psm1" -FunctionsToExport "BarFunc"356 New-ModuleManifest "$testdrive\Modules\Foo\Foo.psd1" -NestedModules "../Bar/Bar.psd1" -FunctionsToExport "BarFunc"357 358 Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force359 (Get-Module -Name "Foo").Name | Should -BeExactly "Foo"360 361 { Get-Command BarFunc -ErrorAction Stop } | Should -Not -Throw362 { Remove-Module -Name "Foo" -ErrorAction Stop } | Should -Not -Throw363 { Get-Command BarFunc -ErrorAction Stop } | Should -Throw364 (Get-Module -Name "Foo").Name | Should -BeNullOrEmpty365 }366 367 It "Remove-Module : module contains nested modules with circular dependencies" {368 New-ModuleManifest "$testdrive\Modules\Bar\Bar.psd1" -RootModule "Bar" -FunctionsToExport "BarFunc" -NestedModules "Bar"369 370 Import-Module "$testdrive\Modules\Bar\Bar.psd1" -Force371 (Get-Module -Name "Bar").Name | Should -BeExactly "Bar"372 373 { Get-Command BarFunc -ErrorAction Stop } | Should -Not -Throw374 { Remove-Module -Name "Bar" -ErrorAction Stop } | Should -Not -Throw375 { Get-Command BarFunc -ErrorAction Stop } | Should -Throw376 (Get-Module -Name "Bar").Name | Should -BeNullOrEmpty377 }378 379 It "Remove-Module : modules are required by other modules" {380 New-ModuleManifest "$testdrive\Modules\Bar\Bar.psd1"381 New-ModuleManifest "$testdrive\Modules\Foo\Foo.psd1" -RequiredModules "Bar"382 383 Import-Module "$testdrive\Modules\Bar\Bar.psd1" -Force384 Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force385 (Get-Module -Name "Bar").Name | Should -BeExactly "Bar"386 (Get-Module -Name "Foo").Name | Should -BeExactly "Foo"387 388 {Remove-Module "Foo" -ErrorAction Stop } | Should -Not -Throw389 Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force390 391 { Remove-Module "Bar" -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsRequired,Microsoft.PowerShell.Commands.RemoveModuleCommand"392 }393}394 395Describe "Remove-Module core module on module path by name" -Tags "CI" {396 $moduleName = "Microsoft.PowerShell.Security"397 398 BeforeEach {399 Import-Module -Name $moduleName -Force400 }401 402 It "should be able to remove a module with using Name switch" {403 (Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName404 405 { Remove-Module -Name $moduleName } | Should -Not -Throw406 (Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty407 }408 409 It "should be able to remove a module with using ModuleInfo switch" {410 (Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName411 412 $a = Get-Module -Name $moduleName413 { Remove-Module -ModuleInfo $a } | Should -Not -Throw414 (Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty415 }416 417 AfterEach {418 Import-Module -Name $moduleName -Force419 }420}421 422Describe "Remove-Module custom module with FullyQualifiedName" -Tags "Feature" {423 BeforeAll {424 $moduleName = 'Banana'425 $moduleVersion = '1.0'426 427 New-Item -Path "$TestDrive/Modules/$moduleName" -ItemType Directory428 New-Item -Path "$TestDrive/Modules/$moduleName/Subanana" -ItemType Directory429 New-Item -Path "$TestDrive/Monkey" -ItemType Directory430 431 $modulePath = "$TestDrive/Modules/$moduleName"432 $moduleName = 'Banana'433 $moduleVersion = '1.0'434 $manifestPath = Join-Path $modulePath "$moduleName.psd1"435 New-ModuleManifest -Path $manifestPath -ModuleVersion $moduleVersion436 437 $testCases = @(438 @{ ModPath = "$TestDrive\Modules/$moduleName" }439 @{ ModPath = "$TestDrive/Modules\$moduleName/$moduleName.psd1" }440 )441 442 It "Removes a module with fully qualified name with path <ModPath>" -TestCases $testCases -Pending {443 param([string]$ModPath)444 445 Get-Module $moduleName | Remove-Module446 447 $m = Import-Module $modulePath -PassThru448 449 $m.Name | Should -Be $moduleName450 $m.Version | Should -Be $moduleVersion451 $m.Path | Should -Be $manifestPath452 453 Remove-Module -FullyQualifiedName @{ ModuleName = $ModPath; RequiredVersion = $moduleVersion } -ErrorAction Stop454 455 Get-Module $moduleName | Should -HaveCount 0 -Because "The module should have been removed by its path"456 }457 }458}459 