Functions/Disconnect-AzureRMS.Tests.ps1

describe "BitTitan.Runbooks.AzureRMS/Disconnect-AzureRms" -Tag "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
        }
    }

}