@@ -498,6 +498,7 @@ public void SheetNameWriteReadTest()
498498 [ InlineData ( false , "" , "" , 0 ) ]
499499 [ InlineData ( false , "autoFilter:0,sort:0" , "" , 0 ) ]
500500 [ InlineData ( true , "" , "objects:1,scenarios:1,selectLockedCells:1,selectUnlockedCells:1" , 0 ) ]
501+ [ InlineData ( true , "selectLockedCells:1,selectUnlockedCells:0" , "objects:1,scenarios:1" , 0 ) ] // Special case: only locked cells selectable is not possible, therefore none
501502 [ InlineData ( true , "autoFilter:0" , "autoFilter:0,objects:1,scenarios:1,selectLockedCells:1,selectUnlockedCells:1" , 0 ) ]
502503 [ InlineData ( true , "pivotTables:0" , "pivotTables:0,objects:1,scenarios:1,selectLockedCells:1,selectUnlockedCells:1" , 0 ) ]
503504 [ InlineData ( true , "sort:0" , "sort:0,objects:1,scenarios:1,selectLockedCells:1,selectUnlockedCells:1" , 0 ) ]
@@ -556,6 +557,32 @@ public void SheetProtectionWriteReadTest(bool useSheetProtection, string givenPr
556557 }
557558 }
558559
560+ [ Fact ( DisplayName = "Test of the 'SheetProtectionValues' when setting selectLockedCells alone (causes auto-fix)" ) ]
561+ public void SheetProtectionWriteReadTest2 ( )
562+ {
563+ int sheetIndex = 0 ;
564+ Workbook workbook = PrepareWorkbook ( 4 , "test" ) ;
565+ for ( int i = 0 ; i <= sheetIndex ; i ++ )
566+ {
567+ if ( sheetIndex == i )
568+ {
569+ workbook . SetCurrentWorksheet ( i ) ;
570+ workbook . CurrentWorksheet . AddAllowedActionOnSheetProtection ( Worksheet . SheetProtectionValue . selectUnlockedCells ) ;
571+ workbook . CurrentWorksheet . AddAllowedActionOnSheetProtection ( Worksheet . SheetProtectionValue . selectLockedCells ) ;
572+ // Override default (technically invalid)
573+ workbook . CurrentWorksheet . RemoveAllowedActionOnSheetProtection ( Worksheet . SheetProtectionValue . selectUnlockedCells ) ;
574+ workbook . CurrentWorksheet . UseSheetProtection = true ;
575+ }
576+ }
577+ Worksheet givenWorksheet = WriteAndReadWorksheet ( workbook , sheetIndex ) ;
578+ Assert . Equal ( 2 , givenWorksheet . SheetProtectionValues . Count ) ;
579+ Assert . True ( givenWorksheet . UseSheetProtection ) ;
580+ Assert . Contains ( Worksheet . SheetProtectionValue . objects , givenWorksheet . SheetProtectionValues ) ;
581+ Assert . Contains ( Worksheet . SheetProtectionValue . scenarios , givenWorksheet . SheetProtectionValues ) ;
582+ Assert . DoesNotContain ( Worksheet . SheetProtectionValue . selectLockedCells , givenWorksheet . SheetProtectionValues ) ;
583+ Assert . DoesNotContain ( Worksheet . SheetProtectionValue . selectUnlockedCells , givenWorksheet . SheetProtectionValues ) ;
584+ }
585+
559586 [ Theory ( DisplayName = "Test of the 'SheetProtectionPasswordHash' property when writing and reading a worksheet" ) ]
560587 [ InlineData ( "x" , 0 ) ]
561588 [ InlineData ( "@test-1,23" , 0 ) ]
0 commit comments