Public/Write-CustomLog.Tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' . "$here\$sut" Describe "Write-CustomLog" { $TestDate = '2018/08/27 16:37:37.83235' $LogHeader = "`r`n-------------$TestDate Log Header-------------" Mock Get-Date { return $TestDate } function GenLogMessages() { $Messages = @() $Messages += Write-CustomLog 1 "Log 1" -Verbose 4>&1 $Messages += Write-CustomLog 2 "Log 2" -Verbose 4>&1 $Messages += Write-CustomLog 3 "Log 3" -Verbose 4>&1 $Messages += Write-CustomLog 4 "Log 4" -Verbose 4>&1 $Messages += Write-CustomLog 5 "Log 5" -Verbose 4>&1 $Messages } It "Produce a log header on a new line" { $global:Verbosity = 2 $Output = Write-CustomLog 1 "Log Header" -LogHeader -Verbose 4>&1 $Output | Should -Be $LogHeader } It "Should log messages with verbosity 1 or lower" { $global:Verbosity = 1 $Messages = GenLogMessages $Messages | Should -HaveCount 1 } It "Should log messages with verbosity 2 or lower" { $global:Verbosity = 2 $Messages = GenLogMessages $Messages | Should -HaveCount 2 } It "Should log messages with verbosity 3 or lower" { $global:Verbosity = 3 $Messages = GenLogMessages $Messages | Should -HaveCount 3 } It "Should log messages with verbosity 4 or lower" { $global:Verbosity = 4 $Messages = GenLogMessages $Messages | Should -HaveCount 4 } It "Should log messages with verbosity 5 or lower" { $global:Verbosity = 5 $Messages = GenLogMessages $Messages | Should -HaveCount 5 } It "Should log no messages" { $global:Verbosity = 0 $Messages = GenLogMessages $Messages | Should -HaveCount 0 } } |