@@ -152,8 +152,6 @@ Describe 'ResourceBase\Assert()' -Tag 'Assert' {
152152 }
153153 }
154154
155- Mock - CommandName Clear-ZeroedEnumPropertyValue
156-
157155 $inModuleScopeScriptBlock = @'
158156using module DscResource.Base
159157
@@ -223,7 +221,6 @@ $script:mockResourceBaseInstance = [MyMockResource]::new()
223221 }
224222
225223 Should - Invoke - CommandName Get-DscProperty - Exactly - Times 1 - Scope It
226- Should - Invoke - CommandName Clear-ZeroedEnumPropertyValue - Exactly - Times 1 - Scope It
227224 }
228225 }
229226 }
@@ -243,8 +240,6 @@ Describe 'ResourceBase\Normalize()' -Tag 'Normalize' {
243240 }
244241 }
245242
246- Mock - CommandName Clear-ZeroedEnumPropertyValue
247-
248243 $inModuleScopeScriptBlock = @'
249244using module DscResource.Base
250245
@@ -314,7 +309,6 @@ $script:mockResourceBaseInstance = [MyMockResource]::new()
314309 }
315310
316311 Should - Invoke - CommandName Get-DscProperty - Exactly - Times 1 - Scope It
317- Should - Invoke - CommandName Clear-ZeroedEnumPropertyValue - Exactly - Times 1 - Scope It
318312 }
319313 }
320314 }
@@ -1751,3 +1745,142 @@ $script:mockResourceBaseInstance = [MyMockResource]::new()
17511745 }
17521746 }
17531747}
1748+
1749+ Describe ' ResourceBase\GetDesiredState()' - Tag ' GetDesiredState' {
1750+ BeforeAll {
1751+ Mock - CommandName Get-ClassName - MockWith {
1752+ # Only return localized strings for this class name.
1753+ @ (' ResourceBase' )
1754+ }
1755+ }
1756+
1757+ Context ' When FeatureOptionalEnums is disabled' {
1758+ BeforeAll {
1759+ $inModuleScopeScriptBlock = @'
1760+ using module DscResource.Base
1761+
1762+ class MyMockResource : ResourceBase
1763+ {
1764+ [DscProperty(Key)]
1765+ [System.String]
1766+ $MyResourceKeyProperty1
1767+
1768+ [DscProperty()]
1769+ [System.String]
1770+ $MyResourceProperty2
1771+
1772+ [DscProperty()]
1773+ [System.String]
1774+ $MyResourceProperty3
1775+
1776+ [DscProperty(NotConfigurable)]
1777+ [System.String]
1778+ $MyResourceReadProperty
1779+
1780+ MyMockResource () {
1781+ $this.FeatureOptionalEnums = $false
1782+ }
1783+ }
1784+
1785+ $script:mockResourceBaseInstance = [MyMockResource]::new()
1786+ '@
1787+
1788+ InModuleScope - ScriptBlock ([Scriptblock ]::Create($inModuleScopeScriptBlock ))
1789+
1790+ Mock - CommandName Get-DscProperty - MockWith {
1791+ return @ {
1792+ MyResourceKeyProperty1 = ' KeyValue'
1793+ MyResourceProperty2 = ' TestValue'
1794+ MyResourceProperty3 = ' Value3'
1795+ }
1796+ }
1797+ }
1798+
1799+ It ' Should have correctly instantiated the resource class' {
1800+ InModuleScope - ScriptBlock {
1801+ $mockResourceBaseInstance | Should -Not - BeNullOrEmpty
1802+ $mockResourceBaseInstance.GetType ().BaseType.Name | Should - Be ' ResourceBase'
1803+ }
1804+ }
1805+
1806+ It ' Should call Get-DscProperty with the correct parameters' {
1807+ InModuleScope - ScriptBlock {
1808+ $null = $mockResourceBaseInstance.GetDesiredState ()
1809+ }
1810+
1811+ Should - Invoke - CommandName Get-DscProperty - ParameterFilter {
1812+ (-not $PesterBoundParameters.ContainsKey (' IgnoreZeroEnumValue' ))
1813+ } - Exactly - Times 1 - Scope It
1814+ }
1815+
1816+ It ' Should return the correct hashtable' {
1817+ InModuleScope - ScriptBlock {
1818+ $result = $mockResourceBaseInstance.GetDesiredState ()
1819+ $result.Keys | Should - HaveCount 3
1820+ $result.MyResourceKeyProperty1 | Should - Be ' KeyValue'
1821+ $result.MyResourceProperty2 | Should - Be ' TestValue'
1822+ $result.MyResourceProperty3 | Should - Be ' Value3'
1823+ }
1824+ }
1825+ }
1826+
1827+ Context ' When FeatureOptionalEnums is enabled' {
1828+ BeforeAll {
1829+ $inModuleScopeScriptBlock = @'
1830+ using module DscResource.Base
1831+
1832+ enum MyMockEnum {
1833+ Value1 = 0
1834+ Value2 = 1
1835+ Value3 = 2
1836+ }
1837+
1838+ class MyMockResource : ResourceBase
1839+ {
1840+ [DscProperty(Key)]
1841+ [System.String]
1842+ $MyResourceKeyProperty1
1843+
1844+ [DscProperty()]
1845+ [System.String]
1846+ $MyResourceProperty2
1847+
1848+ [DscProperty()]
1849+ [MyMockEnum]
1850+ $MyResourceEnumProperty = [MyMockEnum]::Value1
1851+
1852+ [DscProperty(NotConfigurable)]
1853+ [System.String]
1854+ $MyResourceReadProperty
1855+
1856+ MyMockResource () {
1857+ $this.FeatureOptionalEnums = $true
1858+ }
1859+ }
1860+
1861+ $script:mockResourceBaseInstance = [MyMockResource]::new()
1862+ '@
1863+
1864+ InModuleScope - ScriptBlock ([Scriptblock ]::Create($inModuleScopeScriptBlock ))
1865+
1866+ Mock - CommandName Get-DscProperty
1867+ }
1868+
1869+ It ' Should have correctly instantiated the resource class' {
1870+ InModuleScope - ScriptBlock {
1871+ $mockResourceBaseInstance | Should -Not - BeNullOrEmpty
1872+ $mockResourceBaseInstance.GetType ().BaseType.Name | Should - Be ' ResourceBase'
1873+ }
1874+ }
1875+
1876+ It ' Should call Get-DscProperty with the correct parameters including IgnoreZeroEnumValue' {
1877+ InModuleScope - ScriptBlock {
1878+ $null = $mockResourceBaseInstance.GetDesiredState ()
1879+ }
1880+
1881+ Should - Invoke - CommandName Get-DscProperty - ParameterFilter {
1882+ $IgnoreZeroEnumValue -eq $true
1883+ } - Exactly - Times 1 - Scope It
1884+ }
1885+ }
1886+ }
0 commit comments