diff --git a/Examples/TestRestAPI/TestAPIReadXls.ps1 b/Examples/TestRestAPI/TestAPIReadXls.ps1 new file mode 100644 index 0000000..38df9be --- /dev/null +++ b/Examples/TestRestAPI/TestAPIReadXls.ps1 @@ -0,0 +1,41 @@ +function Test-APIReadXls { + param( + [parameter(Mandatory)] + $XlFilename, + $WorksheetName = 'Sheet1' + ) + + $records = Import-Excel $XlFilename + + $params = @{} + + $blocks = $(foreach ($record in $records) { + foreach ($propertyName in $record.psobject.properties.name) { + if ($propertyName -notmatch 'ExpectedResult|QueryString') { + $params.$propertyName = $record.$propertyName + } + } + + if ($record.QueryString) { + $params.Uri += "?{0}" -f $record.QueryString + } + +@" + + it "Should have the expected result '$($record.ExpectedResult)'" { + `$target = '$($params | ConvertTo-Json -compress)' | ConvertFrom-Json + `$target.psobject.Properties.name | % {`$p=@{}} {`$p.`$_=`$(`$target.`$_)} + Invoke-RestMethod @p | Should Be '$($record.ExpectedResult)' + } + +"@ + }) + +@" +Describe "Tests from $($XlFilename) in $($WorksheetName)" { +$($blocks) +} +"@ +} + +Test-APIReadXls .\testlist.xlsx \ No newline at end of file diff --git a/Examples/TestRestAPI/testlist.xlsx b/Examples/TestRestAPI/testlist.xlsx new file mode 100644 index 0000000..6e02ef5 Binary files /dev/null and b/Examples/TestRestAPI/testlist.xlsx differ