tests/unit/functions/Install-AWP.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
InModuleScope awp {
    Describe 'Install-AWP' {
        $testPath = "TestDrive:\awpInstall.exe"
        Set-Content $testPath -value "awpInstLLER"

        BeforeEach {
            Mock Copy-Item { $null }
        }

        Context 'General Tests' {
            It 'Parameter Tests' {
                Mock Test-AWPInstall {}
                Mock Invoke-Command { }

                { Install-AWP -path "$TestDrive\awpInstall.exe" } | Should Not Throw
                { Install-AWP -path "$TestDrive\awpInstall.exe" -cred } | Should throw
            }
        }

        Context 'Is Invoke-Command Called Correctly' {
            it 'When AWP agent is not installed' {
                Mock Test-AWPInstall {
                    @{
                        isInstalled = $false
                    }
                }

                Mock Invoke-Command { "$TestDrive\awpInstall.exe" }

                Install-AWP -path "$TestDrive\awpInstall.exe" | Out-Null

                Assert-MockCalled -CommandName Invoke-Command -Exactly 3 -Scope It
            }

            it 'When AWP agent is installed' {
                Mock Test-AWPInstall {
                    @{
                        isInstalled = $true
                    }
                }

                Mock Start-Process {}

                Install-AWP -path "$TestDrive\awpInstall.exe" | Out-Null

                Assert-MockCalled -CommandName Start-Process -Exactly 0 -Scope It
            }
        }
    }
}