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
59Describe " 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+ }
0 commit comments