public void AnyPropertyOfCardsChangedTest()
        {
            var container = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Relative,
                Left = 1, Top = 10, Width = 300, Height = 3000,
            };
            var button0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };
            var button1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Static,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };

            container.Items.Add(button0);
            container.Items.Add(button1);

            container.AnyPropertyOfAnyChildChanged += (sender, e) =>
            {
                Assert.AreSame(e.Child, button0);
                Assert.AreEqual("IsClickable", e.PropertyName);
                Assert.Pass();
            };

            button0.IsClickable = !button0.IsClickable;
            Assert.Fail();
        }
        public void AttachedDettachedTest()
        {
            var container = new DrawingObjectContainer()
            {
                Left = 1, Top = 10, Width = 300, Height = 3000,
            };
            var button0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };

            var flag0 = false;
            var flag1 = false;
            button0.Attached += (sender, e) =>
            {
                flag0 = true;
            };
            button0.Detached += (sender, e) =>
            {
                flag1 = true;
            };

            flag0 = false;
            container.Items.Add(button0);
            Assert.True(flag0);

            flag1 = false;
            container.Items.Remove(button0);
            Assert.True(flag1);

            flag1 = false;
            container.Items.Add(button0);
            container.Items.Clear();
            Assert.True(flag1);
        }
        public void CurrentItemがマウス座標と一致しない場合はクリックでAction0を発生させない()
        {
            var window = new EPuzzleWindow();
            var testState = new Fish.eigotest.TestState(window);
            Assert.Null(testState.CurrentItem);
            var b0 = new EigoTestButtonItem()
            {
                Left = 100, Top = 100, Width = 10, Height = 10,
            };
            testState.Items.Add(b0);
            window.State = testState;
            Assert.AreSame(b0, testState.CurrentItem);

            testState.Action0 += (sender, e) =>
            {
                Assert.Fail();
            };
            window.MouseUp(0f, 0f, MouseButtons.Left);
        }
        public void フローティング機能でマージン設定()
        {
            var window = new EPuzzleWindow();
            var windowState = new WindowState(window);
            window.State = windowState;
            var container = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1f, Top = 10f,
                Width = 1000f, Height = 1000f,
            };
            var button0 = new EigoTestButtonItem()
            {
                Floating = DrawingObjectFloating.Left,
                Width = 10f, Height = 100f,
            };
            var button1 = new EigoTestButtonItem()
            {
                MarginLeft = 1f, MarginTop = 10f,
                Width = 10f, Height = 100f,
            };
            window.State.Items.Add(container);
            container.Items.Add(button0);
            container.Items.Add(button1);

            Assert.AreEqual(1f, button0.OuterLeft);
            Assert.AreEqual(10f, button0.OuterTop);
            Assert.AreEqual(12f, button1.BorderLeft);
            Assert.AreEqual(20f, button1.BorderTop);
        }
        public void Test4()
        {
            var container = new DrawingObjectContainer()
            {
                Left = 1, Top = 10, Width = 300, Height = 3000,
            };
            Assert.AreEqual(DrawingObjectPosition.Static, container.Position);

            var button1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };
            var button2 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };
            container.Items.Add(button1);
            container.Items.Add(button2);

            // container.Position == Relative
            // button1.Position == Absolute
            // button2.Position == Absolute
            container.Position = DrawingObjectPosition.Relative;
            Assert.AreEqual(DrawingObjectPosition.Relative, container.Position);
            Assert.AreSame(container, button1.GetContainingBlock());
            Assert.AreEqual(2, button1.OuterLeft);
            Assert.AreEqual(20, button1.OuterTop);
            Assert.AreEqual(200, button1.OuterWidth);

            Assert.AreEqual(2, button2.OuterLeft);
            Assert.AreEqual(20, button2.OuterTop);
            Assert.AreEqual(200, button2.OuterWidth);

            // container.Position == Static
            // button1.Position == Absolute
            // button2.Position == Absolute
            container.Position = DrawingObjectPosition.Static;
            Assert.AreEqual(DrawingObjectPosition.Static, container.Position);
            Assert.Null(button1.GetContainingBlock());
            Assert.AreEqual(1, button1.OuterLeft);
            Assert.AreEqual(10, button1.OuterTop);
            Assert.AreEqual(200, button1.OuterWidth);

            Assert.AreEqual(1, button2.OuterLeft);
            Assert.AreEqual(10, button2.OuterTop);
            Assert.AreEqual(200, button2.OuterWidth);

            // container.Position == Static
            // button1.Position == Static
            // button2.Position == Static
            {
                container.Position = DrawingObjectPosition.Static;
                button1.Position = DrawingObjectPosition.Static;
                button2.Position = DrawingObjectPosition.Static;
                Assert.AreEqual(DrawingObjectPosition.Static, container.Position);
                Assert.Null(button1.GetContainingBlock());

                Assert.AreEqual(1, button1.OuterLeft);
                Assert.AreEqual(10, button1.OuterTop);
                Assert.AreEqual(200, button1.OuterWidth);

                Assert.AreEqual(1, button2.OuterLeft);
                Assert.AreEqual(110, button2.OuterTop);
                Assert.AreEqual(200, button2.OuterWidth);

                // Width
                button1.SetWidthNull();
                Assert.AreEqual(300, button1.Width);
                button1.MarginLeft = 10;
                Assert.AreEqual(290, button1.Width);

                // 上下マージン相殺
                button1.MarginBottom = 30f;
                button2.MarginTop = 20f;
                Assert.AreEqual(1, button2.OuterLeft);
                Assert.AreEqual(120, button2.OuterTop);

                // 上下マージン相殺
                button1.MarginBottom = 20f;
                button2.MarginTop = 30f;
                Assert.AreEqual(1, button2.OuterLeft);
                Assert.AreEqual(110, button2.OuterTop);
            }
        }
        public void PreviousItemTest()
        {
            var container = new DrawingObjectContainer()
            {
                Left = 1, Top = 10, Width = 300, Height = 3000,
            };
            Assert.AreEqual(DrawingObjectPosition.Static, container.Position);

            var button0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };
            var button1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };
            var button2 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };

            Assert.Null(button0.PreviousItem);
            Assert.Null(button1.PreviousItem);
            Assert.Null(button2.PreviousItem);

            container.Items.Add(button0);
            container.Items.Add(button1);
            container.Items.Add(button2);

            Assert.Null(button0.PreviousItem);
            Assert.AreSame(button0, button1.PreviousItem);
            Assert.AreSame(button1, button2.PreviousItem);

            Assert.Throws<ArgumentException>(() =>
            {
                container.Items[1] = button2;
            });

            container.Items.RemoveAt(1);
            Assert.Null(button0.PreviousItem);
            Assert.Null(button1.PreviousItem);
            Assert.AreSame(button0, button2.PreviousItem);

            container.Items.Insert(1, button1);
            Assert.Null(button0.PreviousItem);
            Assert.AreSame(button0, button1.PreviousItem);
            Assert.AreSame(button1, button2.PreviousItem);

            container.Items.RemoveAt(2);
            Assert.Null(button0.PreviousItem);
            Assert.AreSame(button0, button1.PreviousItem);
            Assert.Null(button2.PreviousItem);

            container.Items[0] = button2;
            Assert.Null(button0.PreviousItem);
            Assert.AreSame(button2, button1.PreviousItem);
            Assert.Null(button2.PreviousItem);
        }
        public void MustBeRemovedTest()
        {
            var window = new EPuzzleWindow();
            var windowState = new WindowState(window);

            window.State = windowState;
            window.State.Tick();

            var button = new EigoTestButtonItem();
            Assert.False(button.MustBeRemoved);
            window.State.Items.Add(button);
            window.State.Tick();
            Assert.AreSame(button, window.State.Items.Single());

            button.MustBeRemoved = true;
            window.State.Tick();
            CollectionAssert.IsEmpty(window.State.Items);
        }
        public void MouseMove以外ではCurrentItemを変更しない()
        {
            var window = new EPuzzleWindow();
            var state = new WindowState(window);

            var button0 = new EigoTestButtonItem()
            {
                Left = 100, Top = 100, Width = 100, Height = 100,
            };
            var button1 = new EigoTestButtonItem()
            {
                Left = 100, Top = 300, Width = 100, Height = 100,
            };
            state.Items.Add(button0);
            state.Items.Add(button1);

            window.State = state;
            window.State.CurrentItem = button0;
            Assert.AreSame(button0, window.State.CurrentItem);

            window.MouseMove(button1.BorderLeft, button1.BorderTop);
            Assert.AreSame(button1, window.State.CurrentItem);

            window.MouseUp(button0.BorderLeft, button0.BorderTop, MouseButtons.Left);
            Assert.AreSame(button0, window.State.CurrentItem);

            window.State.OnMoveDown();
            Assert.AreSame(button1, window.State.CurrentItem);
        }
        public void マウスカーソル強調テスト()
        {
            var window = new EPuzzleWindow();
            var windowState = new WindowState(window);
            window.State = windowState;

            window.MouseUp(10f, 100f, MouseButtons.Left);
            Assert.AreEqual(new PointF(10f, 100f), windowState.MouseCursorPosition);

            window.MouseMove(20f, 200f);
            Assert.AreEqual(new PointF(20f, 200f), windowState.MouseCursorPosition);

            var button = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Location = new PointF(15f, 150f),
                Size = new SizeF(10f, 100f),
            };
            Assert.False(button.マウスホバー強調);
            window.State.Items.Add(button);
            Assert.True(button.マウスホバー強調);

            button.IsClickable = false;
            Assert.False(button.マウスホバー強調);

            button.IsClickable = true;
            Assert.True(button.マウスホバー強調);

            button.IsVisible = false;
            Assert.False(button.マウスホバー強調);

            button.IsVisible = true;
            Assert.True(button.マウスホバー強調);
        }
        public void カーソル移動は同一軸優先()
        {
            var window = new EPuzzleWindow();
            var testState = new Fish.eigotest.TestState(window);
            Assert.Null(testState.CurrentItem);
            var b0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100, Top = 100, Width = 10, Height = 10,
            };
            testState.Items.Add(b0);
            window.State = testState;
            Assert.AreSame(b0, testState.CurrentItem);

            var b1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 200, Top = 100, Width = 10, Height = 10,
            };
            testState.Items.Add(b1);
            var b2 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100, Top = 200, Width = 10, Height = 10,
            };
            testState.Items.Add(b2);

            {
                var b = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 120, Top = 120, Width = 10, Height = 10,
                };
                testState.Items.Add(b);
            }
            {
                var b = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 180, Top = 120, Width = 10, Height = 10,
                };
                testState.Items.Add(b);
            }
            {
                var b = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 120, Top = 180, Width = 10, Height = 10,
                };
                testState.Items.Add(b);
            }

            Assert.AreSame(b0, testState.CurrentItem);

            testState.OnMoveRight();
            Assert.AreSame(b1, testState.CurrentItem);

            testState.OnMoveLeft();
            Assert.AreSame(b0, testState.CurrentItem);

            testState.OnMoveDown();
            Assert.AreSame(b2, testState.CurrentItem);

            testState.OnMoveUp();
            Assert.AreSame(b0, testState.CurrentItem);
        }
        public void カレントアイテム強調テスト()
        {
            var window = new EPuzzleWindow();
            var windowState = new WindowState(window);
            window.State = windowState;
            WindowState.常にカーソルを表示 = true;

            var button0 = new EigoTestButtonItem()
            {
                Size = new SizeF(10, 100),
            };
            var button1 = new EigoTestButtonItem()
            {
                Size = new SizeF(10, 100),
            };
            Assert.False(button0.カレントアイテム強調);
            Assert.False(button1.カレントアイテム強調);

            window.InputDevice = InputDevice.Keyboard;

            windowState.Items.Add(button0);
            windowState.Items.Add(button1);
            Assert.True(button0.カレントアイテム強調);
            Assert.False(button1.カレントアイテム強調);

            window.State.CurrentItem = button0;
            Assert.True(button0.カレントアイテム強調);
            Assert.False(button1.カレントアイテム強調);

            window.State.CurrentItem = button1;
            Assert.False(button0.カレントアイテム強調);
            Assert.True(button1.カレントアイテム強調);
        }
        public void Test0()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\Mondai3.xml", TestResources.Mondai03);
                test.AddFile(@"mondai\Mondai2.xml", TestResources.Mondai02);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondai2 = window.EPuzzleData.MondaiDocuments[0];
                var mondai3 = window.EPuzzleData.MondaiDocuments[1];

                var testState = new Fish.eigotest.TestState(window);
                var button0 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 10,
                    Top = 10,
                    Width = 40,
                    Height = 40,
                    Text = "↑",
                    Name = "button0",
                    IsVisible = true,
                    IsClickable = true,
                    HelpText = "ボタン0",
                };
                testState.Items.Add(button0);

                var button1 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 800,
                    Top = 10,
                    Width = 40,
                    Height = 40,
                    Text = "↑",
                    Name = "button1",
                    IsVisible = true,
                    IsClickable = true,
            //					HelpText = "ボタン1",
                };
                testState.Items.Add(button1);
                var helpTextBox = new HelpTextBox()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 100,
                    Top = 100,
                    Width = 400,
                    Height = 40,
                };

            /*				Assert.Throws<InvalidOperationException>(() =>
                {
                    helpTextBox.Text = "";
                });*/

                Assert.False(helpTextBox.IsVisible);
                Assert.False(helpTextBox.IsClickable);
                Assert.AreEqual("", helpTextBox.Text);

                testState.Items.Add(helpTextBox);
                Assert.True(helpTextBox.IsVisible);
                Assert.False(helpTextBox.IsClickable);
                Assert.AreEqual("ボタン0", helpTextBox.Text);

                Assert.AreEqual(2, testState.GetAllItems().OfType<EigoTestButtonItem>().Count());
                Assert.AreEqual(1, testState.GetAllItems().OfType<HelpTextBox>().Count());

                window.State = testState;
                Assert.AreSame(button0, window.State.CurrentItem);
                Assert.True(helpTextBox.IsVisible);
                Assert.False(helpTextBox.IsClickable);
                Assert.AreEqual("ボタン0", helpTextBox.Text);

                window.State.CurrentItem = button1;
                Assert.AreSame(button1, window.State.CurrentItem);
                Assert.False(helpTextBox.IsVisible);
                Assert.False(helpTextBox.IsClickable);
                Assert.AreEqual("", helpTextBox.Text);
            }
        }
        public void 包含ブロックの幅が足りないときは次の行へ()
        {
            var window = new EPuzzleWindow();
            var windowState = new WindowState(window);
            window.State = windowState;
            var container = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1f, Top = 10f,
                Width = 25f, Height = 1000f,
            };
            var button0 = new EigoTestButtonItem()
            {
                Floating = DrawingObjectFloating.Left,
                Width = 10f, Height = 100f,
            };
            var button1 = new EigoTestButtonItem()
            {
                Floating = DrawingObjectFloating.Left,
                Width = 10f, Height = 100f,
            };
            var button2 = new EigoTestButtonItem()
            {
                Floating = DrawingObjectFloating.Left,
                Width = 10f, Height = 100f,
            };
            var button3 = new EigoTestButtonItem()
            {
                Floating = DrawingObjectFloating.Left,
                Width = 10f, Height = 100f,
            };
            window.State.Items.Add(container);
            container.Items.Add(button0);
            container.Items.Add(button1);
            container.Items.Add(button2);
            container.Items.Add(button3);

            Assert.AreEqual(1f, button0.OuterLeft);
            Assert.AreEqual(10f, button0.OuterTop);

            Assert.AreEqual(11f, button1.OuterLeft);
            Assert.AreEqual(10f, button1.OuterTop);

            Assert.AreEqual(1f, button2.OuterLeft);
            Assert.AreEqual(110f, button2.OuterTop);

            Assert.AreEqual(11f, button3.OuterLeft);
            Assert.AreEqual(110f, button3.OuterTop);
        }
        public void 中央揃えテスト()
        {
            var container = new DrawingObjectContainer()
            {
                Width = 100f, Height = 1000f,
            };
            var button = new EigoTestButtonItem()
            {
                Width = 10f, Height = 100f,
            };
            container.Items.Add(button);
            Assert.AreSame(container, button.Parent);
            Assert.AreEqual(new PointF(0f, 0f), button.Location);

            button.水平方向に中央揃え();
            Assert.AreEqual(new PointF(45f, 0f), button.Location);

            button.垂直方向に中央揃え();
            Assert.AreEqual(new PointF(45f, 450f), button.Location);

            button.右揃え();
            Assert.AreEqual(new PointF(90f, 450f), button.Location);

            button.下揃え();
            Assert.AreEqual(new PointF(90f, 900f), button.Location);
        }
        public void InputDeviceプロパティによるマウスホバー強調とカレントアイテム強調のテスト()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var windowState = new WindowState(window);
                window.State = windowState;

            //				var window = new EPuzzleWindow();
            //				var windowState = new WindowState(window);
            //				window.State = windowState;

                var button0 = new EigoTestButtonItem()
                {
                    MarginTop = 100f, Size = new SizeF(10, 100),
                };
                var button1 = new EigoTestButtonItem()
                {
                    MarginTop = 100f, Size = new SizeF(10, 100),
                };
                Assert.False(button0.カレントアイテム強調);
                Assert.False(button1.カレントアイテム強調);
                Assert.False(button0.マウスホバー強調);
                Assert.False(button1.マウスホバー強調);

                windowState.Items.Add(button0);
                windowState.Items.Add(button1);
                window.InputDevice = InputDevice.Keyboard;
                Assert.AreEqual(InputDevice.Keyboard, window.InputDevice);
                Assert.AreSame(button0, window.State.CurrentItem);
                Assert.True(button0.カレントアイテム強調);
                Assert.False(button1.カレントアイテム強調);
                Assert.False(button0.マウスホバー強調);
                Assert.False(button1.マウスホバー強調);

                window.MouseMove(button0.BorderLeft, button0.BorderTop);
                Assert.AreEqual(InputDevice.Mouse, window.InputDevice);
                Assert.AreSame(button0, window.State.CurrentItem);
                Assert.False(button0.カレントアイテム強調);
                Assert.False(button1.カレントアイテム強調);
                Assert.True(button0.マウスホバー強調);
                Assert.False(button1.マウスホバー強調);

                window.KeyDown(Keys.Down);
                Assert.AreEqual(InputDevice.Keyboard, window.InputDevice);
                Assert.AreSame(button1, window.State.CurrentItem);
                Assert.False(button0.カレントアイテム強調);
                Assert.True(button1.カレントアイテム強調);
                Assert.False(button0.マウスホバー強調);
                Assert.False(button1.マウスホバー強調);

                window.MouseMove(button0.BorderLeft, button0.BorderTop);
                Assert.AreEqual(InputDevice.Mouse, window.InputDevice);
                Assert.AreSame(button0, window.State.CurrentItem);
                Assert.False(button0.カレントアイテム強調);
                Assert.False(button1.カレントアイテム強調);
                Assert.True(button0.マウスホバー強調);
                Assert.False(button1.マウスホバー強調);
            }
        }
        public void KeyDownでカーソル移動()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
            //				var windowState = new WindowState(window);
            //				window.State = windowState;

            //			var window = new EPuzzleWindow();
                var testState1 =  new Fish.eigotest.TestState(window);
                Assert.Null(testState1.CurrentItem);

                var button = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 100,
                    Top = 100,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button);
                window.State = testState1;
                Assert.AreSame(button, testState1.CurrentItem);

                var button2 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 110,
                    Top = 100,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button2);

                var button3 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 100,
                    Top = 200,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button3);

                window.KeyDown(new KeyEventInfo(new KeyEventArgs(Keys.Down)));
                // testState1.MoveDown();
                Assert.AreSame(button3, testState1.CurrentItem);

                var button4 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 110,
                    Top = 200,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button4);

                window.KeyDown(new KeyEventInfo(new KeyEventArgs(Keys.Up)));
                // testState1.MoveUp();
                Assert.AreSame(button, testState1.CurrentItem);

                var button5 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 100,
                    Top = 110,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button5);
                var button6 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 50,
                    Top = 100,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button6);

                window.KeyDown(new KeyEventInfo(new KeyEventArgs(Keys.Left)));
                //testState1.MoveLeft();
                Assert.AreSame(button6, testState1.CurrentItem);

                var button7 = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 50,
                    Top = 110,
                    Width = 10,
                    Height = 10,
                };
                testState1.Items.Add(button7);

                window.KeyDown(new KeyEventInfo(new KeyEventArgs(Keys.Right)));
                //testState1.MoveRight();
                Assert.AreSame(button, testState1.CurrentItem);
            }
        }
        public void 無効な入力でCurrentItemがnullになる不具合の修正()
        {
            var window = new EPuzzleWindow();
            var testState = new Fish.eigotest.TestState(window);
            Assert.Null(testState.CurrentItem);
            var b0 = new EigoTestButtonItem()
            {
                Left = 100, Top = 100, Width = 10, Height = 10,
            };
            testState.Items.Add(b0);
            window.State = testState;
            Assert.AreSame(b0, testState.CurrentItem);

            testState.OnMoveLeft();
            Assert.AreSame(b0, testState.CurrentItem);

            testState.OnMoveRight();
            Assert.AreSame(b0, testState.CurrentItem);

            testState.OnMoveUp();
            Assert.AreSame(b0, testState.CurrentItem);

            testState.OnMoveDown();
            Assert.AreSame(b0, testState.CurrentItem);
        }
        public void MoveDownTest()
        {
            var window = new EPuzzleWindow();
            var testState1 =  new Fish.eigotest.TestState(window);
            Assert.Null(testState1.CurrentItem);

            var button = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100,
                Top = 100,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button);
            window.State = testState1;
            Assert.AreSame(button, testState1.CurrentItem);

            var button2 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 110,
                Top = 100,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button2);

            var button3 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100,
                Top = 200,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button3);

            testState1.OnMoveDown();
            Assert.AreSame(button3, testState1.CurrentItem);

            var button4 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 110,
                Top = 200,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button4);

            testState1.OnMoveUp();
            Assert.AreSame(button, testState1.CurrentItem);

            var button5 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100,
                Top = 110,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button5);
            var button6 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 50,
                Top = 100,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button6);

            testState1.OnMoveLeft();
            Assert.AreSame(button6, testState1.CurrentItem);

            var button7 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 50,
                Top = 110,
                Width = 10,
                Height = 10,
            };
            testState1.Items.Add(button7);

            testState1.OnMoveRight();
            Assert.AreSame(button, testState1.CurrentItem);
        }
        public void 資格のなくなったCurrentItemを変更する()
        {
            var window = new EPuzzleWindow();
            var testState = new Fish.eigotest.TestState(window);
            Assert.Null(testState.CurrentItem);
            var b0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100, Top = 100, Width = 10, Height = 10,
            };
            Assert.Null(b0.GetState());
            testState.Items.Add(b0);
            window.State = testState;
            Assert.AreSame(b0, testState.CurrentItem);
            Assert.Null(testState.DrawingObjectRoot.Parent);
            Assert.AreSame(testState, testState.DrawingObjectRoot.GetState());
            Assert.AreSame(testState, b0.GetState());

            testState.Items.RemoveAt(0);
            Assert.AreEqual(0, testState.Items.Count());
            Assert.Null(testState.CurrentItem);

            var b1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 200, Top = 100, Width = 10, Height = 10,
            };
            testState.Items.Add(b0);
            testState.Items.Add(b1);
            Assert.AreSame(b0, testState.CurrentItem);

            b0.IsClickable = false;
            Assert.AreSame(b1, testState.CurrentItem);
            testState.Items.Remove(b1);

            Assert.Null(testState.CurrentItem);

            // 同じコレクション内のアイテムを優先する
            b0.IsClickable = true;
            var b2 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 300, Top = 100, Width = 10, Height = 10,
            };
            var container = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 200, Top = 100, Width = 500, Height = 500,
            };

            container.Items.Add(b1);
            container.Items.Add(b2);
            testState.Items.Add(container);

            Assert.AreSame(b0, testState.CurrentItem);
            testState.CurrentItem = b1;

            b1.IsClickable = false;
            Assert.AreSame(b2, testState.CurrentItem);

            // 同じコレクション内のアイテムで座標が近いものを優先する
            b1.IsClickable = true;
            b2.IsClickable = true;
            var b3 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 301, Top = 100, Width = 10, Height = 10,
            };
            container.Items.Add(b3);
            testState.CurrentItem = b2;
            b2.IsClickable = false;
            Assert.AreSame(b3, testState.CurrentItem);

            // 同じコレクション内になければすべての先頭から選択する
            b1.IsClickable = false;
            b2.IsClickable = false;
            b3.IsClickable = false;
            Assert.AreSame(b0, testState.CurrentItem);
        }
        public void SaveCurrentItemAndRestoreCurrentItemTest()
        {
            var window = new EPuzzleWindow();
            var windowState = new WindowState(window);

            var button = new EigoTestButtonItem();
            windowState.Items.Add(button);
            windowState.CurrentItem = button;

            var info = windowState.SaveCurrentItem();
            windowState.CurrentItem = null;

            windowState.RestoreCurrentItem(info);
            Assert.IsInstanceOf<EigoTestButtonItem>(windowState.CurrentItem);

            windowState.CurrentItem = null;
            info = windowState.SaveCurrentItem();

            windowState.CurrentItem = button;
            windowState.RestoreCurrentItem(info);
            Assert.Null(windowState.CurrentItem);

            var button2 = new EigoTestButtonItem();
            windowState.Items.Add(button2);
            windowState.CurrentItem = button2;

            info = windowState.SaveCurrentItem();
            windowState.CurrentItem = button;
            windowState.RestoreCurrentItem(info);

            Assert.AreSame(button2, windowState.CurrentItem);

            button.Name = "a";
            windowState.CurrentItem = button;
            info = windowState.SaveCurrentItem();

            windowState.Items.Clear();

            var button3 = new EigoTestButtonItem() { Name = "b", };
            var button4 = new EigoTestButtonItem() { Name = "c", };
            var button5 = new EigoTestButtonItem() { Name = "d", };
            var button6 = new EigoTestButtonItem() { Name = "e", };

            windowState.Items.Add(button3);
            windowState.Items.Add(button4);
            windowState.Items.Add(button5);
            windowState.Items.Add(button6);
            windowState.RestoreCurrentItem(info);

            Assert.Null(windowState.CurrentItem);

            button6.Name = "a";
            windowState.RestoreCurrentItem(info);
            Assert.AreSame(button6, windowState.CurrentItem);
            Assert.AreNotSame(button, windowState.CurrentItem);
        }
        public void 遷移すると次の遷移先でマウスホバー強調されない不具合の修正()
        {
            var window = new EPuzzleWindow();
            var windowState0 = new WindowState(window);
            var windowState1 = new WindowState(window);

            var button0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100, Top = 1000, Width = 100, Height = 100,
            };
            windowState0.Items.Add(button0);

            var button1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 100, Top = 1000, Width = 100, Height = 100,
            };
            windowState1.Items.Add(button1);

            window.State = windowState0;
            Assert.AreEqual(InputDevice.Mouse, window.InputDevice);
            Assert.AreSame(button0, window.State.CurrentItem);
            Assert.False(button0.マウスホバー強調);
            window.MouseMove(button0.BorderLeft, button0.BorderTop);
            Assert.True(button0.マウスホバー強調);

            // 遷移する
            window.State = windowState1;
            Assert.AreEqual(InputDevice.Mouse, window.InputDevice);
            Assert.AreSame(button1, window.State.CurrentItem);
            Assert.True(button1.マウスホバー強調);
        }
        public void PreviousItemがAbsoluteだった場合()
        {
            var container = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Relative,
                Left = 1, Top = 10, Width = 300, Height = 3000,
            };
            var button0 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };
            var button1 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Static,
                Left = 1, Top = 10, Width = 200, Height = 100,
            };

            container.Items.Add(button0);
            container.Items.Add(button1);

            CollectionAssert.AreEqual(new [] { button0, }, button1.GetPreviousItems());
            Assert.AreEqual(2, button0.OuterLeft);
            Assert.AreEqual(20, button0.OuterTop);
            Assert.AreEqual(1, button1.OuterLeft);
            Assert.AreEqual(10, button1.OuterTop);
        }
 public void ClearしたときにCurrentItemはNullにする()
 {
     var window = new EPuzzleWindow();
     var testState = new Fish.eigotest.TestState(window);
     Assert.Null(testState.CurrentItem);
     var b0 = new EigoTestButtonItem()
     {
         Position = DrawingObjectPosition.Absolute,
         Left = 100, Top = 100, Width = 10, Height = 10,
     };
     testState.Items.Add(b0);
     Assert.AreSame(b0, testState.CurrentItem);
     testState.Items.Clear();
     Assert.Null(testState.CurrentItem);
 }
        public void マージンのデフォルト設定()
        {
            var container0 = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Relative,
                Left = 0, Top = 0, Width = 300, Height = 3000,
            };
            var container1 = new DrawingObjectContainer()
            {
            };
            var button0 = new EigoTestButtonItem()
            {
                MarginTop = 1,
                Width = 200, Height = 100,
            };
            var button1 = new EigoTestButtonItem()
            {
                MarginTop = 10,
                Width = 200, Height = 100,
                MarginBottom = 1,
            };

            container0.Items.Add(container1);
            container1.Items.Add(button0);
            container1.Items.Add(button1);

            Assert.AreEqual(0, container1.MarginTop);
            Assert.AreEqual(0, container1.MarginBottom);
            Assert.AreEqual(210, container1.Height);

            // Absolute要素は除外
            var button2 = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                MarginTop = 10,
                Width = 200, Height = 100,
                MarginBottom = 1,
            };
            container1.Items.Add(button2);
            Assert.AreEqual(210, container1.Height);
        }
        public void CurrenteItemに不正なアイテムを代入した場合は例外()
        {
            var window = new EPuzzleWindow();
            var testState = new Fish.eigotest.TestState(window);
            Assert.Null(testState.CurrentItem);
            var b0 = new EigoTestButtonItem()
            {
                Left = 100, Top = 100, Width = 10, Height = 10,
            };
            Assert.Null(b0.GetState());
            testState.Items.Add(b0);
            window.State = testState;
            Assert.AreSame(b0, testState.CurrentItem);

            b0.IsClickable = false;

            Assert.Throws<ArgumentException>(() =>
            {
                testState.CurrentItem = b0;
            });

            b0.IsClickable = true;
            testState.Items.Remove(b0);
            Assert.Throws<ArgumentException>(() =>
            {
                testState.CurrentItem = b0;
            });
        }
        public void CurrentItemTest()
        {
            var window = new EPuzzleWindow();
            var testState1 = new Fish.eigotest.TestState(window);
            Assert.Null(testState1.CurrentItem);

            var button = new EigoTestButtonItem()
            {
                Left = 100,
                Top = 100,
                Width = 100,
                Height = 100,
            };
            testState1.Items.Add(button);
            window.State = testState1;
            Assert.AreSame(button, testState1.CurrentItem);

            var label = new EigoTestLabelItem();
            testState1.Items.Add(label);
            Assert.Throws<ArgumentException>(() =>
            {
                testState1.CurrentItem = label;
            });
            var button3 = new EigoTestButtonItem()
            {
                Left = 300,
                Top = 300,
                Width = 10,
                Height = 10,
            };
            window.State.Items.Add(button3);

            Assert.AreSame(button, testState1.CurrentItem);
            window.MouseMove(button3.BorderLeft, button3.BorderTop);
            window.Tick();
            Assert.AreSame(button3, testState1.CurrentItem);
        }
        public void 左クリックで座標が合っていない場合はAction0を発生させない()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.Initialize();
                var window = test.Window;
                var doc = window.EPuzzleData.MondaiDocuments.First();
                var userInfo = window.EPuzzleData.CurrentUserInfo;

                var shomon = (Shomon)doc.Items[0].Items[0].Items[0];
                var chumon = (Chumon)doc.Items[0].Items[0];
                var daimon = (Daimon)doc.Items[0];
            //				var shomonState = userInfo.Factory.CreateShomonState(window, shomon);
                var shomonState = window.CreateShomonState(shomon);
                Assert.AreSame(shomon, shomonState.Shomon);
                Assert.AreSame(chumon, shomonState.Shomon.Parent);
                Assert.AreSame(daimon, shomonState.Shomon.Parent.Parent);
                window.State = shomonState;

                var button = new EigoTestButtonItem()
                {
                    Position = DrawingObjectPosition.Absolute,
                    Left = 5000, Top = 5000,
                    Width = 100, Height = 100,
                };
                shomonState.Items.Add(button);

                var flag = false;
                window.State.Action0 += (sender, e) =>
                {
                    flag = true;
                };
                Assert.False(flag);

                flag = false;
                window.State.CurrentItem = button;
                Assert.AreSame(button, window.State.CurrentItem);
                window.MouseUp(button.BorderLeft, button.BorderTop, MouseButtons.Left);
                Assert.AreSame(button, window.State.CurrentItem);
                Assert.True(flag);

                flag = false;
                window.State.CurrentItem = button;
                Assert.AreSame(button, window.State.CurrentItem);
                window.MouseUp(0f, 0f, MouseButtons.Left);
                Assert.AreSame(button, window.State.CurrentItem);
                Assert.False(flag);
            }
        }