Skip to content

Commit 8b74226

Browse files
committed
Issue #821
1 parent 03c3c6f commit 8b74226

10 files changed

+263
-142
lines changed

Modules/Remoting Tests - Download with RemoteScriptCall.ps1 renamed to Modules/Remoting Tests - Download with RemoteScriptCall.Tests.ps1

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
Import-Module -Name SPE -Force
2-
Import-Module -Name Pester -Force
1+
param(
2+
[Parameter()]
3+
[string]$protocolHost = "http://spe.dev.local"
4+
)
5+
6+
Import-Module -Name SPE -Force
37

48
# Download single file
59
Describe "Download with RemoteScriptCall" {
@@ -10,7 +14,7 @@ Describe "Download with RemoteScriptCall" {
1014
}
1115
New-Item -Path $destinationMediaPath -ItemType Directory | Out-Null
1216

13-
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri "https://spe.dev.local"
17+
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
1418
}
1519
AfterEach {
1620
Stop-ScriptSession -Session $session
@@ -59,7 +63,7 @@ Describe "Download with RemoteScriptCall" {
5963
Test-Path -Path $destination | Should Be $true
6064
}
6165
It "download from the Package root path" {
62-
$filename = "SPE Remoting-3.2.zip"
66+
$filename = "readme.txt"
6367
$destination = Join-Path -Path $destinationMediaPath -ChildPath $filename
6468
Receive-RemoteItem -Session $session -Destination $destination -Path $filename -RootPath Package
6569
Test-Path -Path $destination | Should Be $true
@@ -79,8 +83,8 @@ Describe "Download with RemoteScriptCall" {
7983
}
8084
Context "Single fully qualified file" {
8185
It "download fully qualified file" {
82-
$filename = "sc-ee.js"
83-
$pathFolder = "C:\Websites\spe.dev.local\Data\tools\phantomjs\"
86+
$filename = "kitten.jpg"
87+
$pathFolder = Join-Path -Path $PSScriptRoot -ChildPath "spe-test"
8488
$path = Join-Path -Path $pathFolder -ChildPath $filename
8589
$destination = Join-Path -Path $destinationMediaPath -ChildPath $filename
8690
Receive-RemoteItem -Session $session -Path $path -Destination $destination
@@ -118,23 +122,51 @@ Describe "Download with RemoteScriptCall" {
118122
Test-Path -Path $destination | Should Be $true
119123
}
120124
}
121-
}
125+
Context "Advanced/mixed scenarios" {
126+
It "Download first 3 log files" {
127+
$files = Invoke-RemoteScript -Session $session -ScriptBlock {
128+
Get-ChildItem -Path "$($SitecoreLogFolder)" | Where-Object { !$_.PSIsContainer } | Select-Object -Expand Name -First 3
129+
}
130+
131+
$files |
132+
ForEach-Object {
133+
$destination = Join-Path -Path $destinationMediaPath -ChildPath $_
134+
Receive-RemoteItem -Session $session -Destination $destination -Path $_ -RootPath Log
135+
Test-Path -Path $destination | Should Be $true
136+
}
137+
}
122138

123-
exit
124-
# Download multiple files using the filename.
125-
Invoke-RemoteScript @props -ScriptBlock {
126-
Get-ChildItem -Path "$($SitecoreLogFolder)" | Where-Object { !$_.PSIsContainer } | Select-Object -Expand Name
127-
} | Receive-RemoteItem @receiveProps -RootPath Log
139+
It "Download all SPE log files as ZIP" {
140+
$archiveFileName = Invoke-RemoteScript -Session $session -ScriptBlock {
141+
Import-Function -Name Compress-Archive
142+
Get-ChildItem -Path "$($SitecoreLogFolder)" | Where-Object { !$_.PSIsContainer -and $_.Name -match "spe.log." } |
143+
Compress-Archive -DestinationPath "$($SitecoreTempFolder)\archived.SPE.logs.zip" | Select-Object -Expand FullName
144+
}
145+
146+
$destination = Join-Path -Path $destinationMediaPath -ChildPath (Split-Path -Path $archiveFileName -Leaf)
147+
Receive-RemoteItem -Session $session -Destination $destination -Path $archiveFileName
148+
149+
Test-Path -Path $destination | Should Be $true
128150

129-
# Download single zip file using the fully qualified name.
130-
Invoke-RemoteScript @props -ScriptBlock {
131-
Import-Function -Name Compress-Archive
132-
Get-ChildItem -Path "$($SitecoreLogFolder)" | Where-Object { !$_.PSIsContainer } |
133-
Compress-Archive -DestinationPath "$($SitecoreDataFolder)archived.zip" | Select-Object -Expand FullName
134-
} | Receive-RemoteItem @receiveProps
151+
Invoke-RemoteScript -Session $session -ScriptBlock {
152+
Remove-Item -Path "$($using:archiveFileName)"
153+
Test-Path "$($using:archiveFileName)"
154+
} | Should Be $false
155+
}
156+
It "Download first 10 Media Items from Media Library" {
157+
$mediaItemNames = Invoke-RemoteScript -Session $session -ScriptBlock {
158+
Get-ChildItem -Path "master:/sitecore/media library/" -Recurse | Where-Object { $_.Size -gt 0 } |
159+
Select-Object -First 10 | Foreach-Object { "$($_.ItemPath).$($_.Extension)" }
160+
}
135161

136-
# Download multiple media items
137-
Invoke-RemoteScript @props -ScriptBlock {
138-
Get-ChildItem -Path "master:/sitecore/media library/" -Recurse | Where-Object { $_.Size -gt 0 } |
139-
Select-Object -First 10 | Select-Object -Expand ItemPath
140-
} | Receive-RemoteItem @receiveProps -Database master
162+
$mediaItemNames | Foreach-Object {
163+
$source= Join-Path ([System.IO.Path]::GetDirectoryName($_)) ([System.IO.Path]::GetFileNameWithoutExtension($_))
164+
$destination = Join-Path -Path $destinationMediaPath -ChildPath $_
165+
Receive-RemoteItem -Session $session -Destination $destination -Path $source -Database master
166+
Test-Path -Path $destination | Should Be $true
167+
}
168+
169+
170+
}
171+
}
172+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
param(
2+
[Parameter()]
3+
[string]$protocolHost = "http://spe.dev.local"
4+
)
5+
6+
Import-Module -Name SPE -Force
7+
8+
if(!$protocolHost){
9+
$protocolHost = "http://spe.dev.local"
10+
}
11+
12+
Describe "Long running server jobs" {
13+
BeforeEach {
14+
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
15+
Test-RemoteConnection -Session $session -Quiet
16+
}
17+
AfterEach {
18+
Stop-ScriptSession -Session $session
19+
}
20+
21+
It "Rebuild link databases" {
22+
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
23+
"master", "web" | Get-Database |
24+
ForEach-Object {
25+
[Sitecore.Globals]::LinkDatabase.Rebuild($_)
26+
}
27+
} -AsJob
28+
Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 5 -Verbose
29+
}
30+
It "Rebuild search indexes" {
31+
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
32+
(Rebuild-SearchIndex -Name sitecore_master_index -AsJob).Handle.ToString()
33+
}
34+
Wait-RemoteSitecoreJob -Session $session -Id $jobId -Delay 5 -Verbose
35+
}
36+
It "Republish Site" {
37+
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
38+
(Publish-Item -Path "master:\" -PublishMode Full -Recurse -RepublishAll -AsJob).Handle.ToString()
39+
}
40+
Wait-RemoteSitecoreJob -Session $session -Id $jobId -Delay 2 -Verbose
41+
}
42+
It "Smart Publish Site" {
43+
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
44+
(Publish-Item -Path "master:\" -PublishMode Smart -Recurse -AsJob).Handle.ToString()
45+
}
46+
Wait-RemoteSitecoreJob -Session $session -Id $jobId -Delay 2 -Verbose
47+
}
48+
It "Smart Publish item with children and related items" {
49+
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
50+
(Publish-Item -Path "master:\content\home" -PublishMode SingleItem -Recurse -PublishRelatedItems -AsJob).Handle.ToString()
51+
}
52+
Wait-RemoteSitecoreJob -Session $session -Id $jobId -Delay 2 -Verbose
53+
}
54+
It "Incremental Publish Site" {
55+
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
56+
(Publish-Item -Path "master:\" -PublishMode Incremental -FromDate "03/17/2016" -AsJob).Handle.ToString()
57+
}
58+
Wait-RemoteSitecoreJob -Session $session -Id $jobId -Delay 2 -Verbose
59+
}
60+
}

Modules/Remoting Tests - Maintenance.ps1

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
param(
2+
[Parameter()]
3+
[string]$protocolHost = "http://spe.dev.local"
4+
)
5+
6+
Import-Module -Name SPE -Force
7+
8+
if(!$protocolHost){
9+
$protocolHost = "http://spe.dev.local"
10+
}
11+
12+
$count = 0
13+
Describe "Invoke multiple sessions" {
14+
It "Should return 'admin' user 20 consecutive times without errors" {
15+
do {
16+
$session = New-ScriptSession -Username "admin" -Password "b" -ConnectionUri $protocolHost
17+
18+
$script1 = {
19+
[Sitecore.Security.Accounts.User]$user = Get-User -Identity admin
20+
$user
21+
}
22+
23+
$user = Invoke-RemoteScript -ScriptBlock $script1 -Session $session
24+
25+
$user | Should BeOftype System.Management.Automation.PSObject
26+
$user.Name | Should Be sitecore\admin
27+
28+
Stop-ScriptSession -Session $session
29+
30+
$count++
31+
} while($count -lt 20)
32+
}
33+
}

Modules/Remoting Tests - Multiple Script Sessions.ps1

Lines changed: 0 additions & 18 deletions
This file was deleted.

Modules/Remoting Tests - RemotingAutomation.ps1 renamed to Modules/Remoting Tests - RemotingAutomation.Tests.ps1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
Import-Module -Name SPE -Force
2-
Import-Module -Name Pester -Force
1+
param(
2+
[Parameter()]
3+
[string]$protocolHost = "http://spe.dev.local"
4+
)
5+
6+
Import-Module -Name SPE -Force
7+
8+
if(!$protocolHost){
9+
$protocolHost = "http://spe.dev.local"
10+
}
311

412
Describe "Invoke remote scripts with RemotingAutomation" {
513
BeforeEach {
6-
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri "https://spe.dev.local"
14+
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
715
}
816
AfterEach {
917
Stop-ScriptSession -Session $session
@@ -19,5 +27,8 @@ Describe "Invoke remote scripts with RemotingAutomation" {
1927
$actual = Invoke-RemoteScript -Session $session -ScriptBlock { Get-User -Id $using:expected | Select-Object -ExpandProperty Name }
2028
$actual | Should Be $expected
2129
}
30+
It "Sitecore Kittens should not exist" {
31+
Invoke-RemoteScript -Session $session -ScriptBlock { $myints = @(1,1,2,3,5,8,13); $myints } | Should Throw
32+
}
2233
}
2334
}

Modules/Remoting Tests - Upload with RemoteScriptCall.ps1 renamed to Modules/Remoting Tests - Upload with RemoteScriptCall.Tests.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
Import-Module -Name SPE -Force
2-
Import-Module -Name Pester -Force
1+
param(
2+
[Parameter()]
3+
[string]$protocolHost = "http://spe.dev.local"
4+
)
5+
6+
Import-Module -Name SPE -Force
7+
8+
if(!$protocolHost){
9+
$protocolHost = "http://spe.dev.local"
10+
}
311

412
Describe "Upload with RemoteScriptCall" {
513
BeforeEach {
6-
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri "https://spe.dev.local"
14+
$session = New-ScriptSession -Username "sitecore\admin" -Password "b" -ConnectionUri $protocolHost
715
$localFilePath = Join-Path -Path $PSScriptRoot -ChildPath "spe-test"
816
}
917
AfterEach {

0 commit comments

Comments
 (0)