-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding -UseProjectId support Sepearted related tests to seperate files. * Changed mock to return object instead of hashtable.
- Loading branch information
1 parent
90ad303
commit 8e28722
Showing
13 changed files
with
468 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
### -UseProjectId | ||
|
||
Converts the project name to project id before building the URI for the REST API call. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Required: false | ||
Position: Named | ||
Accept pipeline input: false | ||
Parameter Sets: (All) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Set-StrictMode -Version Latest | ||
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") | ||
|
||
. "$here/../../Source/Classes/VSTeamVersions.ps1" | ||
. "$here/../../Source/Classes/VSTeamProjectCache.ps1" | ||
. "$here/../../Source/Private/common.ps1" | ||
. "$here/../../Source/Public/$sut" | ||
|
||
Describe 'Get-VSTeamInfo' { | ||
# Mock the call to Get-Projects by the dynamic parameter for ProjectName | ||
Mock Invoke-RestMethod { return @() } -ParameterFilter { | ||
$Uri -like "*_apis/projects*" | ||
} | ||
|
||
. "$PSScriptRoot\mocks\mockProjectDynamicParamMandatoryFalse.ps1" | ||
|
||
Context 'Get-VSTeamInfo' { | ||
AfterAll { | ||
$Global:PSDefaultParameterValues.Remove("*:projectName") | ||
} | ||
|
||
It 'should return account and default project' { | ||
[VSTeamVersions]::Account = "mydemos" | ||
$Global:PSDefaultParameterValues['*:projectName'] = 'TestProject' | ||
|
||
$info = Get-VSTeamInfo | ||
|
||
$info.Account | Should Be "mydemos" | ||
$info.DefaultProject | Should Be "TestProject" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Set-StrictMode -Version Latest | ||
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") | ||
|
||
. "$here/../../Source/Classes/VSTeamVersions.ps1" | ||
. "$here/../../Source/Classes/VSTeamProjectCache.ps1" | ||
. "$here/../../Source/Private/common.ps1" | ||
. "$here/../../Source/Private/applyTypes.ps1" | ||
. "$here/../../Source/Public/$sut" | ||
|
||
Describe 'Get-VSTeamOption' { | ||
Context 'Get-VSTeamOption' { | ||
# Set the account to use for testing. A normal user would do this | ||
# using the Set-VSTeamAccount function. | ||
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable | ||
|
||
Mock Invoke-RestMethod { return @{ | ||
count = 1 | ||
value = @( | ||
@{ | ||
id = '5e8a8081-3851-4626-b677-9891cc04102e' | ||
area = 'git' | ||
resourceName = 'annotatedTags' | ||
} | ||
) | ||
} | ||
} | ||
|
||
It 'Should return all options' { | ||
Get-VSTeamOption | Should Not Be $null | ||
Assert-MockCalled Invoke-RestMethod -ParameterFilter { | ||
$Uri -eq "https://dev.azure.com/test/_apis" | ||
} | ||
} | ||
|
||
It 'Should return release options' { | ||
Get-VSTeamOption -subDomain vsrm | Should Not Be $null | ||
Assert-MockCalled Invoke-RestMethod -ParameterFilter { | ||
$Uri -eq "https://vsrm.dev.azure.com/test/_apis" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Set-StrictMode -Version Latest | ||
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") | ||
|
||
. "$here/../../Source/Classes/VSTeamVersions.ps1" | ||
. "$here/../../Source/Classes/VSTeamProjectCache.ps1" | ||
. "$here/../../Source/Private/common.ps1" | ||
. "$here/../../Source/Private/applyTypes.ps1" | ||
. "$here/../../Source/Public/$sut" | ||
|
||
Describe 'Get-VSTeamResourceArea' { | ||
Context 'Get-VSTeamResourceArea' { | ||
Mock _callAPI { return @{ | ||
value = @{ } | ||
} | ||
} | ||
|
||
$actual = Get-VSTeamResourceArea | ||
|
||
It 'Should return resources' { | ||
$actual | Should Not Be $null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
Set-StrictMode -Version Latest | ||
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") | ||
|
||
. "$here/../../Source/Classes/VSTeamVersions.ps1" | ||
. "$here/../../Source/Classes/VSTeamProjectCache.ps1" | ||
. "$here/../../Source/Private/common.ps1" | ||
. "$here/../../Source/Public/$sut" | ||
|
||
Describe 'Invoke-VSTeamRequest' { | ||
# Mock the call to Get-Projects by the dynamic parameter for ProjectName | ||
Mock Invoke-RestMethod { | ||
return @() | ||
} -ParameterFilter { | ||
$Uri -like "*_apis/projects*" | ||
} | ||
|
||
Mock Write-Host | ||
|
||
Context 'Invoke-VSTeamRequest Options' { | ||
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable | ||
Mock Invoke-RestMethod { | ||
# Write-Host $args | ||
} | ||
|
||
Invoke-VSTeamRequest -Method Options | ||
|
||
It 'Should call API' { | ||
Assert-VerifiableMock | ||
} | ||
} | ||
|
||
Context 'Invoke-VSTeamRequest Release' { | ||
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable | ||
Mock Invoke-RestMethod { | ||
# Write-Host $args | ||
} -Verifiable | ||
|
||
Invoke-VSTeamRequest -Area release -Resource releases -Id 1 -SubDomain vsrm -Version '4.1-preview' -ProjectName testproject -JSON | ||
|
||
It 'Should call API' { | ||
Assert-VerifiableMock | ||
} | ||
} | ||
|
||
Context 'Invoke-VSTeamRequest AdditionalHeaders' { | ||
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable | ||
Mock Invoke-RestMethod { return @() } -Verifiable -ParameterFilter { | ||
$Headers["Test"] -eq 'Test' | ||
} | ||
|
||
Invoke-VSTeamRequest -Area release -Resource releases -Id 1 -SubDomain vsrm -Version '4.1-preview' -ProjectName testproject -JSON -AdditionalHeaders @{Test = "Test" } | ||
|
||
It 'Should call API' { | ||
Assert-VerifiableMock | ||
} | ||
} | ||
|
||
Context 'Invoke-VSTeamRequest By Product ID' { | ||
# Called to convert from ProjectName to ProjectID | ||
Mock Get-VSTeamProject { | ||
return [PSCustomObject]@{ | ||
id = '00000000-0000-0000-0000-000000000000' | ||
} } -Verifiable | ||
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable | ||
Mock Invoke-RestMethod { return @() } -Verifiable -ParameterFilter { | ||
$Uri -like "*https://vsrm.dev.azure.com/test/00000000-0000-0000-0000-000000000000*" | ||
} | ||
|
||
Invoke-VSTeamRequest -ProjectName testproject -UseProjectId -Area release -Resource releases -Id 1 -SubDomain vsrm -Version '4.1-preview' | ||
|
||
It 'Should call API' { | ||
Assert-VerifiableMock | ||
} | ||
} | ||
} |
Oops, something went wrong.