tests/unit/functions/Test-AWPPreReq.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
InModuleScope awp {
    Describe 'Test-AWPPreReq' {
        Mock New-CimInstance { }

        Context 'General Tests' {
            Mock Get-CimInstance { 
                [PSCustomObject]@{
                    version = [version]8.1
                }
            } -ParameterFilter { $ClassName -eq 'Win32_OperatingSystem' }

            Mock Invoke-Command {
                [psCustomObject]@{
                    release = 394802
                }
            }

            It 'Parameter Tests' {
                { Test-AWPPreReq } | Should Not Throw
                { Test-AWPPreReq -cred } | Should throw
            }
        }
        Context 'AWP Agent PreReq Passes' {
            Mock Get-CimInstance { 
                [PSCustomObject]@{
                    version = [version]8.1
                }
            } -ParameterFilter { $ClassName -eq 'Win32_OperatingSystem' }

            Mock Invoke-Command {
                [psCustomObject]@{
                    release = 394802
                }
            }

            It '.net relase and OS version correct' { 
            (Test-AWPPreReq).preReqPass | Should Be $true
            }
        }

        Context 'AWP Agent PreReq Fails' {
            It '.net release incorrect' { 
                Mock Get-CimInstance { 
                    [PSCustomObject]@{
                        version = [version]6.1.0
                    }
                } -ParameterFilter { $ClassName -eq 'Win32_OperatingSystem' }

                Mock Invoke-Command {
                    [psCustomObject]@{
                        release = 10000
                    }
                }

            (Test-AWPPreReq).preReqPass | Should Be $false
            }

            It 'OS version incorrect' { 
                Mock Get-CimInstance { } -ParameterFilter { $ClassName -eq 'Win32_OperatingSystem' }

                Mock Invoke-Command {
                    [psCustomObject]@{
                        release = 394802
                    }
                }
        
            (Test-AWPPreReq).preReqPass | Should Be $false
            }
        }
    }
}