Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Microsoft.Windows.Assertion Module #90

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix spelling, Fix tests, Use Ensure when needed
Trenly committed Nov 5, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 69549a54ab5c1940e422d44ef074abf919cdf969
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
@@ -37,3 +37,4 @@ uilt
Windo
ELSPROBLEMS
requ
PDevice
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect/generic_terms.txt
Original file line number Diff line number Diff line change
@@ -12,3 +12,5 @@ worktree
sortby
msft
automerge
pnp
RTX
6 changes: 3 additions & 3 deletions resources/Help/Microsoft.Windows.Assertion/PnPDevice.md
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ The `PnPDevice` DSC Resource allows you to check for specific PnP Devices on the
**Parameter**|**Attribute**|**DataType**|**Description**|**Allowed Values**
:-----|:-----|:-----|:-----|:-----
`FriendlyName`|Optional|String[]|The name of the PnP Device to be found|
`DeviceClass`|Optional|String[]|The PnP Class of the PnP Device to be found.| For exampe: `Display` or `Keyboard` or `PrintQueue`
`DeviceClass`|Optional|String[]|The PnP Class of the PnP Device to be found.| For example: `Display` or `Keyboard` or `PrintQueue`
`Status`|Optional|String]]|The current status of the PnP Device to be found|`OK`, `ERROR`, `DEGRADED`, `UNKNOWN`

## EXAMPLES
@@ -63,9 +63,9 @@ Invoke-DscResource -Name PnPDevice -Method Test -Property $params -ModuleName Mi
```powershell
# Check that a specific device is operational
$params = @{
FrienlyName = 'Follow-You-Printing'
FriendlyName = 'Follow-You-Printing'
DeviceClass = 'PrintQueue'
Status = 'OK'
}
Invoke-DscResource -Name PnPDevice -Method Test -Property $params -ModuleName Microsoft.Windows.Assertion
```
```
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
'OsEditionId',
'SystemArchitecture',
'ProcessorArchitecture',
'HyperVisorPresent',
'HyperVisor',
'OsInstallDate',
'OsVersion',
'CsManufacturer',
@@ -35,7 +35,7 @@
'PSDscResource_OsEditionId',
'PSDscResource_SystemArchitecture',
'PSDscResource_ProcessorArchitecture',
'PSDscResource_HyperVisorPresent',
'PSDscResource_HyperVisor',
'PSDscResource_OsInstallDate',
'PSDscResource_OsVersion',
'PSDscResource_CsManufacturer',
Original file line number Diff line number Diff line change
@@ -101,26 +101,20 @@ class ProcessorArchitecture {
}

[DSCResource()]
class HyperVisorPresent {
class HyperVisor {

[DscProperty(Key)]
[Ensure] $Ensure

[DscProperty(NotConfigurable)]
[bool] $HyperVisorPresent

[HyperVisorPresent] Get() {
$this.HyperVisorPresent = Get-ComputerInfo | Select-Object -ExpandProperty HyperVisorPresent

[HyperVisor] Get() {
return @{
Ensure = $this.Ensure
HyperVisorPresent = $this.HyperVisorPresent
Ensure = (Get-ComputerInfo | Select-Object -ExpandProperty HyperVisorPresent) ? [Ensure]::Present : [Ensure]::Absent
}
}

[bool] Test() {
$currentState = $this.Get()
return $currentState.Ensure -eq $currentState.HyperVisorPresent
return $currentState.Ensure -eq $this.Ensure
}

[void] Set() {
@@ -365,9 +359,9 @@ class PnPDevice {
# It's possible that multiple PNP devices match, but as long as one matches then the assertion succeeds
return @{
Ensure = $pnpDevice ? [Ensure]::Present : [Ensure]::Absent
FriendlyName = $pnpDevice ? $pnpDevice.FriendlyName : $null
DeviceClass = $pnpDevice ? $pnpDevice.Class : $null
Status = $pnpDevice ? $pnpDevice.Status : [PnPDeviceState]::UNKNOWN
FriendlyName = $this.FriendlyName
DeviceClass = $this.DeviceClass
Status = $this.Status
}
}

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
# Licensed under the MIT License.
using module Microsoft.Windows.Assertion

$ErrorActionPreference = "Stop"
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

<#
@@ -11,16 +11,15 @@ Set-StrictMode -Version Latest
#>

BeforeAll {
if ($null -eq (Get-Module -ListAvailable -Name PSDesiredStateConfiguration))
{
if ($null -eq (Get-Module -ListAvailable -Name PSDesiredStateConfiguration)) {
Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck
}
Import-Module Microsoft.Windows.Assertion
}

Describe 'List available DSC resources' {
It 'Shows DSC Resources' {
$expectedDSCResources = "OsEditionId", "SystemArchitecture", "ProcessorArchitecture", "HyperVisorPresent", "OsInstallDate", "OsVersion", "CsManufacturer", "CsModel", "CsDomain", "PowerShellVersion", "PnPDevice"
$expectedDSCResources = 'OsEditionId', 'SystemArchitecture', 'ProcessorArchitecture', 'HyperVisor', 'OsInstallDate', 'OsVersion', 'CsManufacturer', 'CsModel', 'CsDomain', 'PowerShellVersion', 'PnPDevice'
$availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Assertion).Name
$availableDSCResources.length | Should -Be 11
$availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop
@@ -106,25 +105,25 @@ InModuleScope -ModuleName Microsoft.Windows.Assertion {

}

Describe 'HyperVisorPresent' {
Describe 'HyperVisor' {
BeforeAll {
Mock Get-ComputerInfo { return @{HyperVisorPresent = $true } }
}

$script:HyperVisorResource = [HyperVisorPresent]::new()
$script:HyperVisorResource = [HyperVisor]::new()

It 'Get Current Property' -Tag 'Get' {
$initialState = $HyperVisorResource.Get()
$initialState.HyperVisorPresent | Should -Be $true
$initialState.Ensure | Should -Be 'Present'
}

Context 'Test Current Property' -Tag 'Test' {
It 'Should match' {
$HyperVisorResource.Required = $true
$HyperVisorResource.Ensure = 'Present'
$HyperVisorResource.Test() | Should -Be $true
}
It 'Should not match' {
$HyperVisorResource.Required = $false
$HyperVisorResource.Ensure = 'Absent'
$HyperVisorResource.Test() | Should -Be $false
}
}
@@ -332,11 +331,11 @@ InModuleScope -ModuleName Microsoft.Windows.Assertion {
}

# Mock when all parameters are present
Mock Get-PnPDevice -ParameterFilter { $FriendlyName -eq "TestName" -and $DeviceClass -eq "TestClass" -and $Status -eq "OK" } -MockWith { return $script:TestPnPDevice }
Mock Get-PnPDevice -ParameterFilter { $FriendlyName -eq 'TestName' -and $DeviceClass -eq 'TestClass' -and $Status -eq 'OK' } -MockWith { return $script:TestPnPDevice }
# Mock when two parameters are present
Mock Get-PnPDevice -ParameterFilter { $FriendlyName -eq "TestName" -and $DeviceClass -eq "TestClass" -and [String]::IsNullOrWhiteSpace($Status) } -MockWith { return $script:TestPnPDevice }
Mock Get-PnPDevice -ParameterFilter { $FriendlyName -eq 'TestName' -and $DeviceClass -eq 'TestClass' -and [String]::IsNullOrWhiteSpace($Status) } -MockWith { return $script:TestPnPDevice }
# Mock when one parameter is present
Mock Get-PnPDevice -ParameterFilter { $FriendlyName -eq "TestName" -and [String]::IsNullOrWhiteSpace($DeviceClass) -and [String]::IsNullOrWhiteSpace($Status) } -MockWith { return $script:TestPnPDevice }
Mock Get-PnPDevice -ParameterFilter { $FriendlyName -eq 'TestName' -and [String]::IsNullOrWhiteSpace($DeviceClass) -and [String]::IsNullOrWhiteSpace($Status) } -MockWith { return $script:TestPnPDevice }
# Catch-all Mock
Mock Get-PnPDevice -ParameterFilter { } -MockWith { return @{ FriendlyName = $null; Class = $null; Status = 'UNKNOWN' } }
}
@@ -351,42 +350,32 @@ InModuleScope -ModuleName Microsoft.Windows.Assertion {
It 'Should match a device with one property specified' {
$PnPDeviceResource.FriendlyName = 'TestName'
$initialState = $PnPDeviceResource.Get()
$initialState.FriendlyName | Should -Be 'TestName'
$initialState.DeviceClass | Should -Be 'TestClass'
$initialState.Status | Should -Be 'OK'
$initialState.Ensure | Should -Be 'Present'
}
It 'Should match a device with two properties specified' {
$PnPDeviceResource.FriendlyName = 'TestName'
$PnPDeviceResource.DeviceClass = 'TestClass'
$initialState = $PnPDeviceResource.Get()
$initialState.FriendlyName | Should -Be 'TestName'
$initialState.DeviceClass | Should -Be 'TestClass'
$initialState.Status | Should -Be 'OK'
$initialState.Ensure | Should -Be 'Present'
}
It 'Should match a device with all properties specified' {
$PnPDeviceResource.FriendlyName = 'TestName'
$PnPDeviceResource.DeviceClass = 'TestClass'
$PnPDeviceResource.Status = 'OK'
$initialState = $PnPDeviceResource.Get()
$initialState.FriendlyName | Should -Be 'TestName'
$initialState.DeviceClass | Should -Be 'TestClass'
$initialState.Status | Should -Be 'OK'
$initialState.Ensure | Should -Be 'Present'
}
It 'Should not match a device with bad FriendlyName' {
$PnPDeviceResource.FriendlyName = 'Name'
$initialState = $PnPDeviceResource.Get()
!$initialState.FriendlyName | Should -Be $true
!$initialState.DeviceClass | Should -Be $true
$initialState.Status | Should -Be 'UNKNOWN'
$initialState.Ensure | Should -Be 'Absent'
}
It 'Should not match a device with bad status' {
$PnPDeviceResource.FriendlyName = 'TestName'
$PnPDeviceResource.DeviceClass = 'TestClass'
$PnPDeviceResource.Status = 'ERROR'
$initialState = $PnPDeviceResource.Get()
!$initialState.FriendlyName | Should -Be $true
!$initialState.DeviceClass | Should -Be $true
$initialState.Status | Should -Be 'UNKNOWN'
$initialState.Ensure | Should -Be 'Absent'
}
}


Unchanged files with check annotations Beta

use_magic_file: 1
extra_dictionary_limit: 10
extra_dictionaries:
https://github.com/streetsidesoftware/cspell-dicts/raw/098e323325a389a5d1cebcd7770807b9d11d0a17/dictionaries/software-terms/src/software-terms.txt

Check notice on line 80 in .github/workflows/spellCheck.yaml

GitHub Actions / Check Spelling

`Line` matches candidate pattern `(?:\[`?[0-9a-f]+`?\]\(https:/|)/(?:www\.|)github\.com(?:/[^/\s"]+){2,}(?:/[^/\s")]+)(?:[0-9a-f]+(?:[-0-9a-zA-Z/#.]*|)\b|)` (candidate-pattern)
https://raw.githubusercontent.com/streetsidesoftware/cspell-dicts/098e323325a389a5d1cebcd7770807b9d11d0a17/dictionaries/filetypes/src/filetypes.txt

Check notice on line 81 in .github/workflows/spellCheck.yaml

GitHub Actions / Check Spelling

`Line` matches candidate pattern `/[-a-z0-9]+\.githubusercontent\.com/[-a-zA-Z0-9?&=_\/.]*` (candidate-pattern)
https://raw.githubusercontent.com/streetsidesoftware/cspell-dicts/098e323325a389a5d1cebcd7770807b9d11d0a17/dictionaries/powershell/src/powershell.txt
https://raw.githubusercontent.com/streetsidesoftware/cspell-dicts/098e323325a389a5d1cebcd7770807b9d11d0a17/dictionaries/win32/src/generator/win32.txt
https://github.com/streetsidesoftware/cspell-dicts/raw/098e323325a389a5d1cebcd7770807b9d11d0a17/dictionaries/python/src/common_packages.txt
$resultSet = [System.Collections.Generic.List[DotNetToolPackage]]::new()
$listCommand = 'tool list --global'
$installDir = Join-Path -Path $env:USERPROFILE '.dotnet' 'tools'

Check notice on line 142 in resources/Microsoft.DotNet.Dsc/Microsoft.DotNet.Dsc.psm1

GitHub Actions / Check Spelling

`Line` matches candidate pattern `(?:^|[\t ,"'`=(])-[DPWXYLlf](?=[A-Z]{2,}|[A-Z][a-z]|[a-z]{2,})` (candidate-pattern)
if ($PSBoundParameters.ContainsKey('ToolPathDirectory')) {
$listCommand = "tool list --tool-path $ToolPathDirectory"
}
# TaskbarSearchboxMode
if (-not(DoesRegistryKeyPropertyExist -Path $global:SearchRegistryPath -Name $this.SearchboxTaskbarMode)) {

Check notice on line 184 in resources/Microsoft.Windows.Developer/Microsoft.Windows.Developer.psm1

GitHub Actions / Check Spelling

`Line` matches candidate pattern `(?:^|[\t ,"'`=(])-[DPWXYLlf](?=[A-Z]{2,}|[A-Z][a-z]|[a-z]{2,})` (candidate-pattern)
$currentState.SearchboxMode = [SearchBoxMode]::SearchBox
} else {
$value = [int](Get-ItemPropertyValue -Path $global:SearchRegistryPath -Name $this.SearchboxTaskbarMode)
static hidden [string] $MessageDurationProperty = 'MessageDuration'
static [bool] GetShowDynamicScrollbarsStatus() {
if (-not(DoesRegistryKeyPropertyExist -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty))) {

Check notice on line 292 in resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1

GitHub Actions / Check Spelling

`Line` matches candidate pattern `(?:^|[\t ,"'`=(])-[DPWXYLlf](?=[A-Z]{2,}|[A-Z][a-z]|[a-z]{2,})` (candidate-pattern)
return $false
} else {
$dynamicScrollbarsValue = (Get-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty)).DynamicScrollbars