refactor(tests): streamline test cases

This commit is contained in:
Jeffrey
2026-10-25 21:29:44 +01:00
parent 74648cbe26
commit 72ab1f348c
14 changed files with 75 additions and 94 deletions
@@ -30,13 +30,6 @@ Describe 'FeatureId parameter contracts' {
$missing | Should -HaveCount 0 -Because ($missing -join ', ') $missing | Should -HaveCount 0 -Because ($missing -join ', ')
} }
It 'declares every FeatureId as a parameter on Scripts/Get.ps1' {
$parameterNames = Get-ScriptParameterNames -Path $script:GetScriptPath
$missing = @($script:Features.FeatureId | Where-Object { $parameterNames -notcontains $_ })
$missing | Should -HaveCount 0 -Because ($missing -join ', ')
}
It 'keeps Scripts/Get.ps1 aligned with Win11Debloat.ps1 plus launcher-only switches' { It 'keeps Scripts/Get.ps1 aligned with Win11Debloat.ps1 plus launcher-only switches' {
$win11DebloatParameters = Get-ScriptParameterNames -Path $script:Win11DebloatPath $win11DebloatParameters = Get-ScriptParameterNames -Path $script:Win11DebloatPath
$getParameters = Get-ScriptParameterNames -Path $script:GetScriptPath $getParameters = Get-ScriptParameterNames -Path $script:GetScriptPath
+12 -5
View File
@@ -15,16 +15,23 @@ Describe 'Import-JsonFile' {
$result.Name | Should -Be 'Example configuration' $result.Name | Should -Be 'Example configuration'
} }
It 'parses the <Kind> settings fixture' -ForEach @( It 'parses the default settings fixture' {
@{ Kind = 'default'; FileName = 'DefaultSettings.Valid.json' } $result = Import-JsonFile -filePath (Join-Path $script:FixturePath 'DefaultSettings.Valid.json') -expectedVersion '1.0'
@{ Kind = 'last-used'; FileName = 'LastUsedSettings.Valid.json' }
) {
$result = Import-JsonFile -filePath (Join-Path $script:FixturePath $FileName) -expectedVersion '1.0'
$result.Settings | Should -Not -BeNullOrEmpty $result.Settings | Should -Not -BeNullOrEmpty
$result.Settings[0].Name | Should -Be 'Supported' $result.Settings[0].Name | Should -Be 'Supported'
} }
It 'parses a single last-used setting and preserves its Boolean value' {
$result = Import-JsonFile -filePath (Join-Path $script:FixturePath 'LastUsedSettings.Valid.json') -expectedVersion '1.0'
$result.Settings | Should -HaveCount 1
$result.Settings[0].Name | Should -Be 'Supported'
$result.Settings[0].Value | Should -BeOfType ([bool])
$result.Settings[0].Value | Should -BeTrue
Should -Invoke Write-Error -Times 0 -Exactly
}
It 'returns null and reports an error for <Case>' -ForEach @( It 'returns null and reports an error for <Case>' -ForEach @(
@{ Case = 'a version mismatch'; FileName = 'Config.VersionMismatch.json'; ExpectedVersion = '1.0'; Optional = $false; Error = 'version mismatch' } @{ Case = 'a version mismatch'; FileName = 'Config.VersionMismatch.json'; ExpectedVersion = '1.0'; Optional = $false; Error = 'version mismatch' }
@{ Case = 'invalid JSON'; FileName = 'Config.Invalid.json'; ExpectedVersion = $null; Optional = $false; Error = 'Failed to parse JSON file' } @{ Case = 'invalid JSON'; FileName = 'Config.Invalid.json'; ExpectedVersion = $null; Optional = $false; Error = 'Failed to parse JSON file' }
+6 -14
View File
@@ -106,6 +106,7 @@ Describe 'Invoke-FeatureApply' {
Mock Get-Process { @() } Mock Get-Process { @() }
Mock Stop-Process { param($InputObject) } Mock Stop-Process { param($InputObject) }
Mock Write-Host {} Mock Write-Host {}
Mock Write-Warning {}
} }
It 'imports a registry-backed feature' { It 'imports a registry-backed feature' {
@@ -164,7 +165,6 @@ Describe 'Invoke-FeatureApply' {
It 'returns false when applying a feature throws' { It 'returns false when applying a feature throws' {
Mock Invoke-ForceRemoveEdge { throw 'access denied' } Mock Invoke-ForceRemoveEdge { throw 'access denied' }
Mock Write-Warning {}
Invoke-FeatureApply -FeatureId 'ForceRemoveEdge' | Should -BeFalse Invoke-FeatureApply -FeatureId 'ForceRemoveEdge' | Should -BeFalse
@@ -172,8 +172,6 @@ Describe 'Invoke-FeatureApply' {
} }
It 'returns false for an unknown feature' { It 'returns false for an unknown feature' {
Mock Write-Warning {}
Invoke-FeatureApply -FeatureId 'Unknown' | Should -BeFalse Invoke-FeatureApply -FeatureId 'Unknown' | Should -BeFalse
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -match "Unknown feature 'Unknown'.*could not be applied" } Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -match "Unknown feature 'Unknown'.*could not be applied" }
@@ -195,21 +193,16 @@ Describe 'Invoke-FeatureApply' {
Should -Invoke Stop-Process -Times 0 -Exactly Should -Invoke Stop-Process -Times 0 -Exactly
} }
It 'stops widget processes before removing widget packages' { It 'stops widget processes without a confirmation prompt before removing widget packages' {
$widget = [PSCustomObject]@{ Name = 'WidgetService' } $calls = [System.Collections.Generic.List[string]]::new()
Mock Get-Process { $widget }
Invoke-FeatureApply -FeatureId 'DisableWidgets'
Should -Invoke Stop-Process -Times 1 -Exactly
}
It 'stops widget processes without a confirmation prompt' {
Mock Get-Process { [PSCustomObject]@{ Name = 'Widgets' } } Mock Get-Process { [PSCustomObject]@{ Name = 'Widgets' } }
Mock Stop-Process { $calls.Add('Stop') }
Mock Remove-SelectedApps { $calls.Add('Remove'); $true }
Invoke-FeatureApply -FeatureId 'DisableWidgets' Invoke-FeatureApply -FeatureId 'DisableWidgets'
Should -Invoke Stop-Process -Times 1 -Exactly -ParameterFilter { $Force -and $ErrorAction -eq 'SilentlyContinue' } Should -Invoke Stop-Process -Times 1 -Exactly -ParameterFilter { $Force -and $ErrorAction -eq 'SilentlyContinue' }
@($calls) | Should -Be @('Stop', 'Remove')
} }
It 'enables the expected optional Windows features' { It 'enables the expected optional Windows features' {
@@ -535,7 +528,6 @@ Describe 'Invoke-AllChanges' {
$script:Params = @{ CustomApply = $true } $script:Params = @{ CustomApply = $true }
$script:UndoParams = @{} $script:UndoParams = @{}
Mock Invoke-ApplyFeatures { $script:AppRemovalVerificationUnavailable = $true } Mock Invoke-ApplyFeatures { $script:AppRemovalVerificationUnavailable = $true }
Mock Write-Warning {}
Invoke-AllChanges Invoke-AllChanges
+17 -10
View File
@@ -15,11 +15,6 @@ Describe 'Invoke-NonBlocking' {
$result | Should -Be @(1, 2, 3) $result | Should -Be @(1, 2, 3)
} }
It 'stops a timed CLI operation and reports a timeout' {
{ Invoke-NonBlocking -ScriptBlock { Start-Sleep -Seconds 3 } -TimeoutSeconds 1 } |
Should -Throw 'Operation timed out after 1 seconds'
}
It 'stops a timed GUI operation and reports a timeout' { It 'stops a timed GUI operation and reports a timeout' {
$script:GuiWindow = [PSCustomObject]@{} $script:GuiWindow = [PSCustomObject]@{}
Mock Invoke-DoEvents {} Mock Invoke-DoEvents {}
@@ -30,11 +25,23 @@ Describe 'Invoke-NonBlocking' {
It 'uses a runspace and pumps UI events when a GUI window is present' { It 'uses a runspace and pumps UI events when a GUI window is present' {
$script:GuiWindow = [PSCustomObject]@{} $script:GuiWindow = [PSCustomObject]@{}
Mock Invoke-DoEvents {} $gate = [System.Threading.ManualResetEventSlim]::new($false)
Mock Invoke-DoEvents { $gate.Set() }
$result = Invoke-NonBlocking -ScriptBlock { 'done' } try {
$result | Should -Be 'done' $result = Invoke-NonBlocking -ScriptBlock {
param($Event)
if (-not $Event.Wait(5000)) { throw 'UI events were not pumped' }
[System.Threading.Thread]::CurrentThread.ManagedThreadId
} -ArgumentList @($gate) -TimeoutSeconds 5
$result | Should -BeOfType ([int])
$result | Should -Not -Be ([System.Threading.Thread]::CurrentThread.ManagedThreadId)
Should -Invoke Invoke-DoEvents -Times 1
}
finally {
$gate.Dispose()
}
} }
It 'surfaces non-terminating errors from a runspace' { It 'surfaces non-terminating errors from a runspace' {
@@ -47,10 +54,10 @@ Describe 'Invoke-NonBlocking' {
Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter { $ErrorRecord.Exception.Message -match 'runspace failure' } Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter { $ErrorRecord.Exception.Message -match 'runspace failure' }
} }
It 'remains usable after a timed operation is stopped' { It 'stops a timed CLI operation, reports a timeout, and remains usable afterward' {
{ Invoke-NonBlocking -ScriptBlock { Start-Sleep -Seconds 3 } -TimeoutSeconds 1 } | { Invoke-NonBlocking -ScriptBlock { Start-Sleep -Seconds 3 } -TimeoutSeconds 1 } |
Should -Throw 'Operation timed out after 1 seconds' Should -Throw 'Operation timed out after 1 seconds'
Invoke-NonBlocking -ScriptBlock { 'next operation' } | Should -Be 'next operation' Invoke-NonBlocking -ScriptBlock { 'next operation' } -TimeoutSeconds 5 | Should -Be 'next operation'
} }
} }
@@ -56,7 +56,6 @@ Describe 'Invoke-SystemRestorePoint' {
$expectedImport = [regex]::Escape('Scripts/Features/Invoke-SystemRestorePoint.ps1') $expectedImport = [regex]::Escape('Scripts/Features/Invoke-SystemRestorePoint.ps1')
$entryPoint | Should -Match $expectedImport $entryPoint | Should -Match $expectedImport
Get-Command Invoke-SystemRestorePoint | Should -Not -BeNullOrEmpty
} }
It 'enables disabled System Restore before creating the point in silent mode' { It 'enables disabled System Restore before creating the point in silent mode' {
+1 -13
View File
@@ -163,19 +163,6 @@ Describe 'Get-PendingTweakActions' {
$map['DisableTelemetryCheckBox'].DesiredValue | Should -BeTrue $map['DisableTelemetryCheckBox'].DesiredValue | Should -BeTrue
} }
It 'matches a mapping whose CategoryId fell back to its Name, for a category missing CategoryId' {
$window = New-TestWindow
$checkBox = New-Object System.Windows.Controls.CheckBox
$checkBox.Visibility = 'Visible'
$window.RegisterName('LegacyCheckBox', $checkBox)
# New-DynamicTweakControls falls back to Name when a category has no CategoryId of its own.
$script:UiControlMappings = @{ LegacyCheckBox = [PSCustomObject]@{ CategoryId = 'Legacy Category'; Type = 'feature'; FeatureId = 'SomeFeature' } }
$map = Get-CategoryTweakPresetMap -Window $window -CategoryId 'Legacy Category'
$map['LegacyCheckBox'].ControlType | Should -Be 'CheckBox'
}
It 'updates navigation visibility and progress indicators for an interior tab' { It 'updates navigation visibility and progress indicators for an interior tab' {
$window = New-TestWindow $window = New-TestWindow
$tabControl = New-Object System.Windows.Controls.TabControl $tabControl = New-Object System.Windows.Controls.TabControl
@@ -250,6 +237,7 @@ Describe 'Get-AppRemovalScopeTarget' {
} }
It 'returns null for an unrecognized ComboBoxItem Name' { It 'returns null for an unrecognized ComboBoxItem Name' {
Mock Write-Warning {}
$combo = New-Object System.Windows.Controls.ComboBox $combo = New-Object System.Windows.Controls.ComboBox
$item = New-Object System.Windows.Controls.ComboBoxItem $item = New-Object System.Windows.Controls.ComboBoxItem
$item.Name = 'SomeUnrelatedControl' $item.Name = 'SomeUnrelatedControl'
+24
View File
@@ -43,6 +43,30 @@ BeforeAll {
} }
} }
Describe 'Legacy tweak categories' {
It 'uses the category Name as CategoryId when building controls without a CategoryId' {
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
$feature = $script:Features['DisableTelemetry'] | Select-Object *
$feature.Category = 'Legacy Category'
$legacyCatalog = [PSCustomObject]@{
Categories = @([PSCustomObject]@{ Name = 'Legacy Category'; Icon = '&#xE72E;' })
Features = @($feature)
}
Mock Import-JsonFile { $legacyCatalog } -ParameterFilter { $filePath -eq $script:FeaturesFilePath }
$window = New-LanguageTestWindow
New-DynamicTweakControls -Window $window -WinVersion 26100
$controlName = 'Feature_DisableTelemetry_Combo'
$script:UiControlMappings.Count | Should -Be 1
$script:UiControlMappings[$controlName].CategoryId | Should -Be 'Legacy Category'
$map = Get-CategoryTweakPresetMap -Window $window -CategoryId 'Legacy Category'
$map.Count | Should -Be 1
$map[$controlName].Control | Should -Be ($window.FindName($controlName))
$map[$controlName].DesiredValue | Should -BeTrue
}
}
Describe 'Language changes on existing controls' { Describe 'Language changes on existing controls' {
BeforeEach { BeforeEach {
$script:Lang = Import-LanguageFile -LanguageCode 'en-US' $script:Lang = Import-LanguageFile -LanguageCode 'en-US'
+2 -2
View File
@@ -231,6 +231,7 @@ Describe 'Registry backup deletion permissions' {
Describe 'Executable registry backup values' { Describe 'Executable registry backup values' {
BeforeEach { BeforeEach {
Mock Write-Host {}
$script:Params = @{} $script:Params = @{}
$script:RegfilesPath = Join-Path $PSScriptRoot '..\Regfiles' $script:RegfilesPath = Join-Path $PSScriptRoot '..\Regfiles'
$script:Features = @{} $script:Features = @{}
@@ -638,6 +639,7 @@ Describe 'Executable registry restore confirmation' {
$script:Features = @{} $script:Features = @{}
foreach ($feature in $script:FeatureCatalog.Features) { $script:Features[$feature.FeatureId] = $feature } foreach ($feature in $script:FeatureCatalog.Features) { $script:Features[$feature.FeatureId] = $feature }
Mock Write-Error {} Mock Write-Error {}
Mock Write-Host {}
Mock Restore-RegistryKeySnapshot {} Mock Restore-RegistryKeySnapshot {}
Mock Invoke-WithLoadedRestoreHive { Mock Invoke-WithLoadedRestoreHive {
param($Target, $ScriptBlock, $ArgumentObject) param($Target, $ScriptBlock, $ArgumentObject)
@@ -678,7 +680,6 @@ Describe 'Executable registry restore confirmation' {
@{ Response = $null } @{ Response = $null }
@{ Response = 'true' } @{ Response = 'true' }
) { ) {
Mock Write-Host {}
$backup = New-ExecutableTestBackup $backup = New-ExecutableTestBackup
(Restore-RegistryBackupState -Backup $backup -ConfirmUntrustedValues { $Response }).Result | Should -BeFalse (Restore-RegistryBackupState -Backup $backup -ConfirmUntrustedValues { $Response }).Result | Should -BeFalse
Should -Invoke Write-Host -Times 1 -Exactly -ParameterFilter { $Object -like 'Registry restore canceled:*' } Should -Invoke Write-Host -Times 1 -Exactly -ParameterFilter { $Object -like 'Registry restore canceled:*' }
@@ -687,7 +688,6 @@ Describe 'Executable registry restore confirmation' {
} }
It 'shows all mismatches before writes and restores only after explicit approval' { It 'shows all mismatches before writes and restores only after explicit approval' {
Mock Write-Host {}
$backup = New-ExecutableTestBackup $backup = New-ExecutableTestBackup
$backup.RegistryKeys += (New-ExecutableTestBackup -Path 'HKEY_CLASSES_ROOT\ms-gamebarservices\shell\open\command' -Data 'custom.exe').RegistryKeys $backup.RegistryKeys += (New-ExecutableTestBackup -Path 'HKEY_CLASSES_ROOT\ms-gamebarservices\shell\open\command' -Data 'custom.exe').RegistryKeys
$script:confirmationCount = 0 $script:confirmationCount = 0
+2 -22
View File
@@ -100,26 +100,6 @@ Describe 'Get-SelectedRegistryFeaturesForBackupValidation' {
} }
} }
Describe 'Test-RegistryValueKindNameSupported' {
It 'accepts supported registry value kind <KindName>' -ForEach @(
@{ KindName = 'dword' }
@{ KindName = 'QWord' }
@{ KindName = 'MultiString' }
) {
Test-RegistryValueKindNameSupported -KindName $KindName | Should -BeTrue
}
It 'rejects <Case>' -ForEach @(
@{ Case = 'a null kind name'; KindName = $null }
@{ Case = 'an empty kind name'; KindName = '' }
@{ Case = 'the Unknown registry kind'; KindName = 'Unknown' }
@{ Case = 'the unsupported None registry kind'; KindName = 'None' }
@{ Case = 'an invalid registry kind name'; KindName = 'NotARegistryValueKind' }
) {
Test-RegistryValueKindNameSupported -KindName $KindName | Should -BeFalse
}
}
Describe 'Test-RegistryValueDataMatchesKind' { Describe 'Test-RegistryValueDataMatchesKind' {
It 'accepts <Case>' -ForEach @( It 'accepts <Case>' -ForEach @(
@{ Case = 'the largest DWord'; Kind = 'DWord'; Data = [uint32]::MaxValue } @{ Case = 'the largest DWord'; Kind = 'DWord'; Data = [uint32]::MaxValue }
@@ -156,11 +136,11 @@ Describe 'Get-NormalizedRegistryValueName' {
} }
Describe 'Test-RegistryValueKindNameSupported' { Describe 'Test-RegistryValueKindNameSupported' {
It 'rejects unsupported kind <KindName>' -ForEach @('99', '-2', 'Unknown', 'None', '') { It 'rejects unsupported kind <KindName>' -ForEach @('99', '-2', 'Unknown', 'None', '', $null, 'NotARegistryValueKind') {
Test-RegistryValueKindNameSupported -KindName $_ | Should -BeFalse Test-RegistryValueKindNameSupported -KindName $_ | Should -BeFalse
} }
It 'accepts defined kind <KindName>' -ForEach @('String', 'expandstring', 'Binary', 'DWord', 'QWord', 'MultiString', '1') { It 'accepts defined kind <KindName>' -ForEach @('String', 'expandstring', 'Binary', 'DWord', 'dword', 'QWord', 'MultiString', '1') {
Test-RegistryValueKindNameSupported -KindName $_ | Should -BeTrue Test-RegistryValueKindNameSupported -KindName $_ | Should -BeTrue
} }
} }
+2 -2
View File
@@ -370,7 +370,7 @@ Describe 'Remove-AppxApp' {
Mock Invoke-NonBlocking { param($ScriptBlock, $ArgumentList) & $ScriptBlock @ArgumentList } Mock Invoke-NonBlocking { param($ScriptBlock, $ArgumentList) & $ScriptBlock @ArgumentList }
Mock Get-AppxPackage { Write-Error 'access denied' } Mock Get-AppxPackage { Write-Error 'access denied' }
Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' | Should -BeFalse Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' 2>$null | Should -BeFalse
} }
It 'returns false when package removal reports a non-terminating error' { It 'returns false when package removal reports a non-terminating error' {
@@ -378,7 +378,7 @@ Describe 'Remove-AppxApp' {
Mock Get-AppxPackage { [PSCustomObject]@{ PackageFullName = 'One.App_1.0' } } Mock Get-AppxPackage { [PSCustomObject]@{ PackageFullName = 'One.App_1.0' } }
Mock Remove-AppxPackage { Write-Error 'access denied' } Mock Remove-AppxPackage { Write-Error 'access denied' }
Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' | Should -BeFalse Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' 2>$null | Should -BeFalse
} }
It 'returns false and reports a terminating Appx failure' { It 'returns false and reports a terminating Appx failure' {
+1
View File
@@ -10,6 +10,7 @@ BeforeAll {
Describe 'Get-StartMenuUserNameFromPath' { Describe 'Get-StartMenuUserNameFromPath' {
BeforeEach { BeforeEach {
Mock Write-Host {}
# Restore copies are named to the second; clear them so tests sharing $TestDrive cannot see each other's copy # Restore copies are named to the second; clear them so tests sharing $TestDrive cannot see each other's copy
Get-ChildItem -LiteralPath $TestDrive -Filter 'Win11Debloat-StartRestore-*.bak' | Remove-Item -Force Get-ChildItem -LiteralPath $TestDrive -Filter 'Win11Debloat-StartRestore-*.bak' | Remove-Item -Force
} }
+4 -14
View File
@@ -165,14 +165,6 @@ Describe 'Get-DeploymentCategoryDetailString' {
Get-DeploymentCategoryDetailString -DeploymentSettings $settings | Should -Not -Match 'ImportExportOptionRegistryBackup' Get-DeploymentCategoryDetailString -DeploymentSettings $settings | Should -Not -Match 'ImportExportOptionRegistryBackup'
} }
}
Describe 'Get-DeploymentCategoryDetailString with unsupported values' {
BeforeEach {
$warnings = [System.Collections.Generic.List[string]]::new()
Mock Write-Warning { $warnings.Add([string]$Message) }
}
It 'does not list the registry backup for an unsupported SkipRegistryBackup value, and does not warn' { It 'does not list the registry backup for an unsupported SkipRegistryBackup value, and does not warn' {
$settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = 'yes' }) $settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = 'yes' })
@@ -180,11 +172,9 @@ Describe 'Get-DeploymentCategoryDetailString with unsupported values' {
$warnings | Should -HaveCount 0 $warnings | Should -HaveCount 0
} }
It 'lists the registry backup when SkipRegistryBackup is false or missing' -ForEach @( It 'lists the registry backup when SkipRegistryBackup is missing' {
@{ Settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = $false }) } $settings = @([PSCustomObject]@{ Name = 'RestartExplorer'; Value = $true })
@{ Settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = 'false' }) }
@{ Settings = @([PSCustomObject]@{ Name = 'RestartExplorer'; Value = $true }) } Get-DeploymentCategoryDetailString -DeploymentSettings $settings | Should -Match 'ImportExportOptionRegistryBackup'
) {
Get-DeploymentCategoryDetailString -DeploymentSettings $Settings | Should -Match 'ImportExportOptionRegistryBackup'
} }
} }
+2 -2
View File
@@ -34,6 +34,7 @@ Describe 'Disable-TelemetryScheduledTasks' {
} }
Mock Invoke-NonBlocking { @{ Success = $true; Status = 'Disabled' } } Mock Invoke-NonBlocking { @{ Success = $true; Status = 'Disabled' } }
Mock Write-Host {} Mock Write-Host {}
Mock Write-Warning {}
} }
It 'dispatches every task to the non-blocking scheduler' { It 'dispatches every task to the non-blocking scheduler' {
@@ -175,7 +176,6 @@ Describe 'Disable-TelemetryScheduledTasks' {
It 'returns false for an unknown scheduler result' { It 'returns false for an unknown scheduler result' {
Mock Get-TelemetryScheduledTasks { @(@{ Path = '\Microsoft\Windows\Test\'; Name = 'Telemetry' }) } Mock Get-TelemetryScheduledTasks { @(@{ Path = '\Microsoft\Windows\Test\'; Name = 'Telemetry' }) }
Mock Invoke-NonBlocking { $null } Mock Invoke-NonBlocking { $null }
Mock Write-Warning {}
Disable-TelemetryScheduledTasks | Should -BeFalse Disable-TelemetryScheduledTasks | Should -BeFalse
Should -Invoke Write-Warning -Times 1 -Exactly Should -Invoke Write-Warning -Times 1 -Exactly
@@ -194,6 +194,7 @@ Describe 'Enable-TelemetryScheduledTasks' {
} }
Mock Invoke-NonBlocking { @{ Success = $true; Status = 'Enabled' } } Mock Invoke-NonBlocking { @{ Success = $true; Status = 'Enabled' } }
Mock Write-Host {} Mock Write-Host {}
Mock Write-Warning {}
} }
It 'dispatches every task to the non-blocking scheduler' { It 'dispatches every task to the non-blocking scheduler' {
@@ -305,7 +306,6 @@ Describe 'Enable-TelemetryScheduledTasks' {
It 'returns false when the scheduler throws' { It 'returns false when the scheduler throws' {
Mock Get-TelemetryScheduledTasks { @(@{ Path = '\Microsoft\Windows\Test\'; Name = 'Telemetry' }) } Mock Get-TelemetryScheduledTasks { @(@{ Path = '\Microsoft\Windows\Test\'; Name = 'Telemetry' }) }
Mock Invoke-NonBlocking { throw 'scheduler unavailable' } Mock Invoke-NonBlocking { throw 'scheduler unavailable' }
Mock Write-Warning {}
Enable-TelemetryScheduledTasks | Should -BeFalse Enable-TelemetryScheduledTasks | Should -BeFalse
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -match 'scheduler unavailable' } Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -match 'scheduler unavailable' }
+2 -2
View File
@@ -22,6 +22,7 @@ BeforeAll {
Describe 'Enable-WindowsFeature' { Describe 'Enable-WindowsFeature' {
BeforeEach { BeforeEach {
Mock Write-Warning {}
$script:Params = @{} $script:Params = @{}
Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $true; Output = $null; Error = $null } } Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $true; Output = $null; Error = $null } }
Mock Write-Host {} Mock Write-Host {}
@@ -65,7 +66,6 @@ Describe 'Enable-WindowsFeature' {
It 'reports the worker error and returns false' { It 'reports the worker error and returns false' {
Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $false; Output = $null; Error = 'feature servicing failed' } } Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $false; Output = $null; Error = 'feature servicing failed' } }
Mock Write-Warning {}
Enable-WindowsFeature -FeatureName 'Feature.One' | Should -BeFalse Enable-WindowsFeature -FeatureName 'Feature.One' | Should -BeFalse
@@ -96,6 +96,7 @@ Describe 'Enable-WindowsFeature' {
Describe 'Disable-WindowsFeature' { Describe 'Disable-WindowsFeature' {
BeforeEach { BeforeEach {
Mock Write-Warning {}
$script:Params = @{} $script:Params = @{}
Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $true; Output = $null; Error = $null } } Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $true; Output = $null; Error = $null } }
Mock Write-Host {} Mock Write-Host {}
@@ -139,7 +140,6 @@ Describe 'Disable-WindowsFeature' {
It 'reports the worker error and returns false' { It 'reports the worker error and returns false' {
Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $false; Output = $null; Error = 'feature servicing failed' } } Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $false; Output = $null; Error = 'feature servicing failed' } }
Mock Write-Warning {}
Disable-WindowsFeature -FeatureName 'Feature.One' | Should -BeFalse Disable-WindowsFeature -FeatureName 'Feature.One' | Should -BeFalse