Tests/AzureHelpers.Tests.ps1

$ModulePath = Split-Path -Path $PSScriptRoot -Parent
$ModuleName = Split-Path -Path $ModulePath -Leaf

# Make sure one or multiple versions of the module are not loaded
Get-Module -Name $ModuleName | Remove-Module

# Import the module and store the information about the module
$ModuleLoadPath = Join-Path $ModulePath "$ModuleName.psd1"
$ModuleInformation = Import-Module -Name $ModuleLoadPath -PassThru
$ModuleInformation | Format-List

# Get the functions present in the Manifest
$ExportedFunctions = $ModuleInformation.ExportedFunctions.Values.Name

# Get the functions present in the Public folder
$PS1Functions = Get-ChildItem -Path $(Join-Path $ModulePath 'Public' '*.ps1')

 # Get the RequiredModules
 $requiredModules = $ModuleInformation.RequiredModules.ModuleName
 
 if ($requiredModules) {
     # Install the required modules
     foreach ($module in $requiredModules) {
         Install-Module $module -Force
     }
 }

Describe "$ModuleName Module - Testing Manifest File (.psd1)" {
    Context "Manifest" {
        It "Should contain RootModule" {
            $ModuleInformation.RootModule | Should -Not -BeNullOrEmpty
        }

        It "Should contain ModuleVersion" {
            $ModuleInformation.Version | Should -Not -BeNullOrEmpty
        }

        It "Should contain GUID" {
            $ModuleInformation.Guid | Should -Not -BeNullOrEmpty
        }

        It "Should contain Author" {
            $ModuleInformation.Author | Should -Not -BeNullOrEmpty
        }

        It "Should contain Description" {
            $ModuleInformation.Description | Should -Not -BeNullOrEmpty
        }

        It "Compare the count of Function Exported and the PS1 files found" {
            $status = $ExportedFunctions.Count -eq $PS1Functions.Count
            $status | Should -Be $true
        }

        It "Compare the missing function" {
            If ($ExportedFunctions.count -ne $PS1Functions.count) {
                $Compare = Compare-Object -ReferenceObject $ExportedFunctions -DifferenceObject $PS1Functions.Basename
                $Compare.InputObject -Join ',' | Should -BeNullOrEmpty
            }
        }
    }
}

Get-Module -Name $ModuleName | Remove-Module