@@ -59,39 +59,27 @@ Describe 'WMI adapter resource tests' {
59
59
$res.results [1 ].result.actualState.result[4 ].properties.AdapterType | Should - BeLike " Ethernet*"
60
60
}
61
61
62
- It ' Throws error when methodName is missing on set ' - Skip:(! $IsWindows ) {
63
- ' {"Name":"wuauserv"} ' | dsc - l trace resource set - r ' root.cimv2/Win32_Service ' -f - 2> $TestDrive \tracing.txt
64
- $LASTEXITCODE | Should - Be 2
65
- " $TestDrive /tracing.txt " | Should - FileContentMatch " 'methodName' property is required for invoking a WMI/CIM method. "
62
+ It ' Set does not work with missing key property ' - Skip:(! $IsWindows ) {
63
+ $s = dsc resource set -- resource root.cimv2/ Win32_Environment -- input ' {} ' 2>&1
64
+ $LASTEXITCODE | Should - Be 1
65
+ $s | Should - BeLike " *Key property 'Name' is required* "
66
66
}
67
67
68
- It ' Throws error when methodName is set but parameters are missing on set' - Skip:(! $IsWindows ) {
69
- ' {"Name":"wuauserv", "methodName":"StartService"}' | dsc - l trace resource set - r ' root.cimv2/Win32_Service' -f - 2> $TestDrive \tracing.txt
70
- $LASTEXITCODE | Should - Be 2
71
- " $TestDrive /tracing.txt" | Should - FileContentMatch " 'parameters' property is required for invoking a WMI/CIM method."
72
- }
73
-
74
- It ' Set works on a WMI resource with methodName and parameters' - Skip:(! $IsWindows ) {
75
- BeforeAll {
76
- $script :service = Get-Service - Name wuauserv - ErrorAction Ignore
77
-
78
- if ($service -and $service.Status -eq ' Running' ) {
79
- $service.Stop ()
80
- }
81
- }
68
+ It ' Set works on a WMI resource' - Skip:(! $IsWindows ) {
69
+ $i = @ {
70
+ UserName = (" {0}\{1}" -f $env: USERDOMAIN , $env: USERNAME ) # Read-only property required
71
+ Name = " TestVariable"
72
+ VariableValue = " TestValue"
73
+ } | ConvertTo-Json
82
74
75
+ $r = dsc - l trace resource set - r root.cimv2/ Win32_Environment - i $i
83
76
84
- $r = ' {"Name":"wuauserv", "methodName ":"StartService", "parameters":{}} ' | dsc resource set - r ' root.cimv2/Win32_Service ' -f -
77
+ $s = dsc resource set -- resource root.cimv2 / Win32_Environment -- input ' {"Name":"TestVariable","Value ":"TestValue"} '
85
78
$LASTEXITCODE | Should - Be 0
86
-
87
- $res = ' {"Name":"wuauserv", "State": null}' | dsc resource get - r ' root.cimv2/Win32_Service' -f - | ConvertFrom-Json
88
- $res.actualState.Name | Should - Be ' wuauserv'
89
- $res.actualState.State | Should - Be ' Running'
79
+ $s | Should - BeLike " *Set operation completed successfully*"
90
80
91
- AfterAll {
92
- if ($service -and $service.Status -eq ' Running' ) {
93
- $service.Stop ()
94
- }
95
- }
81
+ # Verify the variable was set
82
+ $get = dsc resource get - r root.cimv2/ Win32_Environment - i ' {"Name":"TestVariable"}'
83
+ $get | Should - BeLike " *TestValue*"
96
84
}
97
85
}
0 commit comments