Tests/Register-OriAzBopRepository.tests.ps1
. $PSScriptRoot\..\Enum\Get-Constant.ps1 . $PSScriptRoot\..\Private\Register-OriAzBopInternalPackageSource.ps1 . $PSScriptRoot\..\Private\Register-OriAzBopInternalPSRepository.ps1 . $PSScriptRoot\..\Private\Get-OriAzBopInternalPackageSource.ps1 . $PSScriptRoot\..\Public\Register-OriAzBopRepository.ps1 # Keep the description in syntax <ModuleName\TestedScripts> will allow us quick idefntification failing test. Describe 'OriAzCodOriAzCodCiOnlineDeployment\Register-OriAzBopRepository' { Context 'Test of sucessfull processing Register-OriAzBopRepository ' { Mock -CommandName Unregister-PSRepository -Verifiable Mock -CommandName Get-PSRepository -Verifiable -MockWith { return @() } Mock -CommandName Register-OriAzBopInternalPSRepository -Verifiable Mock -CommandName Get-OriAzBopInternalPackageSource -Verifiable -MockWith { return @() } Mock -CommandName Register-OriAzBopInternalPackageSource -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 'heslo1' -AsPlainText -Force $RepositoryCredential = New-Object System.Management.Automation.PSCredential 'Wuhan@myemail.com', $password Register-OriAzBopRepository ` -DevOpsAccount 'oriflame' ` -RepositoryCredential $RepositoryCredential ` -PsProjectName @('PackageManagementFeed') ` -NugetProjectName @('DeploymentPackages') } Assert-MockCalled -CommandName Unregister-PSRepository -Times 1 -Exactly Assert-MockCalled -CommandName Get-PSRepository -Times 1 -Exactly Assert-MockCalled -CommandName Get-OriAzBopInternalPackageSource -Times 1 -Exactly Assert-MockCalled -CommandName Register-OriAzBopInternalPSRepository -Times 1 -Exactly Assert-MockCalled -CommandName Register-OriAzBopInternalPackageSource -Times 1 -Exactly Assert-VerifiableMock } Context 'Test of sucessfull processing Register-OriAzBopRepository ' { Mock -CommandName Unregister-PSRepository -Verifiable Mock -CommandName Get-PSRepository -Verifiable -MockWith { return @() } Mock -CommandName Register-OriAzBopInternalPSRepository -Verifiable Mock -CommandName Get-OriAzBopInternalPackageSource -Verifiable -MockWith { return @() } Mock -CommandName Register-OriAzBopInternalPackageSource -Verifiable Mock -CommandName Write-Verbose -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 with Verbose' { $password = ConvertTo-SecureString 'heslo1' -AsPlainText -Force $RepositoryCredential = New-Object System.Management.Automation.PSCredential 'Wuhan@myemail.com', $password Register-OriAzBopRepository ` -DevOpsAccount 'oriflame' ` -RepositoryCredential $RepositoryCredential ` -PsProjectName @('PackageManagementFeed') ` -NugetProjectName @('DeploymentPackages') ` -Verbose } Assert-MockCalled -CommandName Unregister-PSRepository -Times 1 -Exactly Assert-MockCalled -CommandName Get-PSRepository -Times 1 -Exactly Assert-MockCalled -CommandName Get-OriAzBopInternalPackageSource -Times 2 -Exactly Assert-MockCalled -CommandName Register-OriAzBopInternalPSRepository -Times 1 -Exactly Assert-MockCalled -CommandName Register-OriAzBopInternalPackageSource -Times 1 -Exactly Assert-VerifiableMock } } |