Scope fixes for TestDrive

This commit is contained in:
ili101
2019-08-26 20:02:18 +03:00
parent d1592f8739
commit ab2405edad
6 changed files with 103 additions and 104 deletions

View File

@@ -3,24 +3,24 @@
if ($PSVersionTable.PSVersion.Major -gt 5) { Write-Warning "Can't test grid view on V6 and later" }
else {Add-Type -AssemblyName System.Windows.Forms }
Describe "Compare Worksheet" {
BeforeAll {
Remove-Item -Path "TestDrive:\server*.xlsx"
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name, RequiredServices, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, DependentServices, MachineName
$s | Export-Excel -Path TestDrive:\server1.xlsx
#$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s
$row4Displayname = $s[2].DisplayName
$s[2].DisplayName = "Changed from the orginal"
$d = $s[-1] | Select-Object -Property *
$d.DisplayName = "Dummy Service"
$d.Name = "Dummy"
$s.Insert(3,$d)
$row6Name = $s[5].name
$s.RemoveAt(5)
$s | Export-Excel -Path TestDrive:\server2.xlsx
#Assume default worksheet name, (sheet1) and column header for key ("name")
$comp = compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" | Sort-Object -Property _row, _file
}
Context "Simple comparison output" {
BeforeAll {
Remove-Item -Path "TestDrive:\server*.xlsx"
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name, RequiredServices, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, DependentServices, MachineName
$s | Export-Excel -Path TestDrive:\server1.xlsx
#$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s
$row4Displayname = $s[2].DisplayName
$s[2].DisplayName = "Changed from the orginal"
$d = $s[-1] | Select-Object -Property *
$d.DisplayName = "Dummy Service"
$d.Name = "Dummy"
$s.Insert(3,$d)
$row6Name = $s[5].name
$s.RemoveAt(5)
$s | Export-Excel -Path TestDrive:\server2.xlsx
#Assume default worksheet name, (sheet1) and column header for key ("name")
$comp = compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" | Sort-Object -Property _row, _file
}
it "Found the right number of differences " {
$comp | should not beNullOrEmpty
$comp.Count | should be 4
@@ -55,7 +55,7 @@ Describe "Compare Worksheet" {
$ModulePath = (Get-Command -Name 'Compare-WorkSheet').Module.Path
$PowerShellExec = if ($PSEdition -eq 'Core') {'pwsh.exe'} else {'powershell.exe'}
$PowerShellPath = Join-Path -Path $PSHOME -ChildPath $PowerShellExec
. $PowerShellPath -Command ("Import-Module $ModulePath; " + '$null = Compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView; Start-Sleep -sec 5')
. $PowerShellPath -Command ('Import-Module {0}; $null = Compare-WorkSheet "{1}Server1.xlsx" "{1}Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView; Start-Sleep -sec 5' -f $ModulePath, (Resolve-Path 'TestDrive:').ProviderPath)
}
else {
$null = Compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView:$useGrid
@@ -186,29 +186,29 @@ Describe "Compare Worksheet" {
}
Describe "Merge Worksheet" {
BeforeAll {
Remove-Item -Path "TestDrive:\server*.xlsx" , "TestDrive:\Combined*.xlsx" -ErrorAction SilentlyContinue
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property *
$s | Export-Excel -Path TestDrive:\server1.xlsx
#$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s
$s[2].DisplayName = "Changed from the orginal"
$d = $s[-1] | Select-Object -Property *
$d.DisplayName = "Dummy Service"
$d.Name = "Dummy"
$s.Insert(3,$d)
$s.RemoveAt(5)
$s | Export-Excel -Path TestDrive:\server2.xlsx
#Assume default worksheet name, (sheet1) and column header for key ("name")
Merge-Worksheet -Referencefile "TestDrive:\server1.xlsx" -Differencefile "TestDrive:\Server2.xlsx" -OutputFile "TestDrive:\combined1.xlsx" -Property name,displayname,startType -Key name
$excel = Open-ExcelPackage -Path "TestDrive:\combined1.xlsx"
$ws = $excel.Workbook.Worksheets["sheet1"]
}
Context "Merge with 3 properties" {
BeforeAll {
Remove-Item -Path "TestDrive:\server*.xlsx" , "TestDrive:\Combined*.xlsx" -ErrorAction SilentlyContinue
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property *
$s | Export-Excel -Path TestDrive:\server1.xlsx
#$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s
$s[2].DisplayName = "Changed from the orginal"
$d = $s[-1] | Select-Object -Property *
$d.DisplayName = "Dummy Service"
$d.Name = "Dummy"
$s.Insert(3,$d)
$s.RemoveAt(5)
$s | Export-Excel -Path TestDrive:\server2.xlsx
#Assume default worksheet name, (sheet1) and column header for key ("name")
Merge-Worksheet -Referencefile "TestDrive:\server1.xlsx" -Differencefile "TestDrive:\Server2.xlsx" -OutputFile "TestDrive:\combined1.xlsx" -Property name,displayname,startType -Key name
$excel = Open-ExcelPackage -Path "TestDrive:\combined1.xlsx"
$ws = $excel.Workbook.Worksheets["sheet1"]
}
it "Created a worksheet with the correct headings " {
$ws | should not beNullOrEmpty
$ws.Cells[ 1,1].Value | Should be "name"