EZLog.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Get-Module EZLog | Remove-Module

Import-Module EZLog

InModuleScope "EZLog" {

    Describe "Write-EZLog" {

        $logfile = "TestDrive:\pester.log"

        Context "Example 1" {

            It "Writes the header into the log file." {
                Write-EZLog -Header -LogFile $logfile
                Test-Path $logfile | Should Be $true
            }

            It "Writes an information into the log file." {
                Write-EZLog -Category INF -Message 'This is an info to be written in the log file'
                Get-Content $logfile | Select-String -Pattern 'INF;' -Quiet | Should Be $true
            }

            It "Writes a warning into the log file." {
                Write-EZLog -Category WAR -Message 'This is a warning to be written in the log file'
                Get-Content $logfile | Select-String -Pattern 'WAR;' -Quiet | Should Be $true
            }

           
            It "Writes an error into the log file." {
                Write-EZLog -Category ERR -Message 'This is an error to be written in the log file'
                Get-Content $logfile | Select-String -Pattern 'ERR;' -Quiet | Should Be $true
            }


            It "Writes the footer into the log file." {
                Write-EZLog -Footer
                Get-Content $logfile -Tail 1 | Should Be '+----------------------------------------------------------------------------------------+'
            }
        }
    
    }

}