From c1a26f4f4b2ef136d5fa406c1d3615c571a9525b Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 16 Aug 2019 14:14:31 +0100 Subject: [PATCH] Added Protect-Worksheet Tests --- __tests__/ProtectWorksheet.tests.ps1 | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 __tests__/ProtectWorksheet.tests.ps1 diff --git a/__tests__/ProtectWorksheet.tests.ps1 b/__tests__/ProtectWorksheet.tests.ps1 new file mode 100644 index 0000000..b465de6 --- /dev/null +++ b/__tests__/ProtectWorksheet.tests.ps1 @@ -0,0 +1,37 @@ +$path = "$Env:TEMP\test.xlsx" +Remove-Item -path $path -ErrorAction SilentlyContinue +$excel = ConvertFrom-Csv @" +Product, City, Gross, Net +Apple, London , 300, 250 +Orange, London , 400, 350 +Banana, London , 300, 200 +Orange, Paris, 600, 500 +Banana, Paris, 300, 200 +Apple, New York, 1200,700 + +"@ | Export-Excel -Path $path -WorksheetName Sheet1 -PassThru + +$ws = $excel.sheet1 + +Set-WorkSheetProtection -WorkSheet $ws -IsProtected -BlockEditObject -AllowFormatRows -UnLockAddress "1:1" + +Close-ExcelPackage -ExcelPackage $excel + +Describe "Setting worksheet protection " { + BeforeAll { + $excel = Open-ExcelPackage -Path $path + $ws = $ws = $excel.sheet1 + } + it "Turned on protection for the sheet " { + $ws.Protection.IsProtected | should be $true + } + it "Set sheet-wide protection options " { + $ws.Protection.AllowEditObject | should be $false + $ws.Protection.AllowFormatRows | should be $true + $ws.cells["a2"].Style.Locked | should be $true + } + it "Unprotected some cells " { + $ws.cells["a1"].Style.Locked | should be $false + } +} +