. $PSScriptRoot\..\..\Load-PesterModules.ps1 $here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.' $functionPath = Join-Path -Path $here -ChildPath $sut Write-Host "Overriding SUT: $functionPath" Import-Module $functionPath -Force $moduleForMock = "" $FAKE_ORBLOGS = "TestDrive:\OrbLogs" $FAKE_NOT_ORBLOGS = "TestDrive:\NotOrbLogs" Describe "Remove-ORBLogFiles" { New-Item -Path $FAKE_ORBLOGS -ItemType Directory New-Item -Path $FAKE_NOT_ORBLOGS -ItemType Directory # CODEPATH: ALWAYS Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith {return "[UnitTest_Default]"} # CODEPATH: No LogDirectory param Mock -ModuleName $moduleForMock -CommandName Get-OrbLogsPath -MockWith {return $FAKE_ORBLOGS} # MUFFLER Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {} Mock -ModuleName $moduleForMock -CommandName Remove-Item -MockWith {} Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith {} Context "Parameters" { It "Get_LogLead" { Remove-ORBLogFiles Assert-MockCalled -CommandName Get-LogLeadName -ModuleName $moduleForMock -Scope It ` -Times 1 -Exactly } It "Get_GetOrbLogsPath_If_LogDirectory_Omitted" { Remove-ORBLogFiles Assert-MockCalled -CommandName Get-OrbLogsPath -ModuleName $moduleForMock -Scope It ` -Times 1 -Exactly } It "Skip_GetOrbLogsPath_If_LogDirectory_Passed" { Remove-ORBLogFiles -LogDirectory $FAKE_NOT_ORBLOGS Assert-MockCalled -CommandName Get-OrbLogsPath -ModuleName $moduleForMock -Scope It ` -Times 0 -Exactly } } Context "Log files path and remove tests" { It "TestPath is called" { Remove-ORBLogFiles -LogDirectory $FAKE_NOT_ORBLOGS Assert-MockCalled -CommandName Test-Path -ModuleName $moduleForMock -Scope It ` -Times 1 -Exactly } It "Remove-Item isn't called" { Remove-ORBLogFiles -LogDirectory $FAKE_NOT_ORBLOGS Assert-MockCalled -CommandName Remove-Item -ModuleName $moduleForMock -Scope It ` -Times 0 -Exactly } } }