. $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-IsPackageReliableService" { # Describe fake package info. $source = "https://www.fakepackagerepo.com/nuget/fake.feed"; $name = "fake.package"; $version = "1.2.3"; # Fake responses from Invoke-WebRequest $validReliableServicePackage = "[{`"fullPath`":`"ApplicationManifest.xml`",`"parentFullPath`":`"/`",`"name`":`"ApplicationManifest.xml`",`"isDirectory`":false},{`"fullPath`":`"svc/ServiceManifest.xml`",`"parentFullPath`":`"svc/`",`"name`":`"ServiceManifest.xml`",`"isDirectory`":false}]" $reliableServicePackageMissingServiceManifest = "[{`"fullPath`":`"ApplicationManifest.xml`",`"parentFullPath`":`"/`",`"name`":`"ApplicationManifest.xml`",`"isDirectory`":false}]" $reliableServicePackageMissingApplicationManifest = "[{`"fullPath`":`"svc/ServiceManifest.xml`",`"parentFullPath`":`"svc/`",`"name`":`"ServiceManifest.xml`",`"isDirectory`":false}]" $nonReliableServicePackage = "[{`"fullPath`":`"package/files/otherfile.xml`",`"parentFullPath`":`"package/files/`",`"name`":`"otherfile.xml`",`"isDirectory`":false}]" Context "Valid Reliable Service Package" { Mock -CommandName Get-PackageFileList -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $validReliableServicePackage) } It "Correctly Identifies a Reliable Service File List" { $result = Test-IsPackageReliableService -feedSource $source -name $name -version $version; $result | Should -be $true; } } Context "Incomplete Reliable Service Package - Missing Service Manifest" { Mock -CommandName Get-PackageFileList -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $reliableServicePackageMissingServiceManifest) } It "Returns False Because it is Missing a Service Manifest" { $result = Test-IsPackageReliableService -feedSource $source -name $name -version $version; $result | Should -be $false; } } Context "Incomplete Reliable Service Package - Missing Application Manifest" { Mock -CommandName Get-PackageFileList -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $reliableServicePackageMissingApplicationManifest) } It "Returns False Because it is Missing an Application Manifest" { $result = Test-IsPackageReliableService -feedSource $source -name $name -version $version; $result | Should -be $false; } } Context "Not A Reliable Service Package" { Mock -CommandName Get-PackageFileList -ModuleName $moduleForMock -MockWith { return (ConvertFrom-Json -InputObject $nonReliableServicePackage) } It "Returns False Because it is not a Reliable Service Package" { $result = Test-IsPackageReliableService -feedSource $source -name $name -version $version; $result | Should -be $false; } } # This is an invalid test. "Get-PackageFileList" should be mocked # This test should validate how this SUT responds when the return value of Get-PackageFileList is $null # The _behavior_ of this original test should be moved to tests for "Get-PackageFileList" instead <#Context "Bad Nuget Source" { $source = "https://www.badpackagerepo.com/bad.feed"; It "Fails Because the Source Feed URL is Badly Formatted" { { Test-IsPackageReliableService -feedSource $source -name $name -version $version -ErrorAction Stop} | Should -Throw; } }#> }