-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Hughes
committed
Nov 7, 2024
1 parent
5404e69
commit 3bfb5f8
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
} | ||
} |