Last active
November 19, 2018 14:47
-
-
Save rdbartram/d3ade6177b006cfcdcf93e330766a18d to your computer and use it in GitHub Desktop.
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
Describe 'Get-PodcastImage' { | |
BeforeAll { | |
. $PSScriptRoot\function-Get-PodcastImage.ps1 | |
$TestData = (Get-Content $PSScriptRoot\ObjectMother\RSSData.json -Raw | ConvertFrom-Json) | ForEach-Object { | |
@{ | |
Data = $_ | |
ImageURL = $_.ImageURL | |
Exist = [int][bool]($i++ % 2) # makes odd indexes return false for exist | |
} | |
} | |
} | |
it 'should download <imageUrl> <exist> times' -TestCases $TestData[0..1] { | |
param( | |
$Data, $ImageUrl, $Exist | |
) | |
# Arrange | |
mock Invoke-WebRequest | |
$File = Split-Path $ImageUrl -Leaf | |
mock Test-Path -ParameterFilter { $Path -eq "C:\Temp\$File" } { !([Bool]$Exist) } | |
# Act | |
$null = Get-PodcastImage -rssData $Data -OutputPathFolder 'C:\Temp' | |
# Assert | |
Assert-MockCalled Invoke-WebRequest -ParameterFilter { $Uri -eq $ImageUrl -and $OutFile -eq "C:\Temp\$File" } -Times $exist -Exactly -Scope It | |
} | |
it 'should define parameter rssData as mandatory and as pipeline input' { | |
$Command = Get-Command Get-PodcastImage | |
$Command.Parameters["rssData"].Attributes.Mandatory | Should -BeTrue | |
$Command.Parameters["rssData"].Attributes.ValueFromPipeline | Should -BeTrue | |
$Command.Parameters["rssData"].Attributes.ValueFromPipelineByPropertyName | Should -BeTrue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment