Testing/Unit/PowerShell/Orchestrator/Invoke-ProviderList.Tests.ps1

$OrchestratorPath = '../../../../Modules/Orchestrator.psm1'
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath $OrchestratorPath) -Function 'Invoke-ProviderList' -Force

InModuleScope Orchestrator {
Describe -Tag 'Orchestrator' -Name 'Invoke-ProviderList' {
    BeforeAll {
    function Set-Utf8NoBom {}
    Mock -ModuleName Orchestrator Set-Utf8NoBom {}
        function Export-AADProvider {}
        Mock -ModuleName Orchestrator Export-AADProvider {}
        function Export-EXOProvider {}
        Mock -ModuleName Orchestrator Export-EXOProvider {}
        function Export-DefenderProvider {}
        Mock -ModuleName Orchestrator Export-DefenderProvider {}
        function Export-PowerPlatformProvider {}
        Mock -ModuleName Orchestrator Export-PowerPlatformProvider {}
        function Export-SharePointProvider {}
        Mock -ModuleName Orchestrator Export-SharePointProvider {}
        function Export-TeamsProvider {}
        Mock -ModuleName Orchestrator Export-TeamsProvider {}
        function Get-FileEncoding {}
        Mock -ModuleName Orchestrator Get-FileEncoding {}

        Mock -CommandName Write-Progress {}
        Mock -CommandName Join-Path {"."}
        Mock -CommandName Set-Content {}
        Mock -CommandName Get-TimeZone {}
        Mock -CommandName Set-Utf8NoBom {}
        Mock -CommandName Write-Debug {}
    }
    Context 'When running the providers on commercial tenants' {
        BeforeAll {
              [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'CyberConfig')]
              $CyberConfig = [PSCustomObject]@{
                 ProductNames = @('aad')
                 OutProviderFileName = "ProviderSettingsExport"
                 M365Environment = "commercial"
                 OutRegoFileName = "TestResults"
                 OutReportName = "BaselineReports"
                 OPAPath = "."
                 LogIn = $false
                 PreferredDnsResolvers = @()
                 SkipDoH = $false
              }
              [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'TenantDetails')]
              $TenantDetails = '{"DisplayName": "displayName"}'
              [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'ModuleVersion')]
              $ModuleVersion = '1.0'
              [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'OutFolderPath')]
              $OutFolderPath = "./output"
              [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'Guid')]
              $Guid = "00000000-0000-0000-0000-000000000000"
        }
        It 'With -ProductNames "aad", should not throw' {
              $CyberConfig.ProductNames = @("aad")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
        It 'With -ProductNames "defender", should not throw' {
              $CyberConfig.ProductNames = @("defender")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
        It 'With -ProductNames "exo", should not throw' {
              $CyberConfig.ProductNames = @("exo")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
        It 'With -ProductNames "powerplatform", should not throw' {
              $CyberConfig.ProductNames = @("powerplatform")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
        It 'With -ProductNames "sharepoint", should not throw' {
              $CyberConfig.ProductNames = @("sharepoint")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
        It 'With -ProductNames "teams", should not throw' {
              $CyberConfig.ProductNames = @("teams")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
        It 'With all products, should not throw' {
              $CyberConfig.ProductNames = @("aad", "defender", "exo", "powerplatform", "sharepoint", "teams")
            { Invoke-ProviderList -CyberConfig $CyberConfig -TenantDetails $TenantDetails -ModuleVersion $ModuleVersion -OutFolderPath $OutFolderPath -Guid $Guid } | Should -Not -Throw
        }
    }
}
}

AfterAll {
    Remove-Module Orchestrator -ErrorAction SilentlyContinue
}