Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hughes committed Nov 7, 2024
1 parent 4776c7f commit 9bdb357
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/unit/private/Get-ClassResourceProperty.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ InModuleScope $script:moduleName {

# The class DSC resource in the built module.
$mockBuiltModuleScript = @'
enum ResourceEnum
{
Value1
Value2
Value3
}
class ResourceBase
{
hidden [System.String] $NotADscProperty
Expand Down Expand Up @@ -60,6 +67,9 @@ class MyDscResource : ResourceBase
[DscProperty()]
[ValidateSet('Up', 'Down')]
[System.String[]] $ValidateSetProperty
[DscProperty()]
[ResourceEnum] $EnumProperty
}
'@
# Uses Microsoft.PowerShell.Utility\Out-File to override the stub that is needed for the mocks.
Expand All @@ -72,6 +82,13 @@ class MyDscResource : ResourceBase
to be able to test missing description.
#>
$mockResourceSourceScript = @'
enum ResourceEnum
{
Value1
Value2
Value3
}
<#
.SYNOPSIS
Resource synopsis.
Expand Down Expand Up @@ -103,6 +120,9 @@ class MyDscResource
[DscProperty()]
[ValidateSet('Up', 'Down')]
[System.String[]] $ValidateSetProperty
[DscProperty()]
[ResourceEnum] $EnumProperty
}
'@
# Uses Microsoft.PowerShell.Utility\Out-File to override the stub that is needed for the mocks.
Expand Down Expand Up @@ -147,10 +167,11 @@ class ResourceBase
}

$getClassResourcePropertyResult = Get-ClassResourceProperty @mockGetClassResourcePropertyParameters
$getClassResourcePropertyResult | Should -HaveCount 3
$getClassResourcePropertyResult | Should -HaveCount 4
$getClassResourcePropertyResult.Name | Should -Contain 'Ensure'
$getClassResourcePropertyResult.Name | Should -Contain 'ProjectName'
$getClassResourcePropertyResult.Name | Should -Contain 'ValidateSetProperty'
$getClassResourcePropertyResult.Name | Should -Contain 'EnumProperty'

$ensurePropertyResult = $getClassResourcePropertyResult.Where({ $_.Name -eq 'Ensure' })
$ensurePropertyResult.State | Should -Be 'Write'
Expand All @@ -173,6 +194,15 @@ class ResourceBase
$ensurePropertyResult.IsArray | Should -BeFalse
$ensurePropertyResult.ValueMap | Should -Contain 'Up'
$ensurePropertyResult.ValueMap | Should -Contain 'Down'

$ensurePropertyResult = $getClassResourcePropertyResult.Where({ $_.Name -eq 'EnumProperty' })
$ensurePropertyResult.State | Should -Be 'Write'
$ensurePropertyResult.Description | Should -BeNullOrEmpty
$ensurePropertyResult.DataType | Should -Be 'ResourceEnum'
$ensurePropertyResult.IsArray | Should -BeFalse
$ensurePropertyResult.ValueMap | Should -Contain 'Value1'
$ensurePropertyResult.ValueMap | Should -Contain 'Value2'
$ensurePropertyResult.ValueMap | Should -Contain 'Value3'
}
}

Expand Down

0 comments on commit 9bdb357

Please sign in to comment.