. $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 "Test-PackageHasDatabaseConfigFile" { # Describe fake package info. $source = "https://www.fakepackagerepo.com/nuget/fake.feed"; $name = "fake.package"; $version = "1.2.3"; # Fake responses from Invoke-WebRequest for mocked Get-PackageFileList $validDatabaseConfigPackage = "[{`"fullPath`":`"tools/Whatever.dll`",`"parentFullPath`":`"tools/`",`"name`":`"Whatever.dll`",`"isDirectory`":false},{`"fullPath`":`"DatabaseConfig.ps1`",`"parentFullPath`":`"/`",`"name`":`"DatabaseConfig.ps1`",`"isDirectory`":false}]" $invalidDatabaseConfigPackage = "[{`"fullPath`":`"tools/Whatever.dll`",`"parentFullPath`":`"tools/`",`"name`":`"Whatever.dll`",`"isDirectory`":false},{`"fullPath`":`"src/DatabaseConfig.ps1`",`"parentFullPath`":`"/src`",`"name`":`"DatabaseConfig.ps1`",`"isDirectory`":false}]" $missingDatabaseConfigPackage = "[{`"fullPath`":`"package/files/otherfile.xml`",`"parentFullPath`":`"package/files/`",`"name`":`"otherfile.xml`",`"isDirectory`":false}]" Mock -CommandName Write-Host -ModuleName $moduleForMock -MockWith {} Mock -CommandName Get-LogLeadName -ModuleName $moduleForMock -MockWith {} Context "Package Has Database Config In Valid Path With Valid Name" { Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $validDatabaseConfigPackage) } It "Correctly Identifies Package Has a Database Config In Valid Path With Valid Name" { (Test-PackageHasDatabaseConfigFile -feedSource $source -Name $name -version $version) | Should -BeTrue } } Context "Package Has A Database Config That Is Not In Valid Path With Valid Name" { Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $invalidDatabaseConfigPackage) } It "Correctly Identifies Package Has A Database Config Not In Valid Path With Valid Name" { (Test-PackageHasDatabaseConfigFile -feedSource $source -Name $name -version $version) | Should -BeFalse } } Context "Not a Package With a Database Config" { Mock -CommandName Get-PackageFileListV2 -ModuleName $moduleForMock -MockWith { return @(ConvertFrom-Json -InputObject $missingDatabaseConfigPackage) } It "Returns False Because Package Does Not Have A Database Config" { (Test-PackageHasDatabaseConfigFile -feedSource $source -Name $name -version $version) | Should -BeFalse } } }