. $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 = "" Describe "Get-CoalescedStringValue" { Context "Logic" { It "Returns ValueA if it Is Not Null, Empty, or WhiteSpace" { $valueA = "I am the very model" $valueB = "of a modern Major-General" Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be $valueA } It "Returns ValueB if ValueA is Null" { $valueA = $null $valueB = "I've information vegetable, animal, and mineral" Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be $valueB } It "Returns ValueB if ValueA is Whitespace" { $valueA = " " $valueB = "I know the kings of England, and I quote the fights Historical" Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be $valueB } It "Returns ValueB if ValueA is an Empty String" { $valueA = "" $valueB = "From Marathon to Waterloo, in order categorical" Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be $valueB } } Context "Edge Cases" { It "Returns an empty string and Writes a Warning if ValueA and ValueB are Both Null" { Mock -CommandName Write-Warning -ModuleName $moduleForMock -MockWith {} $valueA = $null $valueB = $null Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be ([String]::Empty) Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 1 -Exactly -Scope It ` -ParameterFilter { $Message -Match "Value B is null, empty, or whitespace." } } It "Returns ValueB and Writes a Warning if ValueA is null and ValueB is Whitespace" { Mock -CommandName Write-Warning -ModuleName $moduleForMock -MockWith {} $valueA = $null $valueB = " " Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be $valueB Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 1 -Exactly -Scope It ` -ParameterFilter { $Message -Match "Value B is null, empty, or whitespace." } } It "Returns ValueB and Writes a Warning if ValueA is null and ValueB is an Empty String" { Mock -CommandName Write-Warning -ModuleName $moduleForMock -MockWith {} $valueA = $null $valueB = "" Get-CoalescedStringValue -ValueA $valueA -ValueB $valueB | Should Be $valueB Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 1 -Exactly -Scope It ` -ParameterFilter { $Message -Match "Value B is null, empty, or whitespace." } } } }