Tests/Invoke-OriAzBopDownloadPackage.tests.ps1
. $PSScriptRoot\..\Enum\Get-Constant.ps1 . $PSScriptRoot\..\Public\Invoke-OriAzBopDownloadPackage.ps1 # Keep the description in syntax <ModuleName\TestedScripts> will allow us quick idefntification failing test. Describe 'OriAzCodOriAzCodCiOnlineDeployment\Invoke-OriAzBopDownloadPackage' { Context 'Test of sucessfull processing Invoke-OriAzBopDownloadPackage ' { # Mock part allow us simulate output of all particular calculations Mock -CommandName Install-Package -Verifiable Mock -CommandName Find-Package -Verifiable -MockWith { return @{ Version = '1.2.3' Name = 'Ori.Online.Website' Source = 'DeploymentPackages' } } Mock -CommandName Write-Output -Verifiable # Act part is execution the teste script with prefabricated input values. See the part Example in the script itself. it 'Should be succesfully processed' { $password = ConvertTo-SecureString 'passowrd1' -AsPlainText -Force $RepositoryCredential = New-Object System.Management.Automation.PSCredential 'Wuhan@myemail.com', $password Invoke-OriAzBopDownloadPackage ` -RepositoryCredential $RepositoryCredential ` -Artifacts @(@{Source = 'DeploymentPackages'; Name = 'Ori.Online.Website'; RequiredVersion = '1.2.3'; Force = $True }) ` -Verbose } Assert-MockCalled -CommandName Find-Package -Times 1 -Exactly -ParameterFilter { $Name -eq "Ori.Online.Website" } Assert-MockCalled -CommandName Install-Package -Times 1 -Exactly -ParameterFilter { $Name -eq "Ori.Online.Website" ` -and $RequiredVersion -eq "1.2.3" ` -and $Source -eq "DeploymentPackages" } Assert-VerifiableMock } } |