public void DrawingPreparersTest()
        {
            var testState = new Fish.eigotest.TestState(null);
            var drawingPreparer1 = new DrawingPreparer();
            var drawingPreparer2 = new DrawingPreparer();
            testState.DrawingPreparers.Add(drawingPreparer1);
            testState.DrawingPreparers.Add(drawingPreparer2);

            // Tick()時、完了プロパティがtrueのDrawingPreparerは取り除かれる
            CollectionAssert.IsSubsetOf(new [] { drawingPreparer1, drawingPreparer2, }, testState.DrawingPreparers);

            testState.Tick();
            CollectionAssert.IsSubsetOf(new [] { drawingPreparer1, drawingPreparer2, }, testState.DrawingPreparers);

            drawingPreparer2.HasBeenFinished = true;
            testState.Tick();
            CollectionAssert.DoesNotContain(testState.DrawingPreparers, drawingPreparer2);

            bool a = false;
            drawingPreparer1.Action = x =>
            {
                a = true;
                return false;
            };
            testState.Tick();
            Assert.True(a);
        }
        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 DrawingObjectRootTest()
 {
     var window = new EPuzzleWindow();
     var testState = new Fish.eigotest.TestState(window);
     Assert.AreEqual(DrawingObjectPosition.Relative, testState.DrawingObjectRoot.Position);
 }
        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 Actionイベント()
        {
            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 testState =  new Fish.eigotest.TestState(window);
                Assert.Null(testState.CurrentItem);
                window.State = testState;

                var flag = false;

                EventHandler handler = (sender, e) =>
                {
                    flag = true;
                };

                // Action0
                testState.Action0 += handler;
                flag = false;
                window.KeyDown(Keys.Return);
                Assert.True(flag);

            /*				flag = false;
                window.KeyDown(Keys.NumPad5);
                Assert.True(flag);
                testState.Action0 -= handler;
                */

            /*				// Action1
                testState.Action1 += handler;
                flag = false;
                window.KeyDown(Keys.Space);
                Assert.True(flag);

                flag = false;
                window.KeyDown(Keys.Back);
                Assert.True(flag);
                testState.Action1 -= handler;
                */

                // Action2
                testState.Action2 += handler;
                flag = false;
                window.KeyDown(Keys.Tab);
                Assert.True(flag);
                testState.Action2 -= handler;

                // Action3
                testState.Action3 += handler;
                flag = false;
                window.KeyDown(Keys.Escape);
                Assert.True(flag);
                testState.Action3 -= handler;

                // Action4
                testState.Action4 += handler;
                flag = false;
                window.KeyDown(Keys.OemOpenBrackets);
                Assert.True(flag);
                testState.Action4 -= handler;

                // Action5
                testState.Action5 += handler;
                flag = false;
                window.KeyDown(Keys.F2);
                Assert.True(flag);
                testState.Action5 -= handler;

                // Action6
                testState.Action6 += handler;
                flag = false;
                window.KeyDown(Keys.F3);
                Assert.True(flag);
                testState.Action6 -= handler;

                // Action7
                testState.Action7 += handler;
                flag = false;
                window.KeyDown(Keys.F4);
                Assert.True(flag);
                testState.Action7 -= handler;

                // Action8
                testState.Action8 += handler;
                flag = false;
                window.KeyDown(Keys.F5);
                Assert.True(flag);
                testState.Action8 -= handler;

                // Action9
                testState.Action9 += handler;
                flag = false;
                window.KeyDown(Keys.F6);
                Assert.True(flag);
                testState.Action9 -= handler;

                // Action10
                testState.Action10 += handler;
                flag = false;
                window.KeyDown(Keys.F7);
                Assert.True(flag);
                testState.Action10 -= handler;

                // Action11
                testState.Action11 += handler;
                flag = false;
                window.KeyDown(Keys.F8);
                Assert.True(flag);
                testState.Action11 -= handler;

                // ActionLeft
                testState.ActionLeft += handler;
                flag = false;
                window.KeyDown(Keys.Left | Keys.Control);
                Assert.True(flag);
                testState.ActionLeft -= handler;

                // ActionRight
                testState.ActionRight += handler;
                flag = false;
                window.KeyDown(Keys.Right | Keys.Control);
                Assert.True(flag);
                testState.ActionRight -= handler;

                // ActionUp
                testState.ActionUp += handler;
                flag = false;
                window.KeyDown(Keys.Up | Keys.Control);
                Assert.True(flag);
                testState.ActionUp -= handler;

                // ActionDown
                testState.ActionDown += handler;
                flag = false;
                window.KeyDown(Keys.Down | Keys.Control);
                Assert.True(flag);
                testState.ActionDown -= handler;

                // 同じキーを割り当てられている異なるアクションのテスト
                {
                    bool flag1 = false, flag2 = false;
                    testState.Action0 += (sender, e) =>
                    {
                        flag1 = true;
                    };
                    testState.Action1 += (sender, e) =>
                    {
                        flag2 = true;
                    };
                    window.EPuzzleData.CurrentUserInfo.KeyBindings.Add(new KeyBinding(Command.Action0, Keys.A, false, true, false));
                    window.EPuzzleData.CurrentUserInfo.KeyBindings.Add(new KeyBinding(Command.Action1, Keys.A, false, true, false));
                    window.KeyDown(Keys.A | Keys.Control);
                    Assert.True(flag1);
                    Assert.True(flag2);
                }
            }
        }
        public void GetAllItemsTest()
        {
            var testState = new Fish.eigotest.TestState(null);
            var drawingObjectContainer1 = new DrawingObjectContainer();
            var drawingObjectContainer2 = new DrawingObjectContainer();
            var eigoTestLabelItem = new EigoTestLabelItem();

            drawingObjectContainer2.Items.Add(eigoTestLabelItem);
            drawingObjectContainer1.Items.Add(drawingObjectContainer2);
            testState.Items.Add(drawingObjectContainer1);

            Assert.AreEqual(3, testState.GetAllItems().Count());
        }
        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が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 資格のなくなった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 カーソル移動は同一軸優先()
        {
            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 最上位アイテムはDrawingObjectContainer()
        {
            var testState = new Fish.eigotest.TestState(null);
            var drawingObjectContainer1 = new DrawingObjectContainer();

            testState.Items.Add(drawingObjectContainer1);

            Assert.NotNull(drawingObjectContainer1.Parent);
            Assert.IsInstanceOf<DrawingObjectContainer>(drawingObjectContainer1.Parent);

            // デフォルトの幅と高さ
            Assert.AreEqual(1024, drawingObjectContainer1.Width);
            Assert.AreEqual(0f, drawingObjectContainer1.Height);
        }
        public void カーソルボタンテスト()
        {
            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 testState = new Fish.eigotest.TestState(window);
                Assert.Null(testState.CurrentItem);
                window.State = testState;

                bool flag = false;

                // MoveUp
                testState.MoveUp += (sender, e) =>
                {
                    flag = true;
                };
                flag = false;
                window.KeyDown(Keys.NumPad8);
                Assert.True(flag);

            /*			flag = false;
                window.KeyDown(Keys.W);
                Assert.True(flag);*/

                flag = false;
                window.KeyDown(Keys.Up);
                Assert.True(flag);

                // MoveDown
                testState.MoveDown += (sender, e) =>
                {
                    flag = true;
                };
                flag = false;
                window.KeyDown(Keys.NumPad2);
                Assert.True(flag);

            /*			flag = false;
                window.KeyDown(Keys.S);
                Assert.True(flag);*/

                flag = false;
                window.KeyDown(Keys.Down);
                Assert.True(flag);

                // MoveLeft
                testState.MoveLeft += (sender, e) =>
                {
                    flag = true;
                };
                flag = false;
                window.KeyDown(Keys.NumPad4);
                Assert.True(flag);

            /*			flag = false;
                window.KeyDown(Keys.A);
                Assert.True(flag);*/

                flag = false;
                window.KeyDown(Keys.Left);
                Assert.True(flag);

                // MoveRight
                testState.MoveRight += (sender, e) =>
                {
                    flag = true;
                };
                flag = false;
                window.KeyDown(Keys.NumPad6);
                Assert.True(flag);

            /*			flag = false;
                window.KeyDown(Keys.D);
                Assert.True(flag);*/

                flag = false;
                window.KeyDown(Keys.Right);
                Assert.True(flag);
            }
        }
        public void AnkimonStateへの遷移()
        {
            EPuzzleWindow window = null;
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

                var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
                var data = ePuzzleData;
                var userInfo = ePuzzleData.CurrentUserInfo;
                WindowState.NowObject = new TestNowObject();

                var t0 = new DateTime(2013, 8, 22, 0, 0, 0); // UTC
                WindowState.NowObject.Now = t0;
                window = new EPuzzleWindow(ePuzzleData);

                var a = new Fish.eigotest.TestState(window);
                a.MoveToStartGameState();

                Assert.IsInstanceOf<FadeoutState>(window.State);
                EPuzzleTime.Now += TimeSpan.FromSeconds(5d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                EPuzzleTime.Now += TimeSpan.FromSeconds(5d);
                window.Tick();

                userInfo.SetLastDaimonInfo(new LastDaimonInfo(data.CurrentMondaiDocument.Id, "daimon3", t0));
                userInfo.MondaiResults.AddNew("3-1", t0, TimeSpan.FromSeconds(1d));
                userInfo.MondaiResults.AddNew("3-2", t0, TimeSpan.FromSeconds(1d));

                // ゲームスタート画面
                Assert.IsInstanceOf<StartGameState>(window.State);
                {
                    var item = window.State.Items.First(x => x.Name == "StartGameButton");
                    item.OnClick(new MouseEventInfo(MouseButtons.Left));
                }
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<MondaiDocumentMenuState>(window.State);
                {
                    var button = window.State.GetAllItems().Where(x => x.Tag is MondaiDocument).First();
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                var daimonState = (DaimonState)window.State;
                Assert.IsInstanceOf<DaimonState>(daimonState);
                Assert.AreEqual("daimon3", daimonState.Daimon.Id);

                var chumonButton = daimonState.GetAllItems().OfType<ChumonButton>().Single(x => "3-3" == x.Chumon.Id);
                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();
                window.Tick();

                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                window.State.OnAction0();
                window.Tick();

                Assert.IsInstanceOf<AnkimonState>(window.State);
                var ankimonState = (AnkimonState)window.State;
                var ankimonRowContainer0 = ankimonState.GetAllItems().OfType<AnkimonRowContainer>().First();
                var ankimonRowContainer1 = ankimonState.GetAllItems().OfType<AnkimonRowContainer>().ElementAt(1);
                Assert.False(ankimonState.正解判定());

                // Action3でエスケープステートに
                window.State.OnAction3();
                Assert.IsInstanceOf<PauseState>(window.State);
                window.State.OnAction3();
                Assert.IsInstanceOf<AnkimonState>(window.State);

                var wordCards = ankimonRowContainer0.GetAllItems().Concat(ankimonRowContainer1.GetAllItems()).
                    Where(x => x is WordCard).ToArray();

                ankimonRowContainer0.WordCardContainer.Items.Clear();
                ankimonRowContainer1.WordCardContainer.Items.Clear();

                Assert.False(ankimonState.正解判定());
                ankimonRowContainer0.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "swim"));
                ankimonRowContainer0.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "swam"));
                ankimonRowContainer0.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "swum"));
                ankimonRowContainer1.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "run"));
                ankimonRowContainer1.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "ran"));
                ankimonRowContainer1.WordCardContainer.Items.Add(wordCards.Where(x => x.Text == "run").ElementAt(1));
                Assert.True(ankimonState.正解判定());

                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<ShomonState>(window.State);
                window.Tick();

                var shomonState = (ShomonState)window.State;
                var wordCard0 = shomonState.GetAllItems().First(x => "This is" == x.Text);
                Assert.NotNull(wordCard0);
                var wordCard1 = shomonState.GetAllItems().First(x => "a ball." == x.Text);
                Assert.NotNull(wordCard1);

                window.State.CurrentItem = wordCard0;
                window.State.OnAction0();
                window.Tick();
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                window.State.CurrentItem = wordCard1;
                window.State.OnAction0();
                window.Tick();
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                window.Tick();

                var kaitouBox = (CardBox)shomonState.GetAllItems().First(x => "kaitouBox" == x.Name);
                Assert.AreEqual("This is a ball.", MondaiWord.Join(kaitouBox.GetAllItems().OfType<WordCard>().Select(x => x.MondaiWord).ToArray()));

                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<AnkimonState>(window.State);
            }
        }
        public void MouseClickイベントの送出()
        {
            var window = new EPuzzleWindow();
            var testState = new Fish.eigotest.TestState(window);
            var container = new DrawingObjectContainer()
            {
                MarginLeft = 10f,
                MarginTop = 100f,
            };
            var label = new EigoTestLabelItem()
            {
                Size = new SizeF(10, 100),
            };
            testState.Items.Add(container);
            container.Items.Add(label);
            window.State = testState;

            label.Click += (sender, e) =>
            {
                Assert.Pass();
            };

            Assert.AreEqual(1014f, container.Width);

            Assert.AreEqual(DrawingObjectPosition.Static, container.Position);
            Assert.AreEqual(10f, label.OuterLeft);
            Assert.AreEqual(100f, label.OuterTop);
            Assert.AreEqual(10f, label.Width);
            Assert.AreEqual(100f, label.Height);
            window.MouseUp(15f, 150f, MouseButtons.Left);
            Assert.Fail();
        }
        public void FiTest()
        {
            var testState = new Fish.eigotest.TestState(null);
            var fadeinState = WindowState.Fi(testState, 1000);

            Assert.IsInstanceOf<FadeinState>(fadeinState);
            Assert.AreSame(testState, fadeinState.NextState);
        }
 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 FoFiTest()
        {
            var testState1 = new Fish.eigotest.TestState(null);
            var testState2 = new Fish.eigotest.TestState(null);
            var fadeoutState = WindowState.FoFi(testState1, testState2, 1000);

            Assert.AreSame(testState1, fadeoutState.PreviousState);
            Assert.IsInstanceOf<FadeoutState>(fadeoutState);
            Assert.IsInstanceOf<FadeinState>(fadeoutState.NextState);
            Assert.AreSame(testState2, fadeoutState.NextState.NextState);
        }
        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 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 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 PreviousStatesが空でない場合にPreviousStateプロパティに代入すると例外()
 {
     var testState = new Fish.eigotest.TestState(null);
     testState.PreviousStates.Add(testState);
     Assert.Throws<InvalidOperationException>(() => { testState.PreviousState = testState; });
 }
        public void ShootingStarsOnChumonResultState()
        {
            var window = new EPuzzleWindow();
            var windowState = new Fish.eigotest.TestState(window);
            var t0 = new DateTime(2013, 7, 25, 0, 0, 0); // UTC
            EPuzzleTime.Now = t0;
            window.State = windowState;

            var p0 = new PointF(1000f, 0f);
            var p1 = new PointF(0f, 700f);
            var x0 = p1.X - p0.X;
            var y0 = p1.Y - p0.Y;
            var a = 1000d;
            var v0 = x0 * Math.Sqrt(a / (2d * y0));

            var star = new ShootingStar(new PointF(0f, 700f))
            {
                Accel = 1000d,
                Left = 1000, Top = 0,
            };
            Assert.AreEqual(DrawingObjectPosition.Absolute, star.Position);
            Assert.True(star.IsVisible);
            Assert.False(star.IsClickable);
            window.State.Items.Add(star);
            window.State.DrawingPreparers.Add(star.GetDrawingPreparer());

            EPuzzleTime.Now += TimeSpan.FromSeconds(0.5d);
            window.State.Tick();

            Assert.AreEqual(p0.X + v0 * 0.5d, star.OuterLeft, 0.001);
            Assert.AreEqual(p0.Y + 0.5d * a * 0.5d * 0.5d, star.OuterTop, 0.001);

            EPuzzleTime.Now = t0 + TimeSpan.FromSeconds(Math.Sqrt( 2d * y0 / a ) - 0.001);
            window.State.Tick();

            Assert.AreEqual(p1.X, star.OuterLeft, 2d);
            Assert.AreEqual(p1.Y, star.OuterTop, 2d);

            EPuzzleTime.Now += TimeSpan.FromSeconds(0.5d);
            window.State.Tick();

            Assert.AreEqual(0, window.State.GetAllItems().OfType<ShootingStar>().Count());
        }