tests/functions/utility/Import-PSFPowerShellDataFile.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 |
Describe "Import-PSFPowerShellDataFile Unit Tests" -Tag "UnitTests" { BeforeAll { $psd1Result = Import-PSFPowerShellDataFile -Path "$($global:testroot)\testdata\utility\ImportPsd1.psd1" $psd1ResultUnsafe = Import-PSFPowerShellDataFile -Path "$($global:testroot)\testdata\utility\ImportPsd1.psd1" -Unsafe $jsonResult = Import-PSFPowerShellDataFile -Path "$($global:testroot)\testdata\utility\ImportJson.json" } Describe "Imports PSD1 files correctly" { It "Should only contain one result" { ($psd1Result | Measure-Object).Count | Should -Be 1 } It "Should contain three keys" { $psd1Result.Keys.Count | Should -Be 3 } It "Should have the expected values" { $psd1Result.Name | Should -Be "Fred" $psd1Result.Age | Should -Be 66 } } Describe "Imports PSD1 files (unsafe) correctly" { It "Should only contain two results" { ($psd1ResultUnsafe | Measure-Object).Count | Should -Be 2 } It "Should contain three keys & 2 Keys" { $psd1ResultUnsafe[0].Keys.Count | Should -Be 3 $psd1ResultUnsafe[1].Keys.Count | Should -Be 2 } It "Should have the expected values" { $psd1ResultUnsafe[0].Name | Should -Be "Fred" $psd1ResultUnsafe[0].Age | Should -Be 66 $psd1ResultUnsafe[1].Name | Should -Be "Max" $psd1ResultUnsafe[1].Nachname | Should -Be "Mustermann" } } Describe "Imports Json files correctly" { It "Should enumerate correctly" { (Import-PSFPowerShellDataFile -Path "$($global:testroot)\testdata\utility\ImportJson.json" | Measure-Object).Count | Should -Be 2 } It "Should have two results" { ($jsonResult | Measure-Object).Count | Should -Be 2 } It "Should contain three keys & 2 Keys" { $jsonResult[0].Keys.Count | Should -Be 3 $jsonResult[1].Keys.Count | Should -Be 2 } It "Should have the expected values" { $jsonResult[0].Name | Should -Be "Fred" $jsonResult[0].Age | Should -Be 66 $jsonResult[1].Name | Should -Be "Max" $jsonResult[1].Nachname | Should -Be "Mustermann" } } } |