public void 同じ問題で同じ時間のとき例外が発生する不具合()
 {
     using (var tempDirectory = new TempDirectory(true))
     {
         tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
         var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
         WindowState.NowObject = new TestNowObject();
         WindowState.NowObject.Now = DateTime.MinValue;
         var window = new EPuzzleWindow(ePuzzleData);
         var userInfo = ePuzzleData.CurrentUserInfo;
         userInfo.MondaiResults.AddNew("d1_chumon1", DateTime.MinValue, TimeSpan.FromSeconds(1d));
         userInfo.MondaiResults.AddNew("d1_chumon1", DateTime.MinValue, TimeSpan.FromSeconds(1d));
     }
 }
        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 PreviousState2Test()
        {
            var window = new EPuzzleWindow();
            var windowState0 = new WindowState(window);
            var windowState1 = new WindowState(window);

            Assert.Null(windowState0.PreviousState2);
            Assert.Null(windowState1.PreviousState2);

            window.State = windowState0;
            Assert.Null(windowState0.PreviousState2);
            Assert.Null(windowState1.PreviousState2);

            window.State = windowState1;
            Assert.Null(windowState0.PreviousState2);
            Assert.AreSame(windowState0, windowState1.PreviousState2);

            window.State = windowState0;
            Assert.AreSame(windowState1, windowState0.PreviousState2);
            Assert.AreSame(windowState0, windowState1.PreviousState2);
        }
 public void DrawingObjectRootTest()
 {
     var window = new EPuzzleWindow();
     var testState = new Fish.eigotest.TestState(window);
     Assert.AreEqual(DrawingObjectPosition.Relative, testState.DrawingObjectRoot.Position);
 }
        public void LeaveTimeTest()
        {
            var window = new EPuzzleWindow();
            var windowState0 = new WindowState(window);
            var windowState1 = new WindowState(window);
            var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
            var t1 = t0 + TimeSpan.FromMinutes(10d);

            Assert.AreEqual(DateTime.MinValue, windowState0.LeaveTime);
            Assert.AreEqual(DateTime.MinValue, windowState1.LeaveTime);

            EPuzzleTime.Now = t0;
            window.State = windowState0;
            window.State = windowState1;
            Assert.AreEqual(t0, windowState0.LeaveTime);

            EPuzzleTime.Now = t1;
            window.State = windowState0;
            Assert.AreEqual(t1, windowState1.LeaveTime);
        }
 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 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 MouseCursorPositionを次の遷移先にコピーする()
        {
            var window = new EPuzzleWindow();
            var windowState0 = new WindowState(window);
            var windowState1 = new WindowState(window);

            window.State = windowState0;
            window.MouseMove(1, 2);
            Assert.AreEqual(new PointF(1, 2), windowState0.MouseCursorPosition);
            Assert.AreNotEqual(new PointF(1, 2), windowState1.MouseCursorPosition);

            window.State = windowState1;
            Assert.AreEqual(new PointF(1, 2), windowState1.MouseCursorPosition);
        }
        public void 状態遷移テスト正常ケース()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

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

                var t0 = new DateTime(2013, 8, 22, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                var window = new EPuzzleWindow(ePuzzleData);
                window.State = WindowState.Fi(new StartGameState(window), EPuzzleConstants.画面切替時間);

                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

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

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                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();

                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);

                // 最初のボタンがCurrentItemになっているべき
                Assert.AreSame(window.State.GetAllItems().OfType<ChumonButton>().First(), window.State.CurrentItem);

                // LastDaimonIdが保存される
                {
                    var daimonState = (DaimonState)window.State;
                    Assert.AreEqual(daimonState.Daimon.Id, userInfo.GetLastDaimonId(daimonState.Daimon.Parent.Id));
                }

                // 結果の保存の確認
                {
                    var daimonState = (DaimonState)window.State;
                    var data2 = EPuzzleData.Create(tempDirectory.DirectoryName);
                    Assert.AreEqual(((DaimonState)window.State).Daimon.Id, data2.CurrentUserInfo.GetLastDaimonId(daimonState.Daimon.Parent.Id));
                }

                {
                    {
                        var daimonState = (DaimonState)window.State;
                        var daimon = daimonState.Daimon;
                        var c1 = (ChumonButton)daimonState.GetAllItems().Where(x => x is ChumonButton).First();
                        var c2 = (ChumonButton)daimonState.GetAllItems().Where(x => x is ChumonButton).Skip(1).First();
                        var c3 = (ChumonButton)daimonState.GetAllItems().Where(x => x is ChumonButton).Skip(2).FirstOrDefault();
                        var nextButton = daimonState.GetAllItems().OfType<NextButton>().First();

                        Assert.AreNotSame(c1, c2);
                        Assert.Null(c3);
                        Assert.AreEqual("This is a pen.", c1.Text);
                        Assert.AreEqual("I'm a policeman.", c2.Text);

                        Assert.False(c1.Chumon.IsLocked(userInfo));
                        Assert.True(c2.Chumon.IsLocked(userInfo));
                        Assert.True(c1.IsVisible);
                        Assert.True(c1.IsClickable);
                        Assert.True(c2.IsVisible);
                        Assert.False(c2.IsClickable);
                        Assert.False(nextButton.IsVisible);
                        Assert.False(nextButton.IsClickable);

                        // マウス座標とCurrentItemのボタン座標が一致していなければ押したことにはならない
                        window.MouseUp(0f, 0f, MouseButtons.Left);
                        Assert.IsInstanceOf<DaimonState>(window.State);

                        // c1
                        window.MouseUp(c1.BorderLeft, c1.BorderTop, MouseButtons.Left);
                        window.Tick();
                    }

                    Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
            //					window.MouseUp(100f, 100f, MouseButtons.Left);
            //					window.KeyDown(Keys.NumPad5);
                    window.State.OnAction0();
                    window.Tick();
                    Assert.IsInstanceOf<ShomonState>(window.State);

                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "This is");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a notebook");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    window.Tick();

                    Assert.IsInstanceOf<FadeoutState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    Assert.IsInstanceOf<FadeinState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();

                    Assert.IsInstanceOf<ShomonState>(window.State);
                    Assert.AreEqual("[英訳] これはボールです。", ((ShomonState)window.State).Shomon.Mondaibun);

                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "This");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "is");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "ball");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    window.Tick();

                    Assert.IsInstanceOf<FadeoutState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    Assert.IsInstanceOf<FadeinState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();

                    Assert.IsInstanceOf<ChumonResultState>(window.State);
            /*					window.MouseUp(0f, 0f, MouseButtons.Left);
                    Assert.IsInstanceOf<ChumonResultState>(window.State);
                    */

                    WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                    window.Tick();
                    window.MouseUp(0f, 0f, MouseButtons.Left);

                    Assert.IsInstanceOf<FadeoutState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    Assert.IsInstanceOf<FadeinState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();

                    // CurrentItemは次の問題のボタンになる
                    Assert.IsInstanceOf<DaimonState>(window.State);
                    Assert.IsInstanceOf<ChumonButton>(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon2", ((ChumonButton)window.State.CurrentItem).Chumon.Id);

                    {
                        var daimonState = (DaimonState)window.State;
                        var daimon = daimonState.Daimon;
                        var c1 = (ChumonButton)daimonState.GetAllItems().Where(x => x is ChumonButton).First();
                        var c2 = (ChumonButton)daimonState.GetAllItems().Where(x => x is ChumonButton).Skip(1).First();
                        var c3 = (ChumonButton)daimonState.GetAllItems().Where(x => x is ChumonButton).Skip(2).FirstOrDefault();
                        var nextButton = daimonState.GetAllItems().First(x => x is NextButton);

                        Assert.False(c1.Chumon.IsLocked(userInfo));
                        Assert.False(c2.Chumon.IsLocked(userInfo));
                        Assert.True(c1.IsVisible);
                        Assert.True(c1.IsClickable);
                        Assert.True(c2.IsVisible);
                        Assert.True(c2.IsClickable);
                        Assert.False(nextButton.IsVisible);
                        Assert.False(nextButton.IsClickable);

                        // c2
                        window.MouseMove(c2.BorderLeft, c2.BorderTop);
                        window.Tick();
                        window.MouseUp(c2.BorderLeft, c2.BorderTop, MouseButtons.Left);
                        window.Tick();
                    }
                    Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    window.MouseUp(100f, 100f, MouseButtons.Left);

                    {
                        Assert.IsInstanceOf<ShomonState>(window.State);
                        Assert.AreEqual("[英訳] 私は警官です。", ((ShomonState)window.State).Shomon.Mondaibun);

                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "I'm");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "policeman");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                        window.Tick();

                        Assert.IsInstanceOf<FadeoutState>(window.State);
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                        Assert.IsInstanceOf<FadeinState>(window.State);
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                    }
                    {
                        Assert.IsInstanceOf<ShomonState>(window.State);
                        Assert.AreEqual("[英訳] あなたは看護婦ではありません。", ((ShomonState)window.State).Shomon.Mondaibun);

                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "You");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "are");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "not");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "nurse");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                        window.Tick();

                        Assert.IsInstanceOf<FadeoutState>(window.State);
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                        Assert.IsInstanceOf<FadeinState>(window.State);
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                    }
                    {
                        Assert.IsInstanceOf<ShomonState>(window.State);
                        Assert.AreEqual("[英訳] ジャックは学生です。", ((ShomonState)window.State).Shomon.Mondaibun);

                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "Jack");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "is");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "student");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        {
                            var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                            window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                        }
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                        window.Tick();

                        Assert.IsInstanceOf<FadeoutState>(window.State);
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                        Assert.IsInstanceOf<FadeinState>(window.State);
                        WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                        window.Tick();
                    }

                    Assert.IsInstanceOf<ChumonResultState>(window.State);
            //					window.MouseUp(0f, 0f, MouseButtons.Left);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                    window.MouseUp(0f, 0f, MouseButtons.Left);
                    window.Tick();
                }

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎II", ((DaimonState)window.State).Daimon.Name);

                {
                    var item = window.State.Items.First(x => x.GetType() == typeof(PreviousButton));
                    window.MouseUp(item.BorderLeft, item.BorderTop, MouseButtons.Left);
            //					item.OnClick(new MouseEventInfo(MouseButtons.Left));
                }

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                {
                    Assert.IsInstanceOf<DaimonState>(window.State);
                    var daimonState = (DaimonState)window.State;
                    var daimon = daimonState.Daimon;

                    /*
                    foreach (var item in daimon.Items)
                    {
                        item.GradeProcessor = GradeProcessorA.Instance;
                    }
                    */
                    userInfo.GradeProcessor = GradeProcessorA.Instance;

                    Assert.AreEqual("基礎I", daimon.Name);

                    {
                        var mondaiResults = userInfo.MondaiResults.GetItems("d1_chumon1").ToArray();
                        Assert.AreEqual(1, mondaiResults.Count());
                        Assert.AreEqual(TimeSpan.FromSeconds(2d), mondaiResults[0].所要時間);
                        Assert.AreEqual("S", daimon.Items[0].GetGradeString(userInfo));
                    }
                    {
                        var mondaiResults = userInfo.MondaiResults.GetItems("d1_chumon2").ToArray();
                        Assert.AreEqual(1, mondaiResults.Count());
                        Assert.AreEqual(TimeSpan.FromSeconds(3d), mondaiResults[0].所要時間);
                        Assert.AreEqual("S", daimon.Items[1].GetGradeString(userInfo));
                    }
                    Assert.False(daimon.Items[0].IsLocked(userInfo));
                    Assert.False(daimon.Items[1].IsLocked(userInfo));

                    Assert.IsInstanceOf<ChumonButton>(daimonState.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)daimonState.CurrentItem).Chumon.Id);

            //					var kirokuBox = (KirokuBox)daimonState.GetAllItems().First(x => x is KirokuBox);
            //					Assert.AreEqual(1, kirokuBox.GetPoints().Count());
                }
                {
                    var item = window.State.Items.First(x => x.Name == "タイトル画面に戻る");
                    item.OnClick(new MouseEventInfo(MouseButtons.Left));
                }

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<StartGameState>(window.State);
            }
        }
        public void Chumon遷移テスト()
        {
            EPuzzleWindow window = null;
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

                var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
                WindowState.NowObject = new TestNowObject();
                var t0 = new DateTime(2013, 8, 22, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;
                window = new EPuzzleWindow(ePuzzleData);
                window.State = WindowState.Fi(new StartGameState(window), EPuzzleConstants.画面切替時間);

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

                // ゲームスタート画面
                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();

                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);

                {
                    var item = window.State.GetAllItems().First(x => x.Text == "This is a pen.");
                    Assert.IsInstanceOf<EigoTestButtonItem>(item);
                    window.MouseMove(item.BorderLeft, item.BorderTop);
                    window.Tick();
                    window.MouseUp(item.BorderLeft, item.BorderTop, MouseButtons.Left);
                }

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

                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                window.MouseUp(100f, 100f, MouseButtons.Left);
                Assert.IsInstanceOf<ShomonState>(window.State);
                Assert.AreEqual("[英訳] これはノートです。", ((ShomonState)window.State).Shomon.Mondaibun);

                var mondaiId = ((ShomonState)window.State).Shomon.Parent.Id;
                Assert.AreEqual("d1_chumon1", mondaiId);

                var startTime = WindowState.NowObject.Now;
                Assert.AreEqual(startTime, window.ChumonResult.StartTime);

                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "This is");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a notebook");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                window.Tick();

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<ShomonState>(window.State);
                Assert.AreEqual("[英訳] これはボールです。", ((ShomonState)window.State).Shomon.Mondaibun);

                // エスケープ画面では時間が経過しない
                window.State.OnAction3();
                Assert.IsInstanceOf<PauseState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromHours(10d);
                window.State.OnAction3();
                Assert.IsInstanceOf<ShomonState>(window.State);
                Assert.AreEqual("[英訳] これはボールです。", ((ShomonState)window.State).Shomon.Mondaibun);

                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "This");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "is");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "ball");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                {
                    var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                    window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                }
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                window.Tick();

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<ChumonResultState>(window.State);
            /*				window.MouseUp(0f, 0f, MouseButtons.Left);
                Assert.IsInstanceOf<ChumonResultState>(window.State);
            */
                // 結果を記録
                Assert.AreEqual(1, window.EPuzzleData.CurrentUserInfo.MondaiResults.Count());
                var mondaiResult = window.EPuzzleData.CurrentUserInfo.MondaiResults.First();
                Assert.AreEqual(mondaiId, mondaiResult.MondaiId);

                var s0 = TimeSpan.FromSeconds(20d);
                Assert.AreEqual(s0, mondaiResult.所要時間);

                // 結果の保存の確認
                {
                    var data2 = EPuzzleData.Create(tempDirectory.DirectoryName);
                    var mr = data2.CurrentUserInfo.MondaiResults.First();
                    Assert.AreEqual("d1_chumon1", mr.MondaiId);
                    Assert.AreEqual(s0, mr.所要時間);
                }

                // 画面エフェクトが終了してからマウス入力を受け付ける
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.MouseUp(0f, 0f, MouseButtons.Left);

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                // 問題メニューに戻る
                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);
            }
        }
        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 D評価なら次のDaimonに遷移しない()
        {
            EPuzzleWindow window = null;
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

                var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
                var userInfo = ePuzzleData.CurrentUserInfo;
                WindowState.NowObject = new TestNowObject();
                var t0 = new DateTime(2013, 8, 22, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;
                window = new EPuzzleWindow(ePuzzleData);
                window.State = WindowState.Fi(new StartGameState(window), EPuzzleConstants.画面切替時間);

                userInfo.MondaiResults.AddNew("d1_chumon1", t0, TimeSpan.FromSeconds(10d));

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

                // ゲームスタート画面
                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();

                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);

                {
                    var item = window.State.GetAllItems().First(x => x.Text == "I'm a policeman.");
                    Assert.IsInstanceOf<EigoTestButtonItem>(item);
                    window.MouseMove(item.BorderLeft, item.BorderTop);
                    window.Tick();
                    window.MouseUp(item.BorderLeft, item.BorderTop, MouseButtons.Left);
                }

                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                window.Tick();
                window.MouseUp(100f, 100f, MouseButtons.Left);

                {
                    Assert.IsInstanceOf<ShomonState>(window.State);
                    Assert.AreEqual("[英訳] 私は警官です。", ((ShomonState)window.State).Shomon.Mondaibun);

                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "I'm");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "policeman");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    window.Tick();

                    Assert.IsInstanceOf<FadeoutState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    Assert.IsInstanceOf<FadeinState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                }
                {
                    Assert.IsInstanceOf<ShomonState>(window.State);
                    Assert.AreEqual("[英訳] あなたは看護婦ではありません。", ((ShomonState)window.State).Shomon.Mondaibun);

                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "You");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "are");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "not");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "nurse");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    window.Tick();

                    Assert.IsInstanceOf<FadeoutState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    Assert.IsInstanceOf<FadeinState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                }
                {
                    Assert.IsInstanceOf<ShomonState>(window.State);
                    Assert.AreEqual("[英訳] ジャックは学生です。", ((ShomonState)window.State).Shomon.Mondaibun);

                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "Jack");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "is");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "student");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    {
                        var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
                        window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
                    }
                    // 10時間
                    WindowState.NowObject.Now += TimeSpan.FromHours(10d);
                    window.Tick();
                    window.Tick();

                    Assert.IsInstanceOf<FadeoutState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                    Assert.IsInstanceOf<FadeinState>(window.State);
                    WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
                    window.Tick();
                }

                Assert.IsInstanceOf<ChumonResultState>(window.State);
                window.MouseUp(0f, 0f, MouseButtons.Left);
            /*				WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.MouseUp(0f, 0f, MouseButtons.Left);
                window.Tick();*/

                Assert.IsInstanceOf<FadeoutState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();
                Assert.IsInstanceOf<FadeinState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.Tick();

                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon1", ((DaimonState)window.State).Daimon.Id);
            }
        }
 public TestState00(EPuzzleWindow window)
     : base(window)
 {
     Flag = false;
 }
        public void EPuzzleData2_問題ファイル以外何も用意しない場合のテスト()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                {
                    tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                    tempDirectory.AddFile(@"mondai\MondaiDocument2.xml", TestResources.Mondai03);
                    tempDirectory.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);

                    // 読み込んではいけないファイル
                    tempDirectory.AddFile(@"mondai\help.xml", TestResources.HelpDocumentXml);

                    var data = EPuzzleData.Create(tempDirectory.Value);

                    // ファイルがない場合は作成する
                    Assert.True(File.Exists(data.SettingsFileName));

                    Assert.AreEqual(tempDirectory.Value, data.DataDir.DirectoryName);
                    CollectionAssert.AreEqual(new [] { "mondaiDocument1", "mondaiDocument2", }, data.MondaiDocuments.Select(x => x.Id));

                    Assert.AreEqual("User's Name", data.CurrentUserInfo.UserName);
                    Assert.AreEqual("mondaiDocument1", data.CurrentMondaiDocument.Id);
                    Assert.AreEqual("daimon1", data.GetDaimon(data.CurrentMondaiDocument.Id).Id);

                    Assert.False((bool)data.Settings.GetValue("常にカーソルを表示"));
                    data.Settings.SetValue("常にカーソルを表示", true);
            //					data.MondaiDocumentFileNames = new [] { "md.xml", "md2.xml", };

                    Assert.False(data.カード選択時に音声ファイルを再生する);
                    data.カード選択時に音声ファイルを再生する = true;

                    Assert.AreEqual(data.DataDir.FullPath("help"), data.HelpDirectory);
                    CollectionAssert.AreEqual(new [] { data.DataDir.FullPath(@"help\HelpDocument.xml"), }, data.HelpDocumentFileNames);

                    Assert.AreEqual("ResultImages", data.結果画像のディレクトリ名);
            //					Assert.AreEqual("ResultImages", ResultImageManager.Instance.DirectoryName);

                    Assert.False(data.最後の問題を解いたあと次の画面に遷移しない);

                    Assert.AreEqual("PronunciationInfoContainer.xml", data.発音情報ファイルのパス);
                    data.発音情報ファイルのパス = tempDirectory.GetFullPath("PronunciationInfoContainer.xml");
                    Assert.NotNull(data.PronunciationInfoContainer);

                    var daimon1 = (Daimon)data.MondaiDocuments[1].GetItem("daimon1");
                    Assert.AreEqual("mondaiDocument2", daimon1.Parent.Id);
                    Assert.AreEqual("daimon1", daimon1.Id);
                    Assert.AreEqual(2, daimon1.Items.Count());

                    Assert.False(data.発音問題を有効にする);
                    data.発音問題を有効にする = true;

                    // 発音情報ファイルを設定する
                    tempDirectory.AddFile(@"p.xml", TestResources.PronunciationInfoContainerXml);
                    data.発音情報ファイルのパス = tempDirectory.FullPath(@"p.xml");

                    CollectionAssert.AreEqual(new []
                    {
                        "mondaiDocument1",
                        "mondaiDocument2",
                    }, data.家庭教師モードの対象になる問題ファイルのIDの配列);

                    data.家庭教師モードの対象になる問題ファイルのIDの配列 = new [] { "mondai2", "mondai3", };

                    Assert.AreEqual(TimeSpan.FromHours(12d), data.家庭教師モードにてこの時間以内の問題は無視する);
                    data.家庭教師モードにてこの時間以内の問題は無視する = TimeSpan.FromHours(6d);

                    Assert.AreEqual("ResultImages", data.CurrentUserInfo.ResultImageManager.DirectoryName);
                    Assert.AreEqual(tempDirectory.GetFullPath("ResultImageInfos.dat"), data.ResultImageInfoContainerFileName);

                    // ユーザー情報の保存
                    Assert.NotNull(data.CurrentUserInfo);
                    data.CurrentUserInfo.MondaiResults.AddNew("id_1", DateTime.MinValue, TimeSpan.FromSeconds(10d));

                    // 保存する
                    data.Save();
                }
                {
                    tempDirectory.DeleteFile(@"mondai\MondaiDocument.xml");
                    tempDirectory.DeleteFile(@"mondai\MondaiDocument2.xml");
                    tempDirectory.AddFile(@"mondai\md.xml", TestResources.Mondai02);
                    tempDirectory.AddFile(@"mondai\md2.xml", TestResources.Mondai03);

                    var data2 = EPuzzleData.Create(tempDirectory.DirectoryName);
                    var mondaiResult = data2.CurrentUserInfo.MondaiResults.First();
                    Assert.AreEqual("id_1", mondaiResult.MondaiId);
                    Assert.AreEqual(TimeSpan.FromSeconds(10d), mondaiResult.所要時間);

            //					Assert.AreEqual(new [] { "md.xml", "md2.xml" }, data2.MondaiDocumentFileNames);
                    Assert.True((bool)data2.Settings.GetValue("常にカーソルを表示"));
                    Assert.True(data2.カード選択時に音声ファイルを再生する);

                    Assert.False(WindowState.常にカーソルを表示);
                    var window = new EPuzzleWindow(data2);
                    Assert.True(WindowState.常にカーソルを表示);

                    EPuzzleTime.NowObject = new TestNowObject();

                    EPuzzleTime.Now = DateTime.MinValue;
                    var daimon0 = (Daimon)data2.MondaiDocuments[0].GetItem("daimon3");
                    data2.CurrentUserInfo.SetLastDaimonInfo(daimon0);

                    EPuzzleTime.Now = DateTime.MinValue + TimeSpan.FromSeconds(1d);
                    var daimon1 = (Daimon)data2.MondaiDocuments[1].GetItem("daimon2");
                    data2.CurrentUserInfo.SetLastDaimonInfo(daimon1);
                    CollectionAssert.AreEqual(new [] { "mondaiDocument1", "mondaiDocument2", }, data2.CurrentUserInfo.GetLastDaimonInfos().OrderBy(x => x.CreationTime).Select(x => x.DocumentId));

                    Assert.True(data2.発音問題を有効にする);

                    var daimon2 = data2.GetLastDaimon();
                    Assert.AreEqual("mondaiDocument2", daimon2.Parent.Id);
                    Assert.AreEqual("daimon2", daimon2.Id);

                    var daimon111 = (Daimon)data2.MondaiDocuments[1].GetItem("daimon1");
                    Assert.AreEqual("mondaiDocument2", daimon111.Parent.Id);
                    Assert.AreEqual(3, daimon111.Items.OfType<Chumon>().Count());

                    CollectionAssert.AreEqual(new []
                    {
                        "mondai2",
                        "mondai3",
                    }, data2.家庭教師モードの対象になる問題ファイルのIDの配列);

                    Assert.AreEqual(TimeSpan.FromHours(6d), data2.家庭教師モードにてこの時間以内の問題は無視する);
                }
            }
        }
        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 Test1()
        {
            MondaiDocument doc = null;
            using (var tempFile = new TempFile(TestResources.Mondai03))
            {
                doc = MondaiDocument.Load(tempFile.FileName);
            }
            var window = new EPuzzleWindow();
            var ankimon = (Ankimon)doc.GetAllItems().First(x => "3-3-1" == x.Id);
            CollectionAssert.AreEqual(new []
            {
                new MondaiWord("swim"),
                new MondaiWord("swam"),
                new MondaiWord("swum"),
                new MondaiWord("run"),
                new MondaiWord("ran"),
                new MondaiWord("run")

            }, ankimon.GetMondaiWords());

            var ankimonState = new AnkimonState(window, ankimon);
            Assert.AreSame(ankimon, ankimonState.Ankimon);

            var ankimonBox = ankimonState.GetAllItems().OfType<AnkimonBox>().Single();
            Assert.AreEqual(2, ankimonBox.Items.Count());
            CollectionAssert.AllItemsAreInstancesOfType(ankimonBox.Items, typeof(AnkimonRowContainer));
            var ankimonRowContainer0 = (AnkimonRowContainer)ankimonBox.Items[0];
            var ankimonRowContainer1 = (AnkimonRowContainer)ankimonBox.Items[1];

            Assert.AreEqual(3, ankimonRowContainer0.WordCardContainer.Items.Count());
            Assert.AreEqual(3, ankimonRowContainer1.WordCardContainer.Items.Count());

            CollectionAssert.AreEquivalent
            (
                new [] { "swim", "swam", "swum", "run", "ran", "run" },
                ankimonBox.GetAllItems().Where(x => x is WordCard).Select(x => x.Text).ToArray()
            );

            Assert.AreEqual(100, ankimonBox.BorderLeft);
            Assert.AreEqual(100, ankimonBox.BorderTop);

            // AnkimonRowContainer
            Assert.AreEqual(DrawingObjectPosition.Relative, ankimonRowContainer0.Position);
            Assert.AreEqual(110, ankimonRowContainer0.BorderLeft);
            Assert.AreEqual(100, ankimonRowContainer0.BorderTop);

            // LabelItem
            var label0 = ankimonRowContainer0.Label;
            Assert.AreEqual("泳ぐ", label0.Text);
            Assert.AreEqual(100, label0.Width);
            Assert.AreEqual(110, label0.BorderLeft);
            Assert.AreEqual(100, label0.OuterWidth);
            Assert.AreEqual(210, label0.BorderRight);

            // wordCard00
            var wordCard00 = ankimonRowContainer0.WordCardContainer.Items[0];
            var wordCard10 = ankimonRowContainer1.WordCardContainer.Items[0];
            Assert.IsInstanceOf<WordCard>(wordCard00);
            Assert.AreEqual(DrawingObjectPosition.Absolute, wordCard00.Position);
            Assert.AreEqual(100, wordCard00.OuterTop);
            Assert.AreEqual(110, ankimonRowContainer1.BorderLeft);
            //			Assert.AreEqual(110 + WordCard.WordCardHeight + 10, wordCard10.BorderTop);
            //			Assert.AreEqual(110 + WordCard.WordCardHeight + 10, ankimonRowContainer1.BorderTop);
        }
        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 Test2()
        {
            MondaiDocument doc = null;
            using (var tempFile = new TempFile(TestResources.Mondai03))
            {
                doc = MondaiDocument.Load(tempFile.FileName);
            }
            var window = new EPuzzleWindow();
            var ankimon = (Ankimon)doc.GetAllItems().First(x => "3-3-1" == x.Id);
            CollectionAssert.AreEqual(new [] { "swim", "swam", "swum", "run", "ran", "run" }, ankimon.GetMondaiWords().Select(x => x.Text));

            var ankimonState = new AnkimonState(window, ankimon);
            Assert.AreSame(ankimon, ankimonState.Ankimon);

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

            window.State = ankimonState;

            var xxx = window.State.GetAllItems().OfType<WordCard>().ToArray();
            var a = xxx[0];
            var b = xxx[3];
            var parentOfA = a.Parent;
            var parentOfB = b.Parent;
            Assert.AreSame(a.Parent, xxx[1].Parent);
            Assert.AreNotSame(parentOfA, parentOfB);
            Assert.AreSame(window.State.CurrentItem, a);
            /*
            WindowState.NowObject.Now += TimeSpan.FromSeconds(0.1d);
            window.Tick();
            */

            // WordCardにAction0で選択
            window.State.OnAction0();
            Assert.True(a.IsSelected);
            Assert.AreSame(a, window.State.GetAllItems().Single(x => x.IsSelected));

            // WordCardにAction0で選択、2回目
            window.State.OnAction0();
            Assert.True(a.IsSelected);
            Assert.AreSame(a, window.State.GetAllItems().Single(x => x.IsSelected));

            // Action1で選択解除
            window.State.OnAction1();
            Assert.False(window.State.GetAllItems().Any(x => x.IsSelected));

            // WordCardにAction0で選択
            window.State.OnAction0();
            Assert.True(a.IsSelected);
            Assert.AreSame(a, window.State.GetAllItems().Single(x => x.IsSelected));

            // カード交換開始
            window.State.CurrentItem = b;
            if ("run" == b.Text)
            {
                Assert.Pass("'run', 'run'は交換しないのでテストはここで終了");
            }
            window.State.OnAction0();
            Assert.False(window.State.GetAllItems().OfType<WordCard>().Where(x => x.IsSelected).Any());

            // カード交換完了
            WindowState.NowObject.Now += TimeSpan.FromSeconds(1d);
            window.Tick();

            // カード交換で正解した場合は、次へ遷移してしまうのでここでエラー

            var xxxx = window.State.GetAllItems().OfType<WordCard>().ToArray();
            Assert.False(xxxx.Any(x => x.IsSelected));
            Assert.AreEqual(6, xxxx.Count());
            var aa = xxxx[0];
            var bb = xxxx[3];
            Assert.AreEqual(a.Text, bb.Text);
            Assert.AreEqual(b.Text, aa.Text);

            // マウスクリックテスト
            window.MouseMove(aa.BorderLeft, aa.BorderTop);
            window.Tick();
            Assert.AreSame(aa, window.State.CurrentItem);
            window.MouseUp(aa.BorderLeft, aa.BorderTop, MouseButtons.Left);
            Assert.True(aa.IsSelected);

            // 右クリックで選択を全解除
            window.State.CurrentItem = bb;
            window.MouseUp(0f, 0f, MouseButtons.Right);
            Assert.False(window.State.GetAllItems().Any(x => x.IsSelected));
        }
        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 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 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;
            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 DrawingObjectの位置交換()
        {
            var window = new EPuzzleWindow();
            var state = new WindowState(window);
            window.State = state;

            var container0 = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Relative,
                MarginLeft = 1f, MarginTop = 10f,
                Height = 100,
            };
            state.Items.Add(container0);
            var container1 = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Relative,
                MarginLeft = 1f, MarginTop = 10f,
                Height = 100,
            };
            state.Items.Add(container1);

            var a = new EigoTestLabelItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Width = 10, Height = 100,
                Name = "a",
            };
            container0.Items.Add(a);
            var b = new EigoTestLabelItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 0, Top = 0,
                Width = 20, Height = 100,
                Name = "b",
            };
            container1.Items.Add(b);
            var c = new EigoTestLabelItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 21, Top = 0,
                Width = 10, Height = 100,
                Name = "c",
            };
            container1.Items.Add(c);

            // container0
            Assert.AreEqual(1, container0.BorderLeft);
            Assert.AreEqual(10, container0.BorderTop);
            Assert.AreEqual(100, container0.Height);
            CollectionAssert.AreEqual(new [] { a, }, container0.Items);

            // container1
            Assert.AreEqual(1, container1.BorderLeft);
            Assert.AreEqual(120, container1.BorderTop);
            Assert.AreEqual(100, container1.Height);
            CollectionAssert.AreEqual(new [] { b, c, }, container1.Items);

            // a
            Assert.AreEqual("a", a.Name);
            Assert.AreEqual(1, a.OuterLeft);
            Assert.AreEqual(10, a.OuterTop);
            Assert.AreEqual(11, a.OuterRight);
            Assert.AreEqual(110, a.OuterBottom);

            // b
            Assert.AreEqual("b", b.Name);
            Assert.AreEqual(1, b.OuterLeft);
            Assert.AreEqual(120, b.OuterTop);
            Assert.AreEqual(21, b.OuterRight);
            Assert.AreEqual(220, b.OuterBottom);

            // c
            Assert.AreEqual("c", c.Name);
            Assert.AreEqual(22, c.OuterLeft);
            Assert.AreEqual(120, c.OuterTop);
            Assert.AreEqual(32, c.OuterRight);
            Assert.AreEqual(220, c.OuterBottom);

            WindowState.NowObject = new TestNowObject();
            WindowState.NowObject.Now = DateTime.MinValue;

            var idouJikan = TimeSpan.FromSeconds(1d);
            state.場所の入れ換え(a, c, idouJikan);

            var aa = state.Items.Single(x => "a" == x.Name);
            var cc = state.Items.Single(x => "c" == x.Name);

            Assert.False(a.IsClickable);
            Assert.False(a.IsVisible);
            Assert.False(c.IsClickable);
            Assert.False(c.IsVisible);

            Assert.False(aa.IsClickable);
            Assert.True(aa.IsVisible);
            Assert.AreEqual(DrawingObjectPosition.Absolute, aa.Position);
            Assert.AreSame(state.DrawingObjectRoot, aa.Parent);
            Assert.AreEqual(a.OuterLeft, aa.OuterLeft);
            Assert.AreEqual(a.OuterTop, aa.OuterTop);
            Assert.AreEqual(a.OuterWidth, aa.OuterWidth);

            Assert.False(cc.IsClickable);
            Assert.True(cc.IsVisible);
            Assert.AreEqual(DrawingObjectPosition.Absolute, cc.Position);
            Assert.AreSame(state.DrawingObjectRoot, cc.Parent);
            Assert.AreEqual(c.OuterLeft, cc.OuterLeft);
            Assert.AreEqual(c.OuterTop, cc.OuterTop);
            Assert.AreEqual(c.OuterWidth, cc.OuterWidth);

            // 移動中
            WindowState.NowObject.Now += TimeSpan.FromTicks((int)Math.Round(idouJikan.Ticks * 0.5f));
            window.Tick();

            Assert.AreEqual(c.OuterLeft + (a.OuterLeft - c.OuterLeft) * 0.5f, cc.OuterLeft, 0.1f);
            Assert.AreEqual(c.OuterTop + (a.OuterTop - c.OuterTop) * 0.5f, cc.OuterTop, 0.1f);
            Assert.AreEqual(c.Width + (a.Width - c.Width) * 0.5f, c.Width, 0.1f);

            Assert.AreEqual(a.OuterLeft + (c.OuterLeft - a.OuterLeft) * 0.5f, aa.OuterLeft, 0.1f);
            Assert.AreEqual(a.OuterTop + (c.OuterTop - a.OuterTop) * 0.5f, aa.OuterTop, 0.1f);
            Assert.AreEqual(a.Width + (c.Width - a.Width) * 0.5f, a.Width, 0.1f);

            // 場所の入れ換え完了
            WindowState.NowObject.Now += idouJikan;
            window.Tick();

            CollectionAssert.DoesNotContain(state.GetAllItems(), a);
            CollectionAssert.DoesNotContain(state.GetAllItems(), c);
            Assert.Null(a.Parent);
            Assert.Null(c.Parent);
            CollectionAssert.AreEqual(new [] { cc, }, container0.Items);
            CollectionAssert.AreEqual(new [] { b, aa }, container1.Items);
            Assert.True(aa.IsClickable);
            Assert.True(aa.IsVisible);
            Assert.True(cc.IsClickable);
            Assert.True(cc.IsVisible);

            // cc
            Assert.AreEqual("c", cc.Name);
            Assert.AreEqual(1, cc.OuterLeft);
            Assert.AreEqual(10, cc.OuterTop);
            Assert.AreEqual(11, cc.OuterRight);
            Assert.AreEqual(110, cc.OuterBottom);

            // aa
            Assert.AreEqual("a", aa.Name);
            Assert.AreEqual(22, aa.OuterLeft);
            Assert.AreEqual(120, aa.OuterTop);
            Assert.AreEqual(32, aa.OuterRight);
            Assert.AreEqual(220, aa.OuterBottom);
        }
        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 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 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 無効な入力で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 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 合格判定テスト()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
                WindowState.NowObject = new TestNowObject();
                WindowState.NowObject.Now = DateTime.MinValue;
                var window = new EPuzzleWindow(ePuzzleData);
                var userInfo = ePuzzleData.CurrentUserInfo;
                userInfo.GradeProcessor = GradeProcessorA.Instance;

                var daimon0 = ePuzzleData.CurrentMondaiDocument.Items[0];
                var chumon0 = daimon0.Items[0];
            //				chumon0.GradeProcessor = GradeProcessorA.Instance;
                Assert.AreEqual("-", chumon0.GetGradeString(userInfo));
                Assert.False(chumon0.合格判定(userInfo));

                userInfo.MondaiResults.AddNew(chumon0.Id, DateTime.MinValue, TimeSpan.FromHours(10d));
                Assert.AreEqual("D", chumon0.GetGradeString(userInfo));
                Assert.False(chumon0.合格判定(userInfo));

                userInfo.MondaiResults.AddNew(chumon0.Id, DateTime.MinValue, TimeSpan.FromSeconds(1d));
                Assert.True(chumon0.合格判定(userInfo));
            }
        }