12
12
using System . Collections ;
13
13
using System . Collections . Generic ;
14
14
using System . Drawing ;
15
+ using System . Windows . Forms ;
16
+ using System . Windows . Forms . VisualStyles ;
15
17
using NUnit . Framework ;
16
18
17
19
namespace BrightIdeasSoftware . Tests
@@ -51,7 +53,7 @@ public void InitEachTest() {
51
53
52
54
[ TearDown ]
53
55
public void TearDownEachTest ( ) {
54
- mainForm . Close ( ) ;
56
+ mainForm . Close ( ) ;
55
57
}
56
58
57
59
[ Test ]
@@ -485,7 +487,7 @@ public void Test_HierarchicalCheckBoxes_CheckedObjects_Set_RecalculatesParent()
485
487
Assert . IsEmpty ( this . olv . CheckedObjects ) ;
486
488
487
489
this . olv . HierarchicalCheckboxes = true ;
488
-
490
+
489
491
this . olv . CheckedObjects = ObjectListView . EnumerableToArray ( firstRoot . Children , true ) ;
490
492
491
493
ArrayList checkedObjects = new ArrayList ( this . olv . CheckedObjects ) ;
@@ -495,6 +497,48 @@ public void Test_HierarchicalCheckBoxes_CheckedObjects_Set_RecalculatesParent()
495
497
Assert . IsTrue ( checkedObjects . Contains ( child ) ) ;
496
498
}
497
499
500
+ [ Test ]
501
+ public void Test_HierarchicalCheckBoxes_CheckedObjects_Set_DeeplyNestedObject ( )
502
+ {
503
+ this . olv . HierarchicalCheckboxes = true ;
504
+ Assert . IsEmpty ( this . olv . CheckedObjects ) ;
505
+
506
+ // The tree structure is:
507
+ // GGP1
508
+ // +-- GP1
509
+ // +-- GP2
510
+ // +-- P1
511
+ // +-- last
512
+ // So checking "last" will also check P1 and GP2, and will make GGP1 indeterminate.
513
+
514
+ Person last = PersonDb . All [ PersonDb . All . Count - 1 ] ;
515
+ Person P1 = last . Parent ;
516
+ Person GP2 = last . Parent . Parent ;
517
+ Person GGP1 = last . Parent . Parent . Parent ;
518
+ Person GP1 = GGP1 . Children [ 0 ] ;
519
+
520
+ ArrayList toBeChecked = new ArrayList ( ) ;
521
+ toBeChecked . Add ( last ) ;
522
+ this . olv . CheckedObjects = toBeChecked ;
523
+
524
+ ArrayList checkedObjects = new ArrayList ( this . olv . CheckedObjects ) ;
525
+ Assert . AreEqual ( 3 , checkedObjects . Count ) ;
526
+ Assert . IsTrue ( checkedObjects . Contains ( last ) ) ;
527
+ Assert . IsTrue ( checkedObjects . Contains ( P1 ) ) ;
528
+ Assert . IsTrue ( checkedObjects . Contains ( GP2 ) ) ;
529
+ Assert . IsFalse ( checkedObjects . Contains ( GGP1 ) ) ;
530
+
531
+ Assert . IsTrue ( this . olv . IsChecked ( last ) ) ;
532
+ Assert . IsTrue ( this . olv . IsChecked ( P1 ) ) ;
533
+ Assert . IsTrue ( this . olv . IsChecked ( GP2 ) ) ;
534
+ Assert . IsTrue ( this . olv . IsCheckedIndeterminate ( GGP1 ) ) ;
535
+
536
+ // When GP1 is checked, GGP1 should also become checked.
537
+ this . olv . CheckObject ( GP1 ) ;
538
+ Assert . IsTrue ( this . olv . IsChecked ( GP1 ) ) ;
539
+ Assert . IsTrue ( this . olv . IsChecked ( GGP1 ) ) ;
540
+ }
541
+
498
542
[ Test ]
499
543
public void Test_HierarchicalCheckBoxes_CheckedObjects_Set_ClearsPreviousChecks ( ) {
500
544
Person firstRoot = PersonDb . All [ 0 ] ;
0 commit comments