Functions/Export-Document.Tests.ps1

$here = Split-Path -Path $MyInvocation.MyCommand.Path -Parent;
$moduleRoot = Split-Path -Path $here -Parent;
Import-Module "$moduleRoot\PScribo.psm1" -Force;

InModuleScope 'PScribo' {

    Describe "Export-Document" {

        $document = Document 'ScaffoldDocument' {};
    
        It "calls single output formatter." {   
            Mock OutText -Verifiable { }
            $document | Export-Document -Format Text;
            Assert-VerifiableMocks;
        }

        It "calls multiple output formatters." {   
            Mock OutText -Verifiable { }
            Mock OutXml -Verifiable { }
            $document | Export-Document -Format Text,XML;
            Assert-VerifiableMocks;
        }

        It "throws on invalid qualified directory path." {
            { $document | Export-Document -Format Text -Path TestDrive:\ThisShouldHopefullyNotExist -ErrorAction SilentlyContinue } |
                Should Throw;
        }

        It "does not throw on valid qualified path." {
            { $document | Export-Document -Format Text -Path TestDrive:\ -ErrorAction SilentlyContinue } |
                Should Not Throw;
        }

        It "throws on invalid relative directory path." {
            { $document | Export-Document -Format Text -Path .\ThisShouldHopefullyNotExist -ErrorAction SilentlyContinue } |
                Should Throw;
        }

        It "does not throw on valid relative path." {
            { $document | Export-Document -Format Text -Path . -ErrorAction SilentlyContinue } |
                Should Not Throw;
        }

        It "calls single output formatter." {   
            Mock OutText -Verifiable { }
            Export-Document -Document $document -Format Text;
            Assert-VerifiableMocks;
        }

        It "calls multiple output formatters." {   
            Mock OutText -Verifiable { }
            Mock OutXml -Verifiable { }
            Export-Document -Document $document -Format Text,XML;
            Assert-VerifiableMocks;
        }

            It "throws on invalid qualified directory path." {
            { Export-Document -Document $document -Format Text -Path TestDrive:\ThisShouldHopefullyNotExist -ErrorAction SilentlyContinue } |
                Should Throw;
        }

        It "does not throw on valid qualified path." {
            { Export-Document -Document $document -Format Text -Path TestDrive:\ -ErrorAction SilentlyContinue } |
                Should Not Throw;
        }

        It "throws on invalid relative directory path." {
            { Export-Document -Document $document -Format Text -Path .\ThisShouldHopefullyNotExist -ErrorAction SilentlyContinue } |
                Should Throw;
        }

        It "does not throw on valid relative path." {
            { Export-Document -Document $document -Format Text -Path . -ErrorAction SilentlyContinue } |
                Should Not Throw;
        }

    }

} #end inmodulescope