mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-12 14:23:14 +00:00
37
Examples/TestRestAPI/RunAndShowUnitTests.ps1
Normal file
37
Examples/TestRestAPI/RunAndShowUnitTests.ps1
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||||
|
|
||||||
|
$xlfilename=".\test.xlsx"
|
||||||
|
rm $xlfilename -ErrorAction Ignore
|
||||||
|
|
||||||
|
$ConditionalText = @()
|
||||||
|
$ConditionalText += New-ConditionalText -Range "C:C" -Text failed -BackgroundColor red -ConditionalTextColor black
|
||||||
|
$ConditionalText += New-ConditionalText -Range "C:C" -Text passed -BackgroundColor green -ConditionalTextColor black
|
||||||
|
|
||||||
|
$r = .\TryIt.ps1
|
||||||
|
|
||||||
|
$xlPkg = $(foreach($result in $r.TestResult) {
|
||||||
|
|
||||||
|
[PSCustomObject]@{
|
||||||
|
Name = $result.Name
|
||||||
|
#Time = $result.Time
|
||||||
|
Result = $result.Result
|
||||||
|
Messge = $result.FailureMessage
|
||||||
|
StackTrace = $result.StackTrace
|
||||||
|
}
|
||||||
|
|
||||||
|
}) | Export-Excel -Path $xlfilename -AutoSize -ConditionalText $ConditionalText -PassThru
|
||||||
|
|
||||||
|
$sheet1 = $xlPkg.Workbook.Worksheets["sheet1"]
|
||||||
|
|
||||||
|
$sheet1.View.ShowGridLines = $false
|
||||||
|
$sheet1.View.ShowHeaders = $false
|
||||||
|
|
||||||
|
Set-Format -Address $sheet1.Cells["A:A"] -AutoSize
|
||||||
|
Set-Format -Address $sheet1.Cells["B:D"] -WrapText
|
||||||
|
|
||||||
|
$sheet1.InsertColumn(1, 1)
|
||||||
|
Set-Format -Address $sheet1.Cells["A:A"] -Width 5
|
||||||
|
|
||||||
|
Set-Format -Address $sheet1.Cells["B1:E1"] -HorizontalAlignment Center -BorderBottom Thick -BorderColor Cyan
|
||||||
|
|
||||||
|
Close-ExcelPackage $xlPkg -Show
|
||||||
40
Examples/TestRestAPI/ShowPesterResults.ps1
Normal file
40
Examples/TestRestAPI/ShowPesterResults.ps1
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
function Show-PesterResults {
|
||||||
|
$xlfilename=".\test.xlsx"
|
||||||
|
rm $xlfilename -ErrorAction Ignore
|
||||||
|
|
||||||
|
$ConditionalText = @()
|
||||||
|
$ConditionalText += New-ConditionalText -Range "Result" -Text failed -BackgroundColor red -ConditionalTextColor black
|
||||||
|
$ConditionalText += New-ConditionalText -Range "Result" -Text passed -BackgroundColor green -ConditionalTextColor black
|
||||||
|
$ConditionalText += New-ConditionalText -Range "Result" -Text pending -BackgroundColor gray -ConditionalTextColor black
|
||||||
|
|
||||||
|
$xlParams = @{
|
||||||
|
Path=$xlfilename
|
||||||
|
WorkSheetname = 'PesterTests'
|
||||||
|
ConditionalText=$ConditionalText
|
||||||
|
PivotRows = 'Description'
|
||||||
|
PivotColumns = 'Result'
|
||||||
|
PivotData = @{'Result'='Count'}
|
||||||
|
IncludePivotTable = $true
|
||||||
|
#IncludePivotChart = $true
|
||||||
|
#NoLegend = $true
|
||||||
|
#ShowPercent = $true
|
||||||
|
#ShowCategory = $true
|
||||||
|
AutoSize = $true
|
||||||
|
AutoNameRange = $true
|
||||||
|
AutoFilter = $true
|
||||||
|
Show = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
$(foreach($result in (Invoke-Pester -PassThru -Show None).TestResult) {
|
||||||
|
|
||||||
|
[PSCustomObject]@{
|
||||||
|
Description = $result.Describe
|
||||||
|
Name = $result.Name
|
||||||
|
#Time = $result.Time
|
||||||
|
Result = $result.Result
|
||||||
|
Messge = $result.FailureMessage
|
||||||
|
StackTrace = $result.StackTrace
|
||||||
|
}
|
||||||
|
|
||||||
|
}) | Sort Description | Export-Excel @xlParams
|
||||||
|
}
|
||||||
49
Examples/TestRestAPI/TestAPIReadXls.ps1
Normal file
49
Examples/TestRestAPI/TestAPIReadXls.ps1
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||||
|
|
||||||
|
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 | ForEach-Object {`$p=@{}} {`$p.`$_=`$(`$target.`$_)}
|
||||||
|
|
||||||
|
Invoke-RestMethod @p | Should Be '$($record.ExpectedResult)'
|
||||||
|
}
|
||||||
|
|
||||||
|
"@
|
||||||
|
})
|
||||||
|
|
||||||
|
$testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss.fff")
|
||||||
|
|
||||||
|
@"
|
||||||
|
Describe "Tests from $($XlFilename) in $($WorksheetName)" {
|
||||||
|
$($blocks)
|
||||||
|
}
|
||||||
|
"@ | Set-Content -Encoding Ascii $testFileName
|
||||||
|
|
||||||
|
#Invoke-Pester -Script (Get-ChildItem $testFileName)
|
||||||
|
Get-ChildItem $testFileName
|
||||||
|
}
|
||||||
|
|
||||||
7
Examples/TestRestAPI/TryIt.ps1
Normal file
7
Examples/TestRestAPI/TryIt.ps1
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||||
|
|
||||||
|
. $PSScriptRoot\TestAPIReadXls.ps1
|
||||||
|
|
||||||
|
Test-APIReadXls $PSScriptRoot\testlist.xlsx | % {
|
||||||
|
Invoke-Pester -Script $_.fullname -PassThru -Show None
|
||||||
|
}
|
||||||
BIN
Examples/TestRestAPI/testlist.xlsx
Normal file
BIN
Examples/TestRestAPI/testlist.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user