. $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 'Publish-SSRSReportsDirectory' { $reportDirectory = $env:TEMP $reportFolder = "foo report" $reportHashLocation = "someHashLocation" $webServiceUrl = "http:\\foo.com" mock -ModuleName $moduleForMock Get-ChildItem -MockWith { [PSCustomObject] ` @{ Name = '.\someReport.rdl' } } mock -ModuleName $moduleForMock Get-Content -MockWith { [xml] " SQL Data Source=JunkSource;Initial Catalog=JunkCatalog true 00000000-0000-0000-0000-000000000000 Fizz-Buzz " } mock -ModuleName $moduleForMock Import-Csv -MockWith { [PSCustomObject] ` @{ Algorithm = "SHA256" Hash = "I'm a matching hash" Path = ".\someReport.rdl" } } mock -ModuleName $moduleForMock Publish-SSRSReport -MockWith { 123 } mock -ModuleName $moduleForMock Start-Job -MockWith { Invoke-Command -ScriptBlock {'Do Nothing'} -ComputerName localhost -AsJob } mock -ModuleName $moduleForMock Wait-Job -MockWith {$null} it "should not throw when reportHashLocation is null" { mock -ModuleName $moduleForMock Get-FileHash -MockWith { [PSCustomObject] ` @{ Algorithm = "SHA256" Hash = "I'm a matching hash" Path = ".\someReport.rdl" } } { Publish-SSRSReportsDirectory $reportDirectory $webServiceUrl $reportFolder -avoidDoubleHop $true -Verbose } ` | should -Not -Throw } it "should call Start-Job when a provided reportHashLocation is null" { mock -ModuleName $moduleForMock Get-FileHash -MockWith { [PSCustomObject] ` @{ Algorithm = "SHA256" Hash = "I'm a matching hash" Path = ".\someReport.rdl" } } Publish-SSRSReportsDirectory $reportDirectory $webServiceUrl $reportFolder -avoidDoubleHop $true -Verbose Assert-MockCalled -ModuleName $moduleForMock Start-Job -Scope It } it "should call start-job when a provided hash doesn't match" { mock -ModuleName $moduleForMock Get-FileHash -mockwith { [PSCustomObject] ` @{ Algorithm = "SHA256" Hash = "I'm a mismatched hash" Path = ".\someReport.rdl" } } Publish-SSRSReportsDirectory $reportdirectory $webserviceurl $reportfolder -avoiddoublehop $true -filehashlocation $reportHashLocation -verbose Assert-MockCalled -ModuleName $moduleForMock Start-Job -scope it } it "should not call start-job when a provided hash matches" { mock -ModuleName $moduleForMock Get-FileHash -mockwith { [PSCustomObject] ` @{ Algorithm = "SHA256" Hash = "I'm a matching hash" Path = ".\someReport.rdl" } } Publish-SSRSReportsDirectory $reportdirectory $webserviceurl $reportfolder -avoiddoublehop $true -filehashlocation $reportHashLocation -verbose Assert-MockCalled -ModuleName $moduleForMock Start-Job -exactly 0 -scope it } }