tests/ConvertFrom-Ini.Test.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
<#/*
 * @Author: Joseph Iannone
 * @Date: 2023-02-08 20:36:45
 * @Last Modified by: Joseph Iannone
 * @Last Modified time: 2023-02-08 20:36:45
 */#>


# Pester v5 required


BeforeAll {

    # Get module root
    $script:PSModuleRoot = (Get-Item $PSScriptRoot).parent.fullname
    
    # Import module
    Import-Module "$($script:PSModuleRoot)\IniConverter.psd1"

}


Describe 'ConvertFrom-Ini' {

    It 'Converts ini text string to PSobject' {
        
        # Get contents of ini test file to convert
        $iniContents = Get-Content "$($script:PSModuleRoot)\tests\test_input_001.ini"


        # Expected output object
        $expectedObj = [PSCustomObject]@{
            Test1 = "hello"
            Test2 = "world"
            Test3 = 123456
            Test4 = 123.456
            Profile = [PSCustomObject]@{
                Name = "Joe"
                Occupation = "Applications Developer"
            }
            EmptySection = @{}
            Address = [PSCustomObject]@{
                Street = "123 Main Street"
                City = "Philadelphia"
                State = "PA"
                ZipCode = 123456
            }
            Test5 = ""
            Test6 = $null
        }

        
        # Test
        $obj = $iniContents | ConvertFrom-Ini

        # Assert
        $obj.Test | Should -BeExactly $expectedObj.Test
        $obj.Test2 | Should -BeExactly $expectedObj.Test2
        $obj.Test3 | Should -BeExactly $expectedObj.Test3
        $obj.Test4 | Should -BeExactly $expectedObj.Test4
        $obj.Test5 | Should -BeExactly $expectedObj.Test5
        $obj.Profile.Name | Should -BeExactly $expectedObj.Profile.Name
        $obj.Profile.Occupation | Should -BeExactly $expectedObj.Profile.Occupation
        $obj.Address.Street | Should -BeExactly $expectedObj.Address.Street
        $obj.Address.City | Should -BeExactly $expectedObj.Address.City
        $obj.Address.State | Should -BeExactly $expectedObj.Address.State
        $obj.Address.ZipCode | Should -BeExactly $expectedObj.Address.ZipCode

    }
}