Tests/Write-LogFile.Tests.ps1
|
BeforeAll { $TestLogPath = Join-Path -Path $TestDrive -ChildPath 'test.log' class MockFreeLogClass { [bool]$IsValid = $true [string]$LogFilePath MockFreeLogClass([string]$logFile) { $this.LogFilePath = $logFile } [void]Log([string]$message) { Write-Verbose "Mock Log called with: $message" -Verbose } [void]Warn([string]$message) { Write-Verbose "Mock Warn called with: $message" -Verbose } [void]Error([string]$message) { Write-Verbose "Mock Error called with: $message" -Verbose } [void]Fail([string]$message) { Write-Verbose "Mock Fail called with: $message" -Verbose } } } Describe 'Write-LogFile Parameter Tests' { It 'Should have [CmdletBinding()] attribute' { (Get-Command Write-LogFile).CmdletBinding | Should -Be $true } It 'Should have all four parameters' { $params = (Get-Command Write-LogFile).Parameters.Keys $params | Should -Contain 'TaskMessage' $params | Should -Contain 'TaskWarn' $params | Should -Contain 'TaskError' $params | Should -Contain 'TaskFail' } } Describe 'Write-LogFile Initialization Tests' { BeforeEach { Remove-Variable -Name 'logger' -Scope 'Script' -ErrorAction SilentlyContinue } It 'Should throw when logger is not initialized' { { Write-LogFile -TaskMessage 'Test' } | Should -Throw 'Logger not initialized. Run New-LogFile first.' } } |