Tests/Manifest.Tests.ps1

$ModulePath = Split-Path -Parent $MyInvocation.MyCommand.Path
$ModuleName = "PSModuleBuilder"

$ManifestPath = "$ModulePath\..\$ModuleName.psd1"

# test the module manifest - exports the right functions, processes the right formats, and is generally correct
Describe "Manifest" {

    $ManifestHash = Invoke-Expression (Get-Content $ManifestPath -Raw)

    It "has a valid manifest" {
        {
                $null = Test-ModuleManifest -Path $ManifestPath -ErrorAction Stop -WarningAction SilentlyContinue
        } | Should Not Throw
    }

    It "has a valid root module" {
        $ManifestHash.RootModule | Should Be "$ModuleName.psm1"
    }

    It "has a valid Description" {
        $ManifestHash.Description | Should Not BeNullOrEmpty
    }

    It "has a valid guid" {
        $ManifestHash.Guid | Should Be 'ce7c4a02-ccd4-4b8b-8cbe-821308e3ac81'
    }

    It "has a valid prefix" {
        $ManifestHash.DefaultCommandPrefix | Should Not BeNullOrEmpty
    }

    It "has a valid copyright" {
        $ManifestHash.CopyRight | Should Not BeNullOrEmpty
    }

    It "exports all public functions" {
        $ExFunctions = $ManifestHash.FunctionsToExport
        $FunctionFiles = Get-ChildItem "$ModulePath\Public" -Filter *.ps1 -Exclude *.Tests.ps1 | Select-Object -ExpandProperty BaseName
        $FunctionNames = $FunctionFiles
        foreach ($FunctionName in $FunctionNames)
        {
                $ExFunctions -contains $FunctionName | Should Be $true
        }
    }
}