@@ -268,4 +268,86 @@ resources:
268268 $out | Should -Not - BeNullOrEmpty
269269 $out | Should - BeLike " *ERROR*Credential object 'Credential' requires both 'username' and 'password' properties*"
270270 }
271+
272+ It ' List works with class-based PS DSC resources' - Skip:(! $IsWindows ) {
273+ BeforeDiscovery {
274+ $windowsPowerShellPath = Join-Path $testDrive ' WindowsPowerShell' ' Modules'
275+ $env: PSModulePath += [System.IO.Path ]::PathSeparator + $windowsPowerShellPath
276+
277+ $moduleFile = @"
278+ @{
279+ RootModule = 'PSClassResource.psm1'
280+ ModuleVersion = '0.1.0'
281+ GUID = '1b2e177b-1819-4f51-8bc9-795dd8fae984'
282+ Author = 'Microsoft Corporation'
283+ CompanyName = 'Microsoft Corporation'
284+ Copyright = '(c) Microsoft Corporation. All rights reserved.'
285+ Description = 'DSC Resource for Windows PowerShell Class'
286+ PowerShellVersion = '5.1'
287+ DscResourcesToExport = @(
288+ 'PSClassResource'
289+ )
290+ PrivateData = @{
291+ PSData = @{
292+ Tags = @(
293+ 'PSDscResource_PSClassResource'
294+ )
295+ }
296+ }
271297}
298+ "@
299+ $moduleFilePath = Join-Path $windowsPowerShellPath ' PSClassResource' ' 0.1.0' ' PSClassResource.psd1'
300+ if (-not (Test-Path - Path $moduleFilePath )) {
301+ New-Item - Path $moduleFilePath - ItemType File - Value $moduleFile - Force | Out-Null
302+ }
303+
304+
305+ $module = @'
306+ [DSCResource()]
307+ class PSClassResource {
308+ [DscProperty(Key)]
309+ [string] $Name
310+
311+ PSClassResource() {
312+ }
313+
314+ [PSClassResource] Get() {
315+ return $this
316+ }
317+
318+ [bool] Test() {
319+ return $true
320+ }
321+
322+ [void] Set() {
323+
324+ }
325+ }
326+ '@
327+
328+ $modulePath = Join-Path $windowsPowerShellPath ' PSClassResource' ' 0.1.0' ' PSClassResource.psm1'
329+ if (-not (Test-Path - Path $modulePath )) {
330+ New-Item - Path $modulePath - ItemType File - Value $module - Force | Out-Null
331+ }
332+ }
333+
334+ $out = dsc - l trace resource list -- adapter Microsoft.Windows/ WindowsPowerShell | ConvertFrom-Json
335+ $LASTEXITCODE | Should - Be 0
336+ $out.type | Should - Contain ' PSClassResource/PSClassResource'
337+ $out | Where-Object - Property type -EQ PSClassResource/ PSClassResource | Select-Object - ExpandProperty implementedAs | Should - Be 1 # Class-based
338+ }
339+
340+ It ' Get works with class-based PS DSC resources' - Skip:(! $IsWindows ) {
341+
342+ $out = dsc resource get - r PSClassResource/ PSClassResource -- input (@ {Name = ' TestName' } | ConvertTo-Json ) | ConvertFrom-Json
343+ $LASTEXITCODE | Should - Be 0
344+ $out.actualState.Name | Should - Be ' TestName'
345+ }
346+
347+ It ' Set works with class-based PS DSC resources' - Skip:(! $IsWindows ) {
348+
349+ $out = dsc resource set - r PSClassResource/ PSClassResource -- input (@ {Name = ' TestName' } | ConvertTo-Json ) | ConvertFrom-Json
350+ $LASTEXITCODE | Should - Be 0
351+ $out.afterstate.InDesiredState | Should - Be $true
352+ }
353+ }
0 commit comments