Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out Unit tests #285

Merged
merged 55 commits into from
Mar 30, 2020
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
af7da7c
VSTeamAccessControlEntry tests moved to seperate file.
DarqueWarrior Mar 12, 2020
8618a55
Get-VSTeamAccessControlList tests moved to seperate file.
DarqueWarrior Mar 12, 2020
508f3dd
Trying to track down macOS CI build fail.
DarqueWarrior Mar 12, 2020
d6175a4
Take two
DarqueWarrior Mar 12, 2020
33903da
Fixed Get-VSTeamAccessControlList tests
DarqueWarrior Mar 12, 2020
7082450
Fixing Add-VSTeamAccessControlEntry
DarqueWarrior Mar 12, 2020
cadebf2
Profile Tests research.
DarqueWarrior Mar 12, 2020
3d50daa
Looks like value is Null on macOS instead of ''
DarqueWarrior Mar 12, 2020
adef81c
output $PSVersionTable
DarqueWarrior Mar 12, 2020
8a140e7
Trying to test versions
DarqueWarrior Mar 12, 2020
9afd33c
wrong mock is being called on macOS
DarqueWarrior Mar 12, 2020
a799515
Fixing profile tests on PowerShell 7.
DarqueWarrior Mar 12, 2020
31ad077
Merge branch 'master' into unittest
DarqueWarrior Mar 13, 2020
a5ee343
Agent and Pool tests broken out.
DarqueWarrior Mar 13, 2020
3e21094
Approval tests broken out.
DarqueWarrior Mar 13, 2020
4e5771c
BuildDefinition test broken out.
DarqueWarrior Mar 13, 2020
380dea0
WorkItemType tests broken out
DarqueWarrior Mar 13, 2020
ef0c118
Merge remote-tracking branch 'origin' into unittest
DarqueWarrior Mar 14, 2020
df8b707
Build test broken out.
DarqueWarrior Mar 15, 2020
2207b31
Moved Add-VSTeamAccessControlEntry json to sample files.
DarqueWarrior Mar 15, 2020
4beecec
Removed InModuleScope from Add-VSTeamPullRequest
DarqueWarrior Mar 15, 2020
1ad0172
Polished Get-VSTeamClassificationNode tests
DarqueWarrior Mar 15, 2020
f70b8af
Polished Get-VSTeamCloudSubscription tests
DarqueWarrior Mar 15, 2020
28a15ba
Polished common tests
DarqueWarrior Mar 15, 2020
e504cb2
Polished Get-VSTeamDescriptor tests
DarqueWarrior Mar 15, 2020
445ab9b
Polished VSTeamExtension tests
DarqueWarrior Mar 16, 2020
771573c
Polished VSTeamFeed tests.
DarqueWarrior Mar 16, 2020
04bd0a0
Polish VSTeamGitCommit tests
DarqueWarrior Mar 16, 2020
e344caa
Polished VSTeamGitStat tests
DarqueWarrior Mar 16, 2020
76847b9
Polish VSTeamRelease tests
DarqueWarrior Mar 16, 2020
e9c6e62
More test polish
DarqueWarrior Mar 16, 2020
e285cb2
Polish Add-VSTeamGitRepositoryPermission tests
DarqueWarrior Mar 17, 2020
9daf278
Unit test refactor checkpoint
DarqueWarrior Mar 20, 2020
c653e09
Fixing some tests.
DarqueWarrior Mar 20, 2020
5c973e1
VSTeamMembership tests broken out.
DarqueWarrior Mar 20, 2020
96f4119
Made tests more reliable
DarqueWarrior Mar 20, 2020
f480dc2
VSTeamPolicy tests broken out.
DarqueWarrior Mar 20, 2020
31c1c94
VSTeamPolicyType tests broken out.
DarqueWarrior Mar 20, 2020
a04c94c
VSTeamPool test broken out.
DarqueWarrior Mar 20, 2020
7358a7a
Unit test checkpoint
DarqueWarrior Mar 21, 2020
340576f
VSTeamProject test broken out.
DarqueWarrior Mar 21, 2020
d42dbfd
VSTeamPullRequest test broken out
DarqueWarrior Mar 22, 2020
b51a833
VSTeamQueue tests polished
DarqueWarrior Mar 22, 2020
fb3af13
VSTeamGitRef tests polished
DarqueWarrior Mar 23, 2020
fab5ac2
VSTeamRelease tests broken out.
DarqueWarrior Mar 23, 2020
17cde57
Unit Test checkpoint
DarqueWarrior Mar 23, 2020
373f370
Check point
DarqueWarrior Mar 23, 2020
3068006
VSTeamWorkItemIterationPermission and VSTeamWorkItemAreaPermission te…
DarqueWarrior Mar 24, 2020
26ca9fd
VSTeamWorkItem tests broken out.
DarqueWarrior Mar 24, 2020
2ee16ea
added _getApiVersion to ease testing.
DarqueWarrior Mar 25, 2020
4f7aac6
Only classes are tested with inmodulescope
DarqueWarrior Mar 29, 2020
1cefd85
Fixed broken unit tests of last build.
DarqueWarrior Mar 29, 2020
d22f688
Breakout class tests.
DarqueWarrior Mar 30, 2020
f8af88e
Update cred scan supression file.
DarqueWarrior Mar 30, 2020
f427f6e
InModuleScope has been removed from all unit tests.
DarqueWarrior Mar 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unit Test checkpoint
DarqueWarrior committed Mar 23, 2020
commit 17cde57353c137dbb2d4afdd9062597401a6354f
88 changes: 88 additions & 0 deletions unit/test/Add-VSTeamGitRepository.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Set-StrictMode -Version Latest

#region include
Import-Module SHiPS

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")

. "$here/../../Source/Classes/VSTeamLeaf.ps1"
. "$here/../../Source/Classes/VSTeamDirectory.ps1"
. "$here/../../Source/Classes/VSTeamVersions.ps1"
. "$here/../../Source/Classes/VSTeamProjectCache.ps1"
. "$here/../../Source/Classes/VSTeamUserEntitlement.ps1"
. "$here/../../Source/Classes/VSTeamTeams.ps1"
. "$here/../../Source/Classes/VSTeamRepositories.ps1"
. "$here/../../Source/Classes/VSTeamReleaseDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamTask.ps1"
. "$here/../../Source/Classes/VSTeamAttempt.ps1"
. "$here/../../Source/Classes/VSTeamEnvironment.ps1"
. "$here/../../Source/Classes/VSTeamRelease.ps1"
. "$here/../../Source/Classes/VSTeamReleases.ps1"
. "$here/../../Source/Classes/VSTeamBuild.ps1"
. "$here/../../Source/Classes/VSTeamBuilds.ps1"
. "$here/../../Source/Classes/VSTeamQueues.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhaseStep.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhase.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcess.ps1"
. "$here/../../Source/Classes/VSTeamPool.ps1"
. "$here/../../Source/Classes/VSTeamQueue.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinition.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/Get-VSTeamQueue.ps1"
. "$here/../../Source/Public/Remove-VSTeamAccount.ps1"
. "$here/../../Source/Public/Get-VSTeamBuildDefinition.ps1"
. "$here/../../Source/Public/Get-VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/$sut"
#endregion

$singleResult = [PSCustomObject]@{
id = ''
url = ''
sshUrl = ''
remoteUrl = ''
defaultBranch = ''
size = 0
name = 'testRepo'
project = [PSCustomObject]@{
name = 'Project'
id = 1
description = ''
url = ''
state = ''
revision = ''
visibility = ''
}
}

Describe "VSTeamGitRepository" {
## Arrange
# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter { $Uri -like "*_apis/projects*" }

. "$PSScriptRoot\mocks\mockProjectNameDynamicParam.ps1"

Mock Invoke-RestMethod {
# Write-Host "Single $Uri"
return $singleResult } -ParameterFilter {
$Uri -like "*00000000-0000-0000-0000-000000000000*" -or
$Uri -like "*testRepo*" -or
$Body -like "*testRepo*"
}

Context 'Add-VSTeamGitRepository' {
Mock _getInstance { return 'https://dev.azure.com/test' }

It 'by name should add Git repo' {
Add-VSTeamGitRepository -Name 'testRepo' -ProjectName 'test'
Assert-VerifiableMock
}
}
}
73 changes: 73 additions & 0 deletions unit/test/Add-VSTeamReleaseDefinition.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Set-StrictMode -Version Latest

#region include
$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/Get-VSTeamProject.ps1"
. "$here/../../Source/Public/$sut"
#endregion

Describe 'VSTeamReleaseDefinition' {
[VSTeamVersions]::Release = '1.0-unittest'

$results = [PSCustomObject]@{
value = [PSCustomObject]@{
queue = [PSCustomObject]@{ name = 'Default' }
_links = [PSCustomObject]@{
self = [PSCustomObject]@{ }
web = [PSCustomObject]@{ }
}
retentionPolicy = [PSCustomObject]@{ }
lastRelease = [PSCustomObject]@{ }
artifacts = [PSCustomObject]@{ }
modifiedBy = [PSCustomObject]@{ name = 'project' }
createdBy = [PSCustomObject]@{ name = 'test' }
}
}

# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter {
$Uri -like "*_apis/projects*"
}

Context 'Add-VSTeamReleaseDefinition' {
Mock Invoke-RestMethod { return $results }

Context 'Services' {
Mock _getInstance { return 'https://dev.azure.com/test' }

it 'should add release' {
## Act
Add-VSTeamReleaseDefinition -projectName project -inFile 'Releasedef.json'

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter {
$Method -eq 'Post' -and
$InFile -eq 'Releasedef.json' -and
$Uri -eq "https://vsrm.dev.azure.com/test/project/_apis/release/definitions?api-version=$([VSTeamVersions]::Release)"
}
}
}

Context 'Server' {
Mock _useWindowsAuthenticationOnPremise { return $true }
Mock _getInstance { return 'http://localhost:8080/tfs/defaultcollection' }

it 'local Auth should add release' {
## Act
Add-VSTeamReleaseDefinition -projectName project -inFile 'Releasedef.json'

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter {
$Method -eq 'Post' -and
$InFile -eq 'Releasedef.json' -and
$Uri -eq "http://localhost:8080/tfs/defaultcollection/project/_apis/release/definitions?api-version=$([VSTeamVersions]::Release)"
}
}
}
}
}
193 changes: 193 additions & 0 deletions unit/test/Get-VSTeamGitRepository.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
Set-StrictMode -Version Latest

#region include
Import-Module SHiPS

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")

. "$here/../../Source/Classes/VSTeamLeaf.ps1"
. "$here/../../Source/Classes/VSTeamDirectory.ps1"
. "$here/../../Source/Classes/VSTeamVersions.ps1"
. "$here/../../Source/Classes/VSTeamProjectCache.ps1"
. "$here/../../Source/Classes/VSTeamUserEntitlement.ps1"
. "$here/../../Source/Classes/VSTeamTeams.ps1"
. "$here/../../Source/Classes/VSTeamRepositories.ps1"
. "$here/../../Source/Classes/VSTeamReleaseDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamTask.ps1"
. "$here/../../Source/Classes/VSTeamAttempt.ps1"
. "$here/../../Source/Classes/VSTeamEnvironment.ps1"
. "$here/../../Source/Classes/VSTeamRelease.ps1"
. "$here/../../Source/Classes/VSTeamReleases.ps1"
. "$here/../../Source/Classes/VSTeamBuild.ps1"
. "$here/../../Source/Classes/VSTeamBuilds.ps1"
. "$here/../../Source/Classes/VSTeamQueues.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhaseStep.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhase.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcess.ps1"
. "$here/../../Source/Classes/VSTeamPool.ps1"
. "$here/../../Source/Classes/VSTeamQueue.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinition.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/Get-VSTeamQueue.ps1"
. "$here/../../Source/Public/Remove-VSTeamAccount.ps1"
. "$here/../../Source/Public/Get-VSTeamBuildDefinition.ps1"
. "$here/../../Source/Public/Get-VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/$sut"
#endregion

$results = [PSCustomObject]@{
value = [PSCustomObject]@{
id = ''
url = ''
sshUrl = ''
remoteUrl = ''
defaultBranch = ''
size = 0
name = ''
project = [PSCustomObject]@{
name = 'Project'
id = 1
description = ''
url = ''
state = ''
revision = ''
visibility = ''
}
}
}

$singleResult = [PSCustomObject]@{
id = ''
url = ''
sshUrl = ''
remoteUrl = ''
defaultBranch = ''
size = 0
name = ''
project = [PSCustomObject]@{
name = 'Project'
id = 1
description = ''
url = ''
state = ''
revision = ''
visibility = ''
}
}

Describe "VSTeamGitRepository" {
## Arrange
# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter { $Uri -like "*_apis/projects*" }

. "$PSScriptRoot\mocks\mockProjectNameDynamicParam.ps1"

Mock Invoke-RestMethod {
# Write-Host "results $Uri"
return $results }
Mock Invoke-RestMethod {
# Write-Host "Single $Uri"
return $singleResult } -ParameterFilter {
$Uri -like "*00000000-0000-0000-0000-000000000000*" -or
$Uri -like "*testRepo*"
}
Mock Invoke-RestMethod {
# Write-Host "boom $Uri"
throw [System.Net.WebException] } -ParameterFilter {
$Uri -like "*00000000-0000-0000-0000-000000000101*" -or
$Uri -like "*boom*"
}

Context 'Get-VSTeamGitRepository' {
Context 'Services' {
## Arrange
# 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' }

It 'no parameters should return all repos for all projects' {
## Act
Get-VSTeamGitRepository

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -eq "https://dev.azure.com/test/_apis/git/repositories?api-version=3.0"
}
}

It 'by Id should return a single repo by id' {
## Act
Get-VSTeamGitRepository -id 00000000-0000-0000-0000-000000000000

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -eq "https://dev.azure.com/test/_apis/git/repositories/00000000-0000-0000-0000-000000000000?api-version=3.0"
}
}

It 'by name should return a single repo by name' {
## Act
Get-VSTeamGitRepository -Name 'testRepo'

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -eq "https://dev.azure.com/test/_apis/git/repositories/testRepo?api-version=3.0"
}
}

It 'by id should throw' {
## Act / Assert
{ Get-VSTeamGitRepository -id 00000000-0000-0000-0000-000000000101 } | Should Throw
}

It 'by name should throw' {
## Act / Assert
{ Get-VSTeamGitRepository -Name 'boom' } | Should Throw
}
}

Context 'Server' {
Mock _getInstance { return 'http://localhost:8080/tfs/defaultcollection' }

Mock _useWindowsAuthenticationOnPremise { return $true }

It 'no parameters Should return Git repo' {
## Act
Get-VSTeamGitRepository

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -eq "http://localhost:8080/tfs/defaultcollection/_apis/git/repositories?api-version=3.0"
}
}

It 'by Id should return a single repo by id' {
## Act
Get-VSTeamGitRepository -id 00000000-0000-0000-0000-000000000000

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -eq "http://localhost:8080/tfs/defaultcollection/_apis/git/repositories/00000000-0000-0000-0000-000000000000?api-version=3.0"
}
}

It 'by name should return a single repo by name' {
## Act
Get-VSTeamGitRepository -Name 'testRepo'

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -eq "http://localhost:8080/tfs/defaultcollection/_apis/git/repositories/testRepo?api-version=3.0"
}
}
}
}
}
122 changes: 122 additions & 0 deletions unit/test/Remove-VSTeamGitRepository.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Set-StrictMode -Version Latest

#region include
Import-Module SHiPS

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")

. "$here/../../Source/Classes/VSTeamLeaf.ps1"
. "$here/../../Source/Classes/VSTeamDirectory.ps1"
. "$here/../../Source/Classes/VSTeamVersions.ps1"
. "$here/../../Source/Classes/VSTeamProjectCache.ps1"
. "$here/../../Source/Classes/VSTeamUserEntitlement.ps1"
. "$here/../../Source/Classes/VSTeamTeams.ps1"
. "$here/../../Source/Classes/VSTeamRepositories.ps1"
. "$here/../../Source/Classes/VSTeamReleaseDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamTask.ps1"
. "$here/../../Source/Classes/VSTeamAttempt.ps1"
. "$here/../../Source/Classes/VSTeamEnvironment.ps1"
. "$here/../../Source/Classes/VSTeamRelease.ps1"
. "$here/../../Source/Classes/VSTeamReleases.ps1"
. "$here/../../Source/Classes/VSTeamBuild.ps1"
. "$here/../../Source/Classes/VSTeamBuilds.ps1"
. "$here/../../Source/Classes/VSTeamQueues.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhaseStep.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhase.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcess.ps1"
. "$here/../../Source/Classes/VSTeamPool.ps1"
. "$here/../../Source/Classes/VSTeamQueue.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinition.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/Get-VSTeamQueue.ps1"
. "$here/../../Source/Public/Remove-VSTeamAccount.ps1"
. "$here/../../Source/Public/Get-VSTeamBuildDefinition.ps1"
. "$here/../../Source/Public/Get-VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/$sut"
#endregion

$singleResult = [PSCustomObject]@{
id = ''
url = ''
sshUrl = ''
remoteUrl = ''
defaultBranch = ''
size = 0
name = ''
project = [PSCustomObject]@{
name = 'Project'
id = 1
description = ''
url = ''
state = ''
revision = ''
visibility = ''
}
}

Describe "VSTeamGitRepository" {
## Arrange
# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter { $Uri -like "*_apis/projects*" }

. "$PSScriptRoot\mocks\mockProjectNameDynamicParam.ps1"

Mock Invoke-RestMethod {
# Write-Host "Single $Uri"
return $singleResult } -ParameterFilter {
$Uri -like "*00000000-0000-0000-0000-000000000000*" -or
$Uri -like "*testRepo*"
}
Mock Invoke-RestMethod {
# Write-Host "boom $Uri"
throw [System.Net.WebException] } -ParameterFilter {
$Uri -like "*00000000-0000-0000-0000-000000000101*" -or
$Uri -like "*boom*"
}

Context 'Remove-VSTeamGitRepository' {
Context 'Services' {
## Arrange
Mock _getInstance { return 'https://dev.azure.com/test' }

It 'by id should remove Git repo' {
## Act
Remove-VSTeamGitRepository -id 00000000-0000-0000-0000-000000000000 -Force

## Assert
Assert-MockCalled Invoke-RestMethod -ParameterFilter {
$Method -eq 'Delete' -and
$Uri -eq "https://dev.azure.com/test/_apis/git/repositories/00000000-0000-0000-0000-000000000000?api-version=$([VSTeamVersions]::Git)"
}
}

It 'by Id should throw' {
{ Remove-VSTeamGitRepository -id 00000000-0000-0000-0000-000000000101 -Force } | Should Throw
}
}

Context 'Server' {
## Arrange
Mock _getInstance { return 'http://localhost:8080/tfs/defaultcollection' }

It 'by id should remove Git repo' {
## Act
Remove-VSTeamGitRepository -id 00000000-0000-0000-0000-000000000000 -Force

## Assert
Assert-MockCalled Invoke-RestMethod -ParameterFilter {
$Method -eq 'Delete' -and
$Uri -eq "http://localhost:8080/tfs/defaultcollection/_apis/git/repositories/00000000-0000-0000-0000-000000000000?api-version=$([VSTeamVersions]::Git)"
}
}
}
}
}
72 changes: 72 additions & 0 deletions unit/test/Remove-VSTeamReleaseDefinition.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Set-StrictMode -Version Latest

#region include
$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/Get-VSTeamProject.ps1"
. "$here/../../Source/Public/$sut"
#endregion

Describe 'VSTeamReleaseDefinition' {
## Arrange
[VSTeamVersions]::Release = '1.0-unittest'

. "$PSScriptRoot\mocks\mockProjectNameDynamicParamNoPSet.ps1"

$results = [PSCustomObject]@{
value = [PSCustomObject]@{
queue = [PSCustomObject]@{ name = 'Default' }
_links = [PSCustomObject]@{
self = [PSCustomObject]@{ }
web = [PSCustomObject]@{ }
}
retentionPolicy = [PSCustomObject]@{ }
lastRelease = [PSCustomObject]@{ }
artifacts = [PSCustomObject]@{ }
modifiedBy = [PSCustomObject]@{ name = 'project' }
createdBy = [PSCustomObject]@{ name = 'test' }
}
}

# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter { $Uri -like "*_apis/projects*" }

Context 'Remove-VSTeamReleaseDefinition' {
Mock Invoke-RestMethod { return $results }

Context 'Services' {
Mock _getInstance { return 'https://dev.azure.com/test' }

It 'should delete release definition' {
## Act
Remove-VSTeamReleaseDefinition -projectName project -id 2 -Force

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter {
$Method -eq 'Delete' -and
$Uri -eq "https://vsrm.dev.azure.com/test/project/_apis/release/definitions/2?api-version=$([VSTeamVersions]::Release)"
}
}
}

Context 'Server' {
Mock _useWindowsAuthenticationOnPremise { return $true }
Mock _getInstance { return 'http://localhost:8080/tfs/defaultcollection' }

It 'local Auth should delete release definition' {
## Act
Remove-VSTeamReleaseDefinition -projectName project -id 2 -Force

## Assert
Assert-MockCalled Invoke-RestMethod -Exactly -Scope Context -Times 1 -ParameterFilter {
$Method -eq 'Delete' -and
$Uri -eq "http://localhost:8080/tfs/defaultcollection/project/_apis/release/definitions/2?api-version=$([VSTeamVersions]::Release)"
}
}
}
}
}
72 changes: 72 additions & 0 deletions unit/test/Show-VSTeamGitRepository.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Set-StrictMode -Version Latest

#region include
Import-Module SHiPS

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")

. "$here/../../Source/Classes/VSTeamLeaf.ps1"
. "$here/../../Source/Classes/VSTeamDirectory.ps1"
. "$here/../../Source/Classes/VSTeamVersions.ps1"
. "$here/../../Source/Classes/VSTeamProjectCache.ps1"
. "$here/../../Source/Classes/VSTeamUserEntitlement.ps1"
. "$here/../../Source/Classes/VSTeamTeams.ps1"
. "$here/../../Source/Classes/VSTeamRepositories.ps1"
. "$here/../../Source/Classes/VSTeamReleaseDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamTask.ps1"
. "$here/../../Source/Classes/VSTeamAttempt.ps1"
. "$here/../../Source/Classes/VSTeamEnvironment.ps1"
. "$here/../../Source/Classes/VSTeamRelease.ps1"
. "$here/../../Source/Classes/VSTeamReleases.ps1"
. "$here/../../Source/Classes/VSTeamBuild.ps1"
. "$here/../../Source/Classes/VSTeamBuilds.ps1"
. "$here/../../Source/Classes/VSTeamQueues.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitions.ps1"
. "$here/../../Source/Classes/VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhaseStep.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcessPhase.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinitionProcess.ps1"
. "$here/../../Source/Classes/VSTeamPool.ps1"
. "$here/../../Source/Classes/VSTeamQueue.ps1"
. "$here/../../Source/Classes/VSTeamBuildDefinition.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/Get-VSTeamQueue.ps1"
. "$here/../../Source/Public/Remove-VSTeamAccount.ps1"
. "$here/../../Source/Public/Get-VSTeamBuildDefinition.ps1"
. "$here/../../Source/Public/Get-VSTeamProject.ps1"
. "$here/../../Source/Classes/VSTeamGitRepository.ps1"
. "$here/../../Source/Private/common.ps1"
. "$here/../../Source/Private/applyTypes.ps1"
. "$here/../../Source/Public/$sut"
#endregion

Describe "VSTeamGitRepository" {
## Arrange
# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter { $Uri -like "*_apis/projects*" }

. "$PSScriptRoot\mocks\mockProjectNameDynamicParam.ps1"

Context 'Show-VSTeamGitRepository' {
Mock Show-Browser
Mock _getInstance { return 'https://dev.azure.com/test' }

it 'by project should return url for mine' {
Show-VSTeamGitRepository -projectName project

Assert-MockCalled Show-Browser -Exactly -Times 1 -Scope It -ParameterFilter {
$url -eq 'https://dev.azure.com/test/_git/project'
}
}

it 'by remote url should return url for mine' {
Show-VSTeamGitRepository -RemoteUrl 'https://dev.azure.com/test/_git/project'
Assert-MockCalled Show-Browser -Exactly -Times 1 -Scope It -ParameterFilter {
$url -eq 'https://dev.azure.com/test/_git/project'
}
}
}
}
35 changes: 35 additions & 0 deletions unit/test/Show-VSTeamReleaseDefinition.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Set-StrictMode -Version Latest

#region include
$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/Get-VSTeamProject.ps1"
. "$here/../../Source/Public/$sut"
#endregion

Describe 'VSTeamReleaseDefinition' {
## Arrange
[VSTeamVersions]::Release = '1.0-unittest'

. "$PSScriptRoot\mocks\mockProjectNameDynamicParamNoPSet.ps1"

# Mock the call to Get-Projects by the dynamic parameter for ProjectName
Mock Invoke-RestMethod { return @() } -ParameterFilter { $Uri -like "*_apis/projects*" }

Context 'Show-VSTeamReleaseDefinition' {
Mock Show-Browser { }
Mock _getInstance { return 'https://dev.azure.com/test' }

it 'by Id should return release definitions' {
Show-VSTeamReleaseDefinition -projectName project -Id 15

Assert-MockCalled Show-Browser -Exactly -Scope It -Times 1 -ParameterFilter {
$url -eq 'https://dev.azure.com/test/project/_release?definitionId=15'
}
}
}
}
2 changes: 1 addition & 1 deletion unit/test/Update-VSTeamAgent.Tests.ps1
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here/../../Source/Public/$sut"

Describe 'Update-VSTeamAgent' {
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable
Mock _getInstance { return 'https://dev.azure.com/test' }
[VSTeamVersions]::DistributedTask = '1.0-unitTest'

Context 'Update-VSTeamAgent by ID' {
12 changes: 7 additions & 5 deletions unit/test/Update-VSTeamProject.Tests.ps1
Original file line number Diff line number Diff line change
@@ -41,11 +41,13 @@ $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
#endregion

Describe 'VSTeamProject' {
Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable
[VSTeamVersions]::Core = '1.0-unitTest'

. "$PSScriptRoot\mocks\mockProjectNameDynamicParam.ps1"
. "$PSScriptRoot\mocks\mockProcessNameDynamicParam.ps1"

Mock _getInstance { return 'https://dev.azure.com/test' } -Verifiable

$singleResult = [PSCustomObject]@{
name = 'Test'
description = ''
@@ -61,7 +63,7 @@ Describe 'VSTeamProject' {
Context 'Update-VSTeamProject' {
Mock Invoke-RestMethod { return $singleResult }
Mock Invoke-RestMethod { return $singleResult } -ParameterFilter { $Uri -eq "https://dev.azure.com/test/_apis/projects/Test?api-version=$([VSTeamVersions]::Core)" }
Mock Invoke-RestMethod { return @{status = 'inProgress'; url = 'https://someplace.com'} } -ParameterFilter { $Method -eq 'Patch'}
Mock Invoke-RestMethod { return @{status = 'inProgress'; url = 'https://someplace.com' } } -ParameterFilter { $Method -eq 'Patch' }
Mock _trackProjectProgress
Mock Invoke-RestMethod { return $singleResult } -ParameterFilter { $Uri -eq "https://dev.azure.com/test/_apis/projects/Testing123?api-version=$([VSTeamVersions]::Core)" }

@@ -75,7 +77,7 @@ Describe 'VSTeamProject' {
Update-VSTeamProject -ProjectName Test -newName Testing123 -Force

Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Uri -eq "https://dev.azure.com/test/_apis/projects/Test?api-version=$([VSTeamVersions]::Core)" }
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Method -eq 'Patch' -and $Body -eq '{"name": "Testing123"}'}
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Method -eq 'Patch' -and $Body -eq '{"name": "Testing123"}' }
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Uri -eq "https://dev.azure.com/test/_apis/projects/Testing123?api-version=$([VSTeamVersions]::Core)" }
}

@@ -90,7 +92,7 @@ Describe 'VSTeamProject' {
Update-VSTeamProject -ProjectName Test -newName Testing123 -newDescription Testing123 -Force

Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Uri -eq "https://dev.azure.com/test/_apis/projects/Test?api-version=$([VSTeamVersions]::Core)" }
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Method -eq 'Patch'}
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Method -eq 'Patch' }
Assert-MockCalled Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter { $Uri -eq "https://dev.azure.com/test/_apis/projects/Testing123?api-version=$([VSTeamVersions]::Core)" }
}
}
105 changes: 0 additions & 105 deletions unit/test/releaseDefinitions.Tests.ps1

This file was deleted.

212 changes: 0 additions & 212 deletions unit/test/repositories.Tests.ps1

This file was deleted.