Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hughes committed Nov 7, 2024
1 parent 5404e69 commit 3bfb5f8
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions tests/unit/private/Get-DscPropertyType.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#region HEADER
$script:projectPath = "$PSScriptRoot\..\..\.." | Convert-Path
$script:projectName = (Get-ChildItem -Path "$script:projectPath\*\*.psd1" | Where-Object -FilterScript {
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
$(try
{
Test-ModuleManifest -Path $_.FullName -ErrorAction Stop
}
catch
{
$false
})
}).BaseName

$script:moduleName = Get-Module -Name $script:projectName -ListAvailable | Select-Object -First 1
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'

Import-Module $script:moduleName -Force -ErrorAction 'Stop'
#endregion HEADER

InModuleScope $script:moduleName {
Describe 'Get-DscPropertyType' {
Context 'When the property type is ''Nullable''' {
BeforeAll {
$mockClassBasedScript = {
[DscResource()]
class AzDevOpsProject
{
[AzDevOpsProject] Get()
{
return [AzDevOpsProject] $this
}

[System.Boolean] Test()
{
return $true
}

[void] Set()
{
}

[DscProperty(Key)]
[System.String]
$ProjectName

[DscProperty(Mandatory)]
[System.String]
$ProjectId

[DscProperty()]
[Nullable[System.Int32]]
$Index
}

[AzDevOpsProject].GetProperties()
}

[System.Reflection.PropertyInfo[]]$mockProperties = $mockClassBasedScript.InvokeReturnAsIs()
}

It 'Should return the inner type name' {
$result = Get-DscPropertyType -PropertyType $mockProperties[2].PropertyType

$result | Should -Be 'System.Int32'
}
}

Context 'When the property type is not ''Nullable''' {
BeforeAll {
$mockClassBasedScript = {
[DscResource()]
class AzDevOpsProject
{
[AzDevOpsProject] Get()
{
return [AzDevOpsProject] $this
}

[System.Boolean] Test()
{
return $true
}

[void] Set()
{
}

[DscProperty(Key)]
[System.String]
$ProjectName

[DscProperty(Mandatory)]
[System.String]
$ProjectId

[DscProperty()]
[Nullable[System.Int32]]
$Index
}

[AzDevOpsProject].GetProperties()
}

[System.Reflection.PropertyInfo[]]$mockProperties = $mockClassBasedScript.InvokeReturnAsIs()
}

It 'Should return the type name' {
$result = Get-DscPropertyType -PropertyType $mockProperties[1].PropertyType

$result | Should -Be 'System.String'
}
}
}
}

0 comments on commit 3bfb5f8

Please sign in to comment.