File tree Expand file tree Collapse file tree 3 files changed +61
-2
lines changed Expand file tree Collapse file tree 3 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ enum EnumPropEnumeration {
88 Expected
99}
1010
11+ enum Ensure {
12+ Present
13+ Absent
14+ }
15+
1116class BaseTestClass
1217{
1318 [DscProperty ()]
@@ -32,6 +37,9 @@ class TestClassResource : BaseTestClass
3237 [DscProperty ()]
3338 [PSCredential ] $Credential
3439
40+ [DscProperty ()]
41+ [Ensure ] $Ensure
42+
3543 [string ] $NonDscProperty # This property shouldn't be in results data
3644
3745 hidden
Original file line number Diff line number Diff line change @@ -274,4 +274,40 @@ Describe 'PowerShell adapter resource tests' {
274274 $out | Should -Not - BeNullOrEmpty
275275 $out | Should - BeLike " *ERROR*Credential object 'Credential' requires both 'username' and 'password' properties*"
276276 }
277+
278+ It ' Config get is able to return proper enum value' {
279+ $yaml = @"
280+ `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
281+ resources:
282+ - name: Class-resource Info
283+ type: TestClassResource/TestClassResource
284+ properties:
285+ Name: 'TestClassResource'
286+ Ensure: 'Present'
287+ "@
288+
289+ $out = dsc config get - i $yaml | ConvertFrom-Json
290+ $LASTEXITCODE | Should - Be 0
291+ $out.results.result.actualState.Ensure | Should - Be ' Present'
292+ }
293+
294+ It ' Config export is able to return proper enum value' {
295+ $yaml = @"
296+ `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
297+ resources:
298+ - name: Working with class-based resources
299+ type: Microsoft.DSC/PowerShell
300+ properties:
301+ resources:
302+ - name: Class-resource Info
303+ type: TestClassResource/TestClassResource
304+ "@
305+
306+ $out = dsc config export - i $yaml | ConvertFrom-Json
307+ $LASTEXITCODE | Should - Be 0
308+ $out.resources [0 ].properties.result.count | Should - Be 5
309+ $out.resources [0 ].properties.result[0 ].Name | Should - Be " Object1"
310+ $out.resources [0 ].properties.result[0 ].Prop1 | Should - Be " Property of object1"
311+ }
277312}
313+
Original file line number Diff line number Diff line change @@ -445,7 +445,15 @@ function Invoke-DscOperation {
445445 ' Get' {
446446 $Result = @ {}
447447 $raw_obj = $dscResourceInstance.Get ()
448- $ValidProperties | ForEach-Object { $Result [$_ ] = $raw_obj .$_ }
448+ $ValidProperties | ForEach-Object {
449+ if ($raw_obj .$_ -is [System.Enum ]) {
450+ $Result [$_ ] = $raw_obj .$_.ToString ()
451+
452+ }
453+ else {
454+ $Result [$_ ] = $raw_obj .$_
455+ }
456+ }
449457 $addToActualState.properties = $Result
450458 }
451459 ' Set' {
@@ -473,7 +481,14 @@ function Invoke-DscOperation {
473481 $raw_obj_array = $method.Invoke ($null , $null )
474482 foreach ($raw_obj in $raw_obj_array ) {
475483 $Result_obj = @ {}
476- $ValidProperties | ForEach-Object { $Result_obj [$_ ] = $raw_obj .$_ }
484+ $ValidProperties | ForEach-Object {
485+ if ($raw_obj .$_ -is [System.Enum ]) {
486+ $Result_obj [$_ ] = $raw_obj .$_.ToString ()
487+ }
488+ else {
489+ $Result_obj [$_ ] = $raw_obj .$_
490+ }
491+ }
477492 $resultArray += $Result_obj
478493 }
479494 $addToActualState = $resultArray
You can’t perform that action at this time.
0 commit comments