MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Get-HotFix Tests" -Tag CI {5 BeforeAll {6 $originalDefaultParameterValues = $PSDefaultParameterValues.Clone()7 8 $skip = $false9 if (!$IsWindows) {10 $skip = $true11 }12 elseif (Test-IsWindowsArm64) {13 # Win32Exception: Failed to load required native library 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\wminet_utils.dll'.14 Write-Verbose "needed provider not on ARM64, skipping tests" -Verbose15 $PSDefaultParameterValues["it:skip"] = $true16 return17 }18 else {19 # skip the tests if there are no hotfixes returned20 $qfe = Get-CimInstance Win32_QuickFixEngineering21 if ($qfe.Count -eq 0) {22 $skip = $true23 }24 }25 26 $PSDefaultParameterValues["it:skip"] = $skip27 }28 29 AfterAll {30 $global:PSDefaultParameterValues = $originalDefaultParameterValues31 }32 33 It "Get-HotFix will enumerate all QFEs" {34 $hotfix = Get-HotFix35 $hotfix.Count | Should -Be $qfe.Count36 }37 38 It "Get-HotFix can filter on -Id" {39 $testQfe = $qfe[0]40 41 $hotfix = Get-HotFix -Id $testQfe.HotFixID42 $hotfix.HotFixID | Should -BeExactly $testQfe.HotFixID43 $hotfix.Description | Should -BeExactly $testQfe.Description44 }45 46 It "Get-HotFix can filter on -Description" {47 $testQfes = $qfe | Where-Object { $_.Description -eq 'Update' }48 if ($testQfes.Count -gt 0) {49 $hotfixes = Get-HotFix -Description 'Update'50 }51 elseif ($qfe.Count -gt 0) {52 $description = $qfe[0].Description53 $testQfes = $qfe | Where-Object { $_.Description -eq $description }54 $hotfixes = Get-HotFix -Desscription $description55 }56 57 # if no applicable qfes are found on test system, this test will still58 # pass as both will have count 059 60 $hotfixes.Count | Should -Be $testQfes.Count61 }62 63 It "Get-HotFix can use -ComputerName" {64 $hotfixes = Get-HotFix -ComputerName localhost65 $hotfixes.Count | Should -Be $qfe.Count66 }67 68 It "Get-Hotfix can accept ComputerName via pipeline" {69 { [PSCustomObject]@{ComputerName = 'UnavailableComputer'} | Get-HotFix } | Should -Throw -ErrorId 'Microsoft.PowerShell.Commands.GetHotFixCommand'70 [PSCustomObject]@{ComputerName = 'localhost'} | Get-HotFix | Should -Not -BeNullOrEmpty71 }72}73 