diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dca8a0..7e34253 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `New-NotImplementedException` - Now takes a parameter `PassThru` that returns the error record that was created (and does not throw). +- `Compare-DscParameterState` + - Add support for the type `[System.Collections.Specialized.OrderedDictionary]` + passed to parameters `CurrentValues` and `DesiredValues` ([issue #57](https://github.com/dsccommunity/DscResource.Common/issues/57)). ### Changed diff --git a/source/Public/Compare-DscParameterState.ps1 b/source/Public/Compare-DscParameterState.ps1 index 0fc7889..2e5bb85 100644 --- a/source/Public/Compare-DscParameterState.ps1 +++ b/source/Public/Compare-DscParameterState.ps1 @@ -182,7 +182,8 @@ function Compare-DscParameterState #region CheckType of object $types = 'System.Management.Automation.PSBoundParametersDictionary', 'System.Collections.Hashtable', - 'Microsoft.Management.Infrastructure.CimInstance' + 'Microsoft.Management.Infrastructure.CimInstance', + 'System.Collections.Specialized.OrderedDictionary' if ($DesiredValues.GetType().FullName -notin $types) { diff --git a/source/en-US/DscResource.Common.strings.psd1 b/source/en-US/DscResource.Common.strings.psd1 index 016a47f..22eada9 100644 --- a/source/en-US/DscResource.Common.strings.psd1 +++ b/source/en-US/DscResource.Common.strings.psd1 @@ -7,8 +7,8 @@ ConvertFrom-StringData @' AddressFormatError = Address '{0}' is not in the correct format. Please correct the Address parameter in the configuration and try again. (DRC0011) AddressIPv4MismatchError = Address '{0}' is in IPv4 format, which does not match server address family {1}. Please correct either of them in the configuration and try again. (DRC0012) AddressIPv6MismatchError = Address '{0}' is in IPv6 format, which does not match server address family {1}. Please correct either of them in the configuration and try again. (DRC0013) - InvalidDesiredValuesError = Property 'DesiredValues' in Test-DscParameterState must be either a Hashtable or CimInstance. Type detected was '{0}'. (DRC0014) - InvalidCurrentValuesError = Property 'CurrentValues' in Test-DscParameterState must be either a Hashtable, CimInstance, or CimIntance[]. Type detected was '{0}'. (DRC0015) + InvalidDesiredValuesError = Property 'DesiredValues' in Test-DscParameterState must be either a Hashtable, CimInstance, CimIntance[], or System.Collections.Specialized.OrderedDictionary. Type detected was '{0}'. (DRC0014) + InvalidCurrentValuesError = Property 'CurrentValues' in Test-DscParameterState must be either a Hashtable, CimInstance, CimIntance[], or System.Collections.Specialized.OrderedDictionary. Type detected was '{0}'. (DRC0015) InvalidPropertiesError = If 'DesiredValues' is a CimInstance then property 'Properties' must contain a value. (DRC0016) MatchPsCredentialUsernameMessage = MATCH: PSCredential username match. Current state is '{0}' and desired state is '{1}'. (DRC0017) NoMatchPsCredentialUsernameMessage = NOTMATCH: PSCredential username mismatch. Current state is '{0}' and desired state is '{1}'. (DRC0018) diff --git a/tests/Unit/Public/Compare-DscParameterState.Tests.ps1 b/tests/Unit/Public/Compare-DscParameterState.Tests.ps1 index 5a272d8..012e2a7 100644 --- a/tests/Unit/Public/Compare-DscParameterState.Tests.ps1 +++ b/tests/Unit/Public/Compare-DscParameterState.Tests.ps1 @@ -2636,4 +2636,104 @@ Describe 'ComputerManagementDsc.Common\Compare-DscParameterState' { } } } + + Context 'When using an ordered dictionary' { + Context 'When some values does not match' { + BeforeAll { + $currentValues = [ordered]@{ + String = 'This is a string' + Int = 1 + Bool = $true + } + $desiredValues = [ordered]@{ + String = 'This is a string' + Int = 99 + Bool = $false + } + } + + BeforeEach { + $verbose = $true + } + + It 'Should not throw exception' { + { $script:result = Compare-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -IncludeInDesiredState ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return non-null result' { + $script:result | Should -Not -BeNullOrEmpty + } + + It 'Should return $true for String in property InDesiredState' { + $script:result.Where({ + $_.Property -eq 'String' + }).InDesiredState | Should -BeTrue + } + + It 'Should return $false for Int in property InDesiredState' { + $script:result.Where({ + $_.Property -eq 'Int' + }).InDesiredState | Should -BeFalse + } + + It 'Should return $true for Bool in property InDesiredState' { + $script:result.Where({ + $_.Property -eq 'Bool' + }).InDesiredState | Should -BeFalse + } + } + + Context 'When all values match' { + BeforeAll { + $currentValues = [ordered]@{ + String = 'This is a string' + Int = 99 + Bool = $true + } + $desiredValues = [ordered]@{ + String = 'This is a string' + Int = 99 + Bool = $true + } + } + + BeforeEach { + $verbose = $true + } + + It 'Should not throw exception' { + { $script:result = Compare-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -IncludeInDesiredState ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return non-null result' { + $script:result | Should -Not -BeNullOrEmpty + } + + It 'Should return $true for String in property InDesiredState' { + $script:result.Where({ + $_.Property -eq 'String' + }).InDesiredState | Should -BeTrue + } + + It 'Should return $false for Int in property InDesiredState' { + $script:result.Where({ + $_.Property -eq 'Int' + }).InDesiredState | Should -BeTrue + } + + It 'Should return $true for Bool in property InDesiredState' { + $script:result.Where({ + $_.Property -eq 'Bool' + }).InDesiredState | Should -BeTrue + } + } + } }