-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from pspete/dev
Feature 11.5
- Loading branch information
Showing
54 changed files
with
2,475 additions
and
197 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
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,81 @@ | ||
Describe $($PSCommandPath -Replace ".Tests.ps1") { | ||
|
||
BeforeAll { | ||
#Get Current Directory | ||
$Here = Split-Path -Parent $PSCommandPath | ||
|
||
#Assume ModuleName from Repository Root folder | ||
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf | ||
|
||
#Resolve Path to Module Directory | ||
$ModulePath = Resolve-Path "$Here\..\$ModuleName" | ||
|
||
#Define Path to Module Manifest | ||
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1" | ||
|
||
if ( -not (Get-Module -Name $ModuleName -All)) { | ||
|
||
Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop | ||
|
||
} | ||
|
||
$Script:RequestBody = $null | ||
$Script:BaseURI = "https://SomeURL/SomeApp" | ||
$Script:ExternalVersion = "0.0" | ||
$Script:WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession | ||
|
||
} | ||
|
||
|
||
AfterAll { | ||
|
||
$Script:RequestBody = $null | ||
|
||
} | ||
|
||
InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) { | ||
|
||
Context "General" { | ||
|
||
BeforeEach { | ||
|
||
$InputObj = @{ | ||
Property1 = "Value" | ||
Property2 = "Another Value" | ||
} | ||
|
||
} | ||
|
||
It "does not throw" { | ||
|
||
{ ConvertTo-QueryString } | Should -Not -Throw | ||
|
||
} | ||
|
||
It "produces no output if given no input" { | ||
|
||
ConvertTo-QueryString | Should -BeNullOrEmpty | ||
|
||
} | ||
|
||
It "converts hashtable to expected query string" { | ||
|
||
$InputObj | ConvertTo-QueryString | Should -Match "Value&Property" | ||
$InputObj | ConvertTo-QueryString | Should -Match "Property1=Value" | ||
$InputObj | ConvertTo-QueryString | Should -Match "Property2=Another%20Value" | ||
|
||
} | ||
|
||
It "converts hashtable to expected filter string" { | ||
|
||
$InputObj | ConvertTo-QueryString -Format Filter | Should -Match "%20AND%20" | ||
$InputObj | ConvertTo-QueryString -Format Filter | Should -Match "Property1%20eq%20Value" | ||
$InputObj | ConvertTo-QueryString -Format Filter | Should -Match "Property2%20eq%20Another%20Value" | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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,181 @@ | ||
Describe $($PSCommandPath -Replace ".Tests.ps1") { | ||
|
||
BeforeAll { | ||
#Get Current Directory | ||
$Here = Split-Path -Parent $PSCommandPath | ||
|
||
#Assume ModuleName from Repository Root folder | ||
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf | ||
|
||
#Resolve Path to Module Directory | ||
$ModulePath = Resolve-Path "$Here\..\$ModuleName" | ||
|
||
#Define Path to Module Manifest | ||
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1" | ||
|
||
if ( -not (Get-Module -Name $ModuleName -All)) { | ||
|
||
Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop | ||
|
||
} | ||
|
||
$Script:RequestBody = $null | ||
$Script:BaseURI = "https://SomeURL/SomeApp" | ||
$Script:ExternalVersion = "11.4" | ||
$Script:WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession | ||
|
||
} | ||
|
||
|
||
AfterAll { | ||
|
||
$Script:RequestBody = $null | ||
|
||
} | ||
|
||
InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) { | ||
|
||
Context "Mandatory Parameters" { | ||
|
||
$Parameters = @{Parameter = 'TargetPlatform' }, | ||
@{Parameter = 'DependentPlatform' }, | ||
@{Parameter = 'GroupPlatform' }, | ||
@{Parameter = 'RotationalGroup' }, | ||
@{Parameter = 'ID' }, | ||
@{Parameter = 'name' } | ||
|
||
It "specifies parameter <Parameter> as mandatory" -TestCases $Parameters { | ||
|
||
param($Parameter) | ||
|
||
(Get-Command Copy-PASPlatform).Parameters["$Parameter"].Attributes.Mandatory | Should -Be $true | ||
|
||
} | ||
|
||
} | ||
|
||
Context "Input" { | ||
|
||
BeforeEach { | ||
Mock Invoke-PASRestMethod -MockWith { | ||
[PSCustomObject]@{"Prop1" = "Val1"; "Prop2" = "Val2" } | ||
} | ||
|
||
$InputObj = [pscustomobject]@{ | ||
"name" = "SomeName" | ||
"ID" = 1234 | ||
} | ||
|
||
$response = $InputObj | Copy-PASPlatform -TargetPlatform | ||
|
||
} | ||
|
||
It "sends request" { | ||
|
||
Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "sends request to expected endpoint - TargetPlatform" { | ||
|
||
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { | ||
|
||
$URI -eq "$($Script:BaseURI)/API/Platforms/targets/1234/duplicate" | ||
|
||
} -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "sends request to expected endpoint - DependentPlatform" { | ||
$response = $InputObj | Copy-PASPlatform -DependentPlatform | ||
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { | ||
|
||
$URI -eq "$($Script:BaseURI)/API/Platforms/dependents/1234/duplicate" | ||
|
||
} -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "sends request to expected endpoint - RotationalGroup" { | ||
|
||
$response = $InputObj | Copy-PASPlatform -RotationalGroup | ||
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { | ||
|
||
$URI -eq "$($Script:BaseURI)/API/Platforms/rotationalGroups/1234/duplicate" | ||
|
||
} -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "sends request to expected endpoint - GroupPlatform" { | ||
|
||
$response = $InputObj | Copy-PASPlatform -GroupPlatform | ||
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { | ||
|
||
$URI -eq "$($Script:BaseURI)/API/Platforms/groups/1234/duplicate" | ||
|
||
} -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "uses expected method" { | ||
|
||
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "sends request with expected body" { | ||
|
||
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { | ||
|
||
$Script:RequestBody = $Body | ConvertFrom-Json | ||
|
||
($Script:RequestBody) -ne $null | ||
|
||
} -Times 1 -Exactly -Scope It | ||
|
||
} | ||
|
||
It "has a request body with expected number of properties" { | ||
|
||
($Script:RequestBody | Get-Member -MemberType NoteProperty).length | Should -Be 1 | ||
|
||
} | ||
|
||
It "throws error if version requirement not met" { | ||
$Script:ExternalVersion = "11.0" | ||
{ $InputObj | Copy-PASPlatform -GroupPlatform } | Should -Throw | ||
$Script:ExternalVersion = "0.0" | ||
} | ||
|
||
} | ||
|
||
Context "Output" { | ||
|
||
BeforeEach { | ||
|
||
$Script:ExternalVersion = "11.4" | ||
Mock Invoke-PASRestMethod -MockWith { | ||
[PSCustomObject]@{"Prop1" = "Val1"; "Prop2" = "Val2" } | ||
} | ||
|
||
$InputObj = [pscustomobject]@{ | ||
"name" = "SomeName" | ||
"ID" = 1234 | ||
} | ||
|
||
$response = $InputObj | Copy-PASPlatform -TargetPlatform | ||
|
||
} | ||
|
||
it "provides output" { | ||
|
||
$response | Should -Not -BeNullOrEmpty | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.