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 {
8
8
Expected
9
9
}
10
10
11
+ enum Ensure {
12
+ Present
13
+ Absent
14
+ }
15
+
11
16
class BaseTestClass
12
17
{
13
18
[DscProperty ()]
@@ -32,6 +37,9 @@ class TestClassResource : BaseTestClass
32
37
[DscProperty ()]
33
38
[PSCredential ] $Credential
34
39
40
+ [DscProperty ()]
41
+ [Ensure ] $Ensure
42
+
35
43
[string ] $NonDscProperty # This property shouldn't be in results data
36
44
37
45
hidden
Original file line number Diff line number Diff line change @@ -274,4 +274,40 @@ Describe 'PowerShell adapter resource tests' {
274
274
$out | Should -Not - BeNullOrEmpty
275
275
$out | Should - BeLike " *ERROR*Credential object 'Credential' requires both 'username' and 'password' properties*"
276
276
}
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
+ }
277
312
}
313
+
Original file line number Diff line number Diff line change @@ -445,7 +445,15 @@ function Invoke-DscOperation {
445
445
' Get' {
446
446
$Result = @ {}
447
447
$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
+ }
449
457
$addToActualState.properties = $Result
450
458
}
451
459
' Set' {
@@ -473,7 +481,14 @@ function Invoke-DscOperation {
473
481
$raw_obj_array = $method.Invoke ($null , $null )
474
482
foreach ($raw_obj in $raw_obj_array ) {
475
483
$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
+ }
477
492
$resultArray += $Result_obj
478
493
}
479
494
$addToActualState = $resultArray
You can’t perform that action at this time.
0 commit comments