Functions/Disconnect-AzureRMS.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
describe "BitTitan.Runbooks.AzureRMS/Disconnect-AzureRms" -Tags "module", "unit" {

    # Import the function to test
    . "$($PSScriptRoot)\Disconnect-AzureRms.ps1"

    # Declare external functions
    function Disconnect-AadrmService {}

    context "when there are no issues" {
        # Declare mocks
        mock Disconnect-AadrmService {}

        it "disconnects from Azure RMS" {
            # Call the function
            $output = Disconnect-AzureRMS -ErrorAction SilentlyContinue -ErrorVariable errorVariable

            # Verify the mocks
            Assert-MockCalled Disconnect-AadrmService -Times 1 -Exactly -Scope it

            # Verify the outputs
            $output | Should Be $true
            $errorVariable | Should BeNullOrEmpty
        }
    }

    context "when an exception is thrown while disconnecting from Azure RMS" {
        # Declare mocks
        mock Disconnect-AadrmService {
            throw "up"
        }

        it "outputs an error" {
            # Call the function
            $output = Disconnect-AzureRMS -ErrorAction SilentlyContinue -ErrorVariable errorVariable

            # Verify the mocks
            Assert-MockCalled Disconnect-AadrmService -Times 1 -Exactly -Scope it

            # Verify the outputs
            $output | Should Be $false
            $errorVariable | Should Not BeNullOrEmpty
        }
    }

}