public void OnDockPaneRemovedTest()
        {
            var target = new DockBayLayoutEngine(new DockBayBase());
            var neighA = new DockPaneLayoutEngine(new DockPaneBase());
            var neighB = new DockPaneLayoutEngine(new DockPaneBase());
            var logger = new bool[2];
            var counter = 0;
            target.PaneRemovedInBay += (sender, e) =>
            {
                //[0]はneighAのeventが呼ばれたかを記録
                //[1]はneighBのeventが呼ばれたかを記録
                logger[0] |= neighA == e.DockPane;
                logger[1] |= neighB == e.DockPane;
                counter++;
                if (counter > 2)
                    Assert.Fail("DockPaneAddedの呼び出し回数が多すぎです");
            };
            target.Add(neighA, DockDirection.Top);
            neighA.Add(neighB, DockDirection.Left);
            neighA.Remove(neighB);
            target.Remove(neighA);

            Assert.AreEqual<int>(counter, 2, "DockPaneAddedの呼び出し回数が少なすぎです。");
        }
        public void OnDockPaneAddedTest()
        {
            var target = new DockBayLayoutEngine(new DockBayBase());
            var neighA = new DockPaneLayoutEngine(new DockPaneBase());
            var neighB = new DockPaneLayoutEngine(new DockPaneBase());
            var idx_logger = 0;
            var logger = new DockDirection[2];
            target.PaneAddedInBay += (sender, e) =>
            {
                logger[idx_logger++] = e.Align;
                if (idx_logger > 2)
                    Assert.Fail("DockPaneAddedの呼び出し回数が多すぎです");
            };
            target.Add(neighA, DockDirection.Top);
            neighA.Add(neighB, DockDirection.Left);

            Assert.AreEqual<int>(idx_logger, 2, "DockPaneAddedの呼び出し回数が少なすぎです。");
        }
        public void GetChildrenOfTest()
        {
            var target = new DockBayLayoutEngine(new DockBayBase());
            var lv1A = new DockPaneLayoutEngine(new DockPaneBase());
            var lv1B = new DockPaneLayoutEngine(new DockPaneBase());
            var lv1C = new DockPaneLayoutEngine(new DockPaneBase());
            var lv1D = new DockPaneLayoutEngine(new DockPaneBase());
            var lv2A = new DockPaneLayoutEngine(new DockPaneBase());

            target.Add(lv1A, DockDirection.Top);

            target.Add(lv1D, DockDirection.Top);
            lv1D.Add(lv2A, DockDirection.Right);
            target.Add(lv1C, DockDirection.Left);
            target.Add(lv1B, DockDirection.Top);

            //自ノードを含まない
            var testA = target.GetChildrenOf(DockDirection.Left, deep: false).ToArray();
            Assert.IsTrue(testA.Contains(lv1B));
            Assert.IsTrue(testA.Contains(lv1C));
            Assert.AreEqual(2, testA.Length);

            //自ノードを含む
            var testB = target.GetChildrenOf(DockDirection.Right, deep: false).ToArray();
            Assert.IsTrue(testB.Contains(lv1B));
            Assert.IsTrue(testB.Contains(lv1D));
            Assert.IsTrue(testB.Contains(lv1A));
            Assert.AreEqual(3, testB.Length);

            //自ノードを含み、かつ実質接触要素
            var testC = target.GetChildrenOf(DockDirection.Right, deep: true).ToArray();
            Assert.IsTrue(testC.Contains(lv1A));
            Assert.IsTrue(testC.Contains(lv1B));
            Assert.IsTrue(testC.Contains(lv2A));
            Assert.AreEqual(3, testC.Length);

            //自ノードを含み、スキップ2使用(lv1Cから探索)
            var testD = target.GetChildrenOf(DockDirection.Right, 2).ToArray();
            Assert.IsTrue(testD.Contains(lv1A));
            Assert.IsTrue(testD.Contains(lv2A));
            Assert.AreEqual(2, testD.Length);
        }
        public void AddTest()
        {
            var target = new DockPaneLayoutEngine(new DockPaneBase());

            //AddTest
            //DockPaneNeighs
            var tmp = new[]
                {
                    new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Left, Index = 0, Count = 1 },
                    new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Top, Index = 1, Count = 2 },
                    new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Right, Index = 2, Count = 3 },
                    new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Bottom, Index = 3, Count = 4 },
                    new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Right, Index = 3, Count = 5 },
                }
                .ToArray();
            //TestDatas
            var testDtIdx = 0;
            var testDt = new[]
                {
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = tmp[0].LayoutEngine },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = tmp[1].LayoutEngine, Left = tmp[0].LayoutEngine, Right = (DockPaneLayoutEngine)null },
                    new { Top = tmp[1].LayoutEngine, Bottom = (DockPaneLayoutEngine)null, Left = tmp[2].LayoutEngine, Right = (DockPaneLayoutEngine)null },
                    new { Top = tmp[3].LayoutEngine, Bottom = (DockPaneLayoutEngine)null, Left = tmp[0].LayoutEngine, Right = tmp[2].LayoutEngine },
                    new { Top = tmp[1].LayoutEngine, Bottom = (DockPaneLayoutEngine)null, Left = tmp[4].LayoutEngine, Right = tmp[2].LayoutEngine },
                };
            //MargeCollection
            var children = tmp
                .Select(n => new
                {
                    Align = n.Align,
                    LayoutEngine = n.LayoutEngine,
                    TestData = testDt[testDtIdx++],
                    Index = n.Index,
                    Count = n.Count,
                })
                .ToArray();
            foreach (var item in children)
            {
                target.Add(item.LayoutEngine, item.Align, item.Index);

                Assert.AreEqual(target, item.LayoutEngine.Parent);
                Assert.AreEqual(item.Align, item.LayoutEngine.Align);
                Assert.AreEqual(target, item.LayoutEngine.Parent);
                Assert.IsNull(item.LayoutEngine.Owner);
                Assert.AreEqual(item.Index, target.Children.IndexOf(item.LayoutEngine));
                Assert.AreEqual(item.Count, target.Children.Count);

                Assert.AreEqual(item.TestData.Top, item.LayoutEngine.Top);
                Assert.AreEqual(item.TestData.Bottom, item.LayoutEngine.Bottom);
                Assert.AreEqual(item.TestData.Left, item.LayoutEngine.Left);
                Assert.AreEqual(item.TestData.Right, item.LayoutEngine.Right);
                switch (item.Align)
                {
                    case DockDirection.Top:
                        Assert.AreEqual(0,
                            target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1)
                            .Select(n => n.Top)
                            .Where(n => n != item.LayoutEngine)
                            .Count());
                        break;
                    case DockDirection.Bottom:
                        Assert.AreEqual(0,
                            target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1)
                            .Select(n => n.Bottom)
                            .Where(n => n != item.LayoutEngine)
                            .Count());
                        break;
                    case DockDirection.Left:
                        Assert.AreEqual(0,
                            target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1)
                            .Select(n => n.Left)
                            .Where(n => n != item.LayoutEngine)
                            .Count());
                        break;
                    case DockDirection.Right:
                        Assert.AreEqual(0,
                            target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1)
                            .Select(n => n.Right)
                            .Where(n => n != item.LayoutEngine)
                            .Count());
                        break;
                }
            }

            //InsertTest
            var lyout = new DockPaneLayoutEngine(new DockPaneBase());
            target.Add(lyout, DockDirection.Left, 3);
            Assert.AreEqual(tmp[1].LayoutEngine, lyout.Top);
            Assert.AreEqual(tmp[0].LayoutEngine, lyout.Left);
            Assert.AreEqual(lyout, lyout.Right);
            Assert.AreEqual(null, lyout.Bottom);
            Assert.AreEqual(target.Left, lyout);
            Assert.AreEqual(tmp[3].LayoutEngine.Left, lyout);
            Assert.AreEqual(target, lyout.Parent);

            var bay = new DockBayLayoutEngine(new DockBayBase());
            bay.Add(target, DockDirection.Top);
            foreach (var item in children)
                Assert.AreEqual(bay, item.LayoutEngine.Owner);

            //不正引数用
            var exCnter = 0;
            try { target.Add((DockPaneLayoutEngine)null, DockDirection.Top, 0); }
            catch (ArgumentNullException) { exCnter++; }
            catch { }

            try { target.Add(children[0].LayoutEngine, DockDirection.Bottom, 0); }
            catch (ArgumentException) { exCnter++; }
            catch { }

            try { target.Add(new DockPaneLayoutEngine(new DockPaneBase()), DockDirection.None, 0); }
            catch (ArgumentException) { exCnter++; }
            catch { }

            try { target.Add(new DockPaneLayoutEngine(new DockPaneBase()), DockDirection.Left, -1); }
            catch (ArgumentException) { exCnter++; }
            catch { }
            Assert.AreEqual(4, exCnter, "無効な引数に対して適切な対処が取れていません。");
        }
        public void RemoveTest()
        {
            //テスト事項
            //Bay: 子要素の最初の時
            //Pane: 子要素がある場合の処理, 独身の場合

            var bay = new DockBayLayoutEngine(new DockBayBase());
            var lv1A = new DockPaneLayoutEngine(new DockPaneBase());
            var lv1B = new DockPaneLayoutEngine(new DockPaneBase());
            var lv2A = new DockPaneLayoutEngine(new DockPaneBase());
            var flg_removed = false;
            bay.PaneRemoved += (sender, e) => flg_removed = true;

            //lv0A
            //-lv1A(Top)
            //-lv1B(Left)
            // -lv2A(Bottom)
            bay.Add(lv1A, DockDirection.Top);
            bay.Add(lv1B, DockDirection.Left);
            lv1B.Add(lv2A, DockDirection.Bottom);

            var lv1ASeq = new[]
                {
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = lv2A, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Top, Parent = (DockNodeLayoutEngine)bay },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = lv2A, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Top, Parent = (DockNodeLayoutEngine)bay },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = lv2A, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Top, Parent = (DockNodeLayoutEngine)bay },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null },
                };
            var lv1BSeq = new[]
                {
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null },
                    new { Top = lv1B, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Bottom, Parent = (DockNodeLayoutEngine)lv2A },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null },
                };
            var lv2ASeq = new[]
                {
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = lv1B, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay },
                    new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay },
                };
            var testFunc = (Action<int>)(idx =>
                {
                    Assert.AreEqual(lv1ASeq[idx].Align, lv1A.Align);
                    Assert.AreEqual(lv1ASeq[idx].Parent, lv1A.Parent);
                    Assert.AreEqual(lv1ASeq[idx].Top, lv1A.Top);
                    Assert.AreEqual(lv1ASeq[idx].Bottom, lv1A.Bottom);
                    Assert.AreEqual(lv1ASeq[idx].Left, lv1A.Left);
                    Assert.AreEqual(lv1ASeq[idx].Right, lv1A.Right);

                    Assert.AreEqual(lv1BSeq[idx].Align, lv1B.Align);
                    Assert.AreEqual(lv1BSeq[idx].Parent, lv1B.Parent);
                    Assert.AreEqual(lv1BSeq[idx].Top, lv1B.Top);
                    Assert.AreEqual(lv1BSeq[idx].Bottom, lv1B.Bottom);
                    Assert.AreEqual(lv1BSeq[idx].Left, lv1B.Left);
                    Assert.AreEqual(lv1BSeq[idx].Right, lv1B.Right);

                    Assert.AreEqual(lv2ASeq[idx].Align, lv2A.Align);
                    Assert.AreEqual(lv2ASeq[idx].Parent, lv2A.Parent);
                    Assert.AreEqual(lv2ASeq[idx].Top, lv2A.Top);
                    Assert.AreEqual(lv2ASeq[idx].Bottom, lv2A.Bottom);
                    Assert.AreEqual(lv2ASeq[idx].Left, lv2A.Left);
                    Assert.AreEqual(lv2ASeq[idx].Right, lv2A.Right);
                });

            //lv0A
            //-lv1A(Top)
            //-lv2A(Bottom->Left)
            bay.Remove(lv1B);
            testFunc(0);

            //lv0A
            //-lv1A(Top)
            //-lv2A(Bottom->Left)
            // -lv1B(Left->Bottom)
            lv2A.Add(lv1B, DockDirection.Bottom);
            testFunc(1);

            //lv0A
            //-lv1A(Top)
            //-lv2A(Bottom->Left)
            lv2A.Remove(lv1B);
            testFunc(2);

            //lv0A
            //-lv2A(Bottom->Left)
            bay.Remove(lv1A);
            testFunc(3);

            Assert.IsTrue(flg_removed, "Removed eventが発生してません。");
        }
        public void GetSucceedingDireWhenDeletingPaneTest()
        {
            var nA = new DockPaneLayoutEngine(new DockPaneBase());
            var nB = new DockPaneLayoutEngine(new DockPaneBase());
            var nC = new DockPaneLayoutEngine(new DockPaneBase());
            var parent = new DockBayLayoutEngine(new DockBayBase());

            var nB_acc = DockPaneLayoutEngine_Accessor.AttachShadow(nB);
            var parent_acc = DockBayLayoutEngine_Accessor.AttachShadow(parent);

            //parent
            //-nA
            //-nB
            // -nC
            parent.Add(nA, DockDirection.Top);
            parent.Add(nB, DockDirection.Left);
            nB.Add(nC, DockDirection.Top);

            Assert.IsTrue(nA.GetSucceedingDireWhenDeletingPane() == DockDirection.Left,
                "DockBayNeigh下での挙動に異常があります。");
            Assert.IsTrue(nB.GetSucceedingDireWhenDeletingPane() == DockDirection.Top,
                "DockPaneNeigh下での挙動に異常があります。");
            Assert.IsTrue(nC.GetSucceedingDireWhenDeletingPane() == DockDirection.Bottom,
                "DockPaneNeigh下での挙動に異常があります。");
        }