Tests/Unit/ConvertFrom-ScriptConfigJson.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
$modulePath = Resolve-Path -Path "$PSScriptRoot\..\..\.." | Select-Object -ExpandProperty Path $moduleName = Resolve-Path -Path "$PSScriptRoot\..\.." | Get-Item | Select-Object -ExpandProperty BaseName Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue Import-Module -Name "$modulePath\$moduleName" -Force InModuleScope ScriptConfig { Describe 'ConvertFrom-ScriptConfigJson' { It 'should be able to convert the example config file' { # Arrange $content = Get-Content -Path "$PSScriptRoot\TestData\config.json" # Act $config = ConvertFrom-ScriptConfigJson -Content $content # Assert $config | Should -Not -BeNullOrEmpty } It 'shloud be able to parse a string' { # Arrange $content = Get-Content -Path "$PSScriptRoot\TestData\config.json" # Act $config = ConvertFrom-ScriptConfigJson -Content $content # Assert $config.MyString | Should -Be 'This is a test JSON config file!' $config.MyString.GetType() | Should -Be ([System.String]) } It 'shloud be able to parse an integer' { # Arrange $content = Get-Content -Path "$PSScriptRoot\TestData\config.json" # Act $config = ConvertFrom-ScriptConfigJson -Content $content # Assert $config.MyIntegerPositive | Should -Be 42 $config.MyIntegerPositive.GetType() | Should -Be ([System.Int32]) $config.MyIntegerNegative | Should -Be -153 $config.MyIntegerNegative.GetType() | Should -Be ([System.Int32]) } It 'shloud be able to parse an boolean' { # Arrange $content = Get-Content -Path "$PSScriptRoot\TestData\config.json" # Act $config = ConvertFrom-ScriptConfigJson -Content $content # Assert $config.MyBooleanTrue | Should -BeTrue $config.MyBooleanTrue.GetType() | Should -Be ([System.Boolean]) $config.MyBooleanFalse | Should -BeFalse $config.MyBooleanFalse.GetType() | Should -Be ([System.Boolean]) } It 'shloud be able to parse an array' { # Arrange $content = Get-Content -Path "$PSScriptRoot\TestData\config.json" $expectedArray = @( 'Lorem', 'Ipsum' ) # Act $config = ConvertFrom-ScriptConfigJson -Content $content # Assert $config.MyArray | Should -Not -BeNullOrEmpty $config.MyArray | Should -Be $expectedArray $config.MyArray.GetType() | Should -Be ([System.Object[]]) } It 'shloud be able to parse an hashtable' { # Arrange $content = Get-Content -Path "$PSScriptRoot\TestData\config.json" $expectedHashtable = @{ Foo = 'Bar'; Hello = 'World' } # Act $config = ConvertFrom-ScriptConfigJson -Content $content # Assert $config.MyHashtable | Should -Not -BeNullOrEmpty $config.MyHashtable.Keys -as [string[]] | Should -Be ($expectedHashtable.Keys -as [string[]]) $config.MyHashtable.Values -as [string[]] | Should -Be ($expectedHashtable.Values -as [string[]]) $config.MyHashtable.GetType() | Should -Be ([System.Collections.Hashtable]) } } } |