public void BackToStartGameStateButtonTest()
        {
            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];

            //				CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, EPuzzleTutor.GetMondaiDocumentsFromIds(window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", }).Select(x => x.Id));
                CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, GetIds(TestUtility.Inv(typeof(EPuzzleTutor), "GetMondaiDocumentsFromIds", window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", })));

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);
                var tutorState = new TutorState(window, tutor);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);

                var backToStartGameStateButton = tutorState.GetAllItems().OfType<EigoTestButtonItem>().Single(x => "backToStartGameStateButton" == x.Name);
                window.State.CurrentItem = backToStartGameStateButton;
                window.State.OnAction0();

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

                Assert.IsInstanceOf<StartGameState>(window.State);
            }
        }
        public void 要復習項目が正しく抽出されていない感じがする_266()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\mondai1.xml", _mondai1);
                test.AddFile(@"mondai\mondai2.xml", _mondai2);
                test.AddFile(@"mondai\mondai3.xml", _mondai3);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocuments = window.EPuzzleData.MondaiDocuments;

                // 期間における復習猶予期間の最大値を書き換える
                ((GradeProcessorB)userInfo.GradeProcessor).期間における復習猶予期間の最大値 = new []
                {
                    new Pair<TimeSpan, TimeSpan>(TimeSpan.FromHours(12d), TimeSpan.FromHours(12d)),
                };

                {
                    var tutor = new EPuzzleTutor(userInfo, mondaiDocuments, TimeSpan.FromHours(12d), 30);
                    CollectionAssert.AreEqual(mondaiDocuments, tutor.MondaiDocuments);

                    {
                        CollectionAssert.AreEqual(new []
                        {
                            "d11", "d21", "d31",
            //						}, tutor.GetAllDaimons().Select(x => x.Id));
                        }, TestUtility.Invoke<IEnumerable<Daimon>>(tutor, "GetAllDaimons").Select(x => x.Id));

                        CollectionAssert.AreEqual(new []
                        {
                            "d11", "d21", "d31",
            //						}, tutor.GetUnlockedDaimons().Select(x => x.Id));
                        }, TestUtility.Invoke<IEnumerable<Daimon>>(tutor, "GetUnlockedDaimons").Select(x => x.Id));

                        CollectionAssert.AreEqual(new []
                        {
                            "c11", "c21", "c31",
            //						}, GetIds(tutor.GetUnlockedChumons()));
                        }, GetIds(TestUtility.Inv(tutor, "GetUnlockedChumons")));

                        CollectionAssert.AreEqual(new []
                        {
                            "c11", "c21", "c31",
                        }, GetIds(TestUtility.Inv(tutor, "GetChumons")));
                    }

                    var t0 = new DateTime(2013, 6, 11, 0, 0, 0); // UTC
                    var t1 = t0 + TimeSpan.FromHours(1d);
                    var t2 = t1 + TimeSpan.FromHours(1d);

                    EPuzzleTime.Now = t2;
            //					tutor.NumberOfQuestionsThatYouHaveToDoToday = 3;
                    TestUtility.SetValue(tutor, "NumberOfQuestionsThatYouHaveToDoToday", 3);

                    CollectionAssert.AreEqual(new []
                    {
                        "c11", "c21", "c31",
                    }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                    // 指定時間が経過していないがグレードAに達していない問題はやっていないことにされるため。
                    userInfo.MondaiResults.AddNew("c11", t0, TimeSpan.FromMinutes(5d));

                    CollectionAssert.AreEqual(new []
                    {
                        "c21", "c31",
                    }, GetIds(TestUtility.Inv(tutor, "GetChumons")));
                }
            }
        }
        public void もっとやる係数の自動リセットテスト()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\mondai.xml", @"<?xml version=""1.0"" encoding=""utf-8""?>
            <mondai-document id=""doc1"" title=""DocumentB"">
            <daimon id=""d1"" title=""基礎I"">
            <chumon id=""c1"" title=""This is a pen."">
            <shomon id=""s1"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c2"" title=""This is a pen."">
            <shomon id=""s2"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c3"" title=""This is a pen."">
            <shomon id=""s3"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c4"" title=""This is a pen."">
            <shomon id=""s4"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c5"" title=""This is a pen."">
            <shomon id=""s5"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c6"" title=""This is a pen."">
            <shomon id=""s6"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c7"" title=""This is a pen."">
            <shomon id=""s7"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c8"" title=""This is a pen."">
            <shomon id=""s8"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            </daimon>
            </mondai-document>");
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocuments = window.EPuzzleData.MondaiDocuments;

                userInfo.UseNewMethodThatGetsChumonsThatYouHaveDoneToday = true;
                userInfo.TimeToChangeDay = new TimeSpan(3, 0, 0);

                // 期間における復習猶予期間の最大値を書き換える
                ((GradeProcessorB)userInfo.GradeProcessor).期間における復習猶予期間の最大値 = new []
                {
                    new Pair<TimeSpan, TimeSpan>(TimeSpan.FromHours(12d), TimeSpan.FromHours(12d)),
                };

                var tutor = new EPuzzleTutor(userInfo, mondaiDocuments, TimeSpan.FromHours(12d), 1);
                CollectionAssert.AreEqual(mondaiDocuments, tutor.MondaiDocuments);
                Assert.AreEqual(1, tutor.NumberOfQuestionsThatYouHaveToDoToday);
                Assert.AreEqual(TimeSpan.FromHours(12f), tutor.この時間以内の問題は無視する);

                var t0 = new DateTime(2014, 1, 1, 12, 0, 0, DateTimeKind.Local);
                var now = t0 + TimeSpan.FromDays(30d);

                userInfo.MondaiResults.AddNew("c1", t0, TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c2", t0 + TimeSpan.FromSeconds(1d), TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c3", t0 + TimeSpan.FromSeconds(2d), TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c4", t0 + TimeSpan.FromSeconds(3d), TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c5", t0 + TimeSpan.FromSeconds(4d), TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c6", t0 + TimeSpan.FromSeconds(5d), TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c7", t0 + TimeSpan.FromSeconds(6d), TimeSpan.FromSeconds(3d));
                userInfo.MondaiResults.AddNew("c8", t0 + TimeSpan.FromSeconds(7d), TimeSpan.FromSeconds(3d));

                EPuzzleTime.Now = now;

                CollectionAssert.AreEquivalent(new []
                {
                    "c1",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                userInfo.MondaiResults.AddNew("c1", now - TimeSpan.FromHours(1d), TimeSpan.FromSeconds(3d));

                CollectionAssert.IsEmpty(TestUtility.Inv(tutor, "GetChumons"));

                tutor.もっとやる係数++;
                Assert.AreEqual(2, tutor.もっとやる係数);

                CollectionAssert.AreEquivalent(new []
                {
                    "c2",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                userInfo.MondaiResults.AddNew("c2", now - TimeSpan.FromHours(1d), TimeSpan.FromSeconds(3d));

                tutor.もっとやる係数++;
                Assert.AreEqual(3, tutor.もっとやる係数);

                CollectionAssert.AreEquivalent(new []
                {
                    "c3",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                EPuzzleTime.Now += TimeSpan.FromDays(1d);

                CollectionAssert.AreEquivalent(new []
                {
                    "c3", "c4", "c5",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                Assert.AreEqual(3, tutor.もっとやる係数);

                tutor.もっとやる係数を適正値に修正();

                CollectionAssert.AreEquivalent(new []
                {
                    "c3",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                Assert.AreEqual(1, tutor.もっとやる係数);
            }
        }
        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 mondaiDocuments = window.EPuzzleData.MondaiDocuments;
            //				userInfo.HoursToIgnoreMondaisThatYouHaveDone = 5.8f;

                // 期間における復習猶予期間の最大値を書き換える
                ((GradeProcessorB)userInfo.GradeProcessor).期間における復習猶予期間の最大値 = new []
                {
                    new Pair<TimeSpan, TimeSpan>(TimeSpan.FromHours(12d), TimeSpan.FromHours(12d)),
                };
                {
                    var tutor = new EPuzzleTutor(userInfo, new [] { mondaiDocuments[0], }, TimeSpan.FromHours(12d), 30);
                    CollectionAssert.AreEqual(new [] { mondaiDocuments[0], }, tutor.MondaiDocuments);
            //					Assert.AreEqual(TimeSpan.FromHours(5.8f), tutor.この時間以内の問題は無視する);
                }
            //				userInfo.HoursToIgnoreMondaisThatYouHaveDone = 6f;
                {
                    var tutor = new EPuzzleTutor(userInfo, mondaiDocuments, TimeSpan.FromHours(12d), 30);
                    CollectionAssert.AreEqual(mondaiDocuments, tutor.MondaiDocuments);
            //					Assert.AreEqual(TimeSpan.FromHours(6f), tutor.この時間以内の問題は無視する);

                    {
                        CollectionAssert.AreEqual(new []
                        {
                            "daimon1", "daimon2", "daimon3", "daimon1", "daimon2", "daimon3", "daimon4", "daimon5", "daimon6", "daimon_hatsuon_mondai_test",
            //						}, tutor.GetAllDaimons().Select(x => x.Id));
                        }, TestUtility.Invoke<IEnumerable<Daimon>>(tutor, "GetAllDaimons").Select(x => x.Id));

                        CollectionAssert.AreEqual(new []
                        {
                            "daimon1", "daimon1",
            //						}, tutor.GetUnlockedDaimons().Select(x => x.Id));
                        }, TestUtility.Invoke<IEnumerable<Daimon>>(tutor, "GetUnlockedDaimons").Select(x => x.Id));

                        CollectionAssert.AreEqual(new []
                        {
                            "d1_chumon1", "chumon1",
            //						}, GetIds(tutor.GetUnlockedChumons()));
                        }, GetIds(TestUtility.Inv(tutor, "GetUnlockedChumons")));

                        CollectionAssert.AreEqual(new []
                        {
                            "d1_chumon1", "chumon1",
                        }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                        var t0 = new DateTime(2013, 6, 11, 0, 0, 0); // UTC
                        var t1 = t0 + TimeSpan.FromDays(10d);
                        var t2 = t1 + TimeSpan.FromDays(10d);
                        var t2a = t2 + TimeSpan.FromDays(5d);
                        var t2b = t2a + TimeSpan.FromDays(1d);
                        var t3 = t2 + TimeSpan.FromDays(10d);

                        userInfo.MondaiResults.AddNew("d1_chumon1", t1, TimeSpan.FromSeconds(10d));
                        userInfo.MondaiResults.AddNew("d1_chumon2", t2, TimeSpan.FromSeconds(20d));
                        userInfo.MondaiResults.AddNew("d2_chumon1", t2a, TimeSpan.FromSeconds(1d));
                        userInfo.MondaiResults.AddNew("d2_chumon1", t2b, TimeSpan.FromSeconds(1d));
                        EPuzzleTime.Now = t3;

                        Assert.NotNull(mondaiDocuments[0].GetItem("d2_chumon2"));
                        Assert.NotNull(mondaiDocuments[1].GetItem("chumon1"));
                        Assert.AreEqual(t1 + TimeSpan.FromHours(12d), TestUtility.Inv(tutor, "復習猶予期間と最終プレイ時間を足す", (Chumon)mondaiDocuments[0].GetItem("d1_chumon1")));
                        Assert.AreEqual(t2 + TimeSpan.FromHours(12d), TestUtility.Inv(tutor, "復習猶予期間と最終プレイ時間を足す", (Chumon)mondaiDocuments[0].GetItem("d1_chumon2")));
                        Assert.AreEqual(t3, TestUtility.Inv(tutor, "復習猶予期間と最終プレイ時間を足す", (Chumon)mondaiDocuments[0].GetItem("d2_chumon2")));
                        Assert.AreEqual(t3, TestUtility.Inv(tutor, "復習猶予期間と最終プレイ時間を足す", (Chumon)mondaiDocuments[1].GetItem("chumon1")));
                        Assert.AreEqual
                        (
                            t2b + ((Chumon)mondaiDocuments[0].GetItem("d2_chumon1")).復習までの猶予期間を取得(userInfo),
                            TestUtility.Inv(tutor, "復習猶予期間と最終プレイ時間を足す", (Chumon)mondaiDocuments[0].GetItem("d2_chumon1"))
                        );

                        var d1_chumon1 = (Chumon)mondaiDocuments[0].GetItem("d1_chumon1");
                        var d1_chumon2 = (Chumon)mondaiDocuments[0].GetItem("d1_chumon2");
                        var d2_chumon1 = (Chumon)mondaiDocuments[0].GetItem("d2_chumon1");

                        Assert.False(d1_chumon1.IsLocked(userInfo));
                        Assert.False(d1_chumon2.IsLocked(userInfo));
                        Assert.False(d2_chumon1.IsLocked(userInfo));

                        CollectionAssert.AreEqual(new []
                        {
                            "d1_chumon1", "d1_chumon2", "d2_chumon2", "d2_chumon3", "d2_chumon4", "chumon1", "d2_chumon1"
                        }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                        CollectionAssert.AreEqual(new []
                        {
                            "A", "B", "-", "-", "-", "-", "A",
                        }, TestUtility.Invoke<IEnumerable<Chumon>>(tutor, "GetChumons").Select(x => x.GetGradeString(userInfo)).ToArray());

                        CollectionAssert.AreEqual(new []
                        {
                            "B", "A", "A", "-", "-", "-", "-",
                        }, tutor.GetChumons(true).Select(x => x.GetGradeString(userInfo)).ToArray());

                        userInfo.MondaiResults.AddNew("d1_chumon1", t3, TimeSpan.FromSeconds(1d));

                        CollectionAssert.AreEqual(new []
                        {
                            "d1_chumon2", "d2_chumon2", "d2_chumon3", "d2_chumon4", "chumon1", "d2_chumon1"
                        }, GetIds(TestUtility.Inv(tutor, "GetChumons")));
                    }
                }
            }
        }
        public void SortChumonsByDateYouDidThem_Test()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\mondai.xml", @"<?xml version=""1.0"" encoding=""utf-8""?>
            <mondai-document id=""doc1"" title=""DocumentB"">
            <daimon id=""d1"" title=""基礎I"">
            <chumon id=""c1"" title=""This is a pen."">
            <shomon id=""s1"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c2"" title=""This is a pen."">
            <shomon id=""s2"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c3"" title=""This is a pen."">
            <shomon id=""s3"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            </daimon>
            </mondai-document>");
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocuments = window.EPuzzleData.MondaiDocuments;
                var mondaiDocument = mondaiDocuments.First();

                userInfo.UseNewMethodThatGetsChumonsThatYouHaveDoneToday = true;
                userInfo.DoesNotShowChumonsYouHaveNeverDone = false;
                userInfo.TimeToChangeDay = new TimeSpan(3, 0, 0);
                userInfo.HideChumonsYouHaveGotGradeAToday = false;
                userInfo.Difficulty = Difficulty.Normal;

                // 期間における復習猶予期間の最大値を書き換える
                ((GradeProcessorB)userInfo.GradeProcessor).期間における復習猶予期間の最大値 = new []
                {
                    new Pair<TimeSpan, TimeSpan>(TimeSpan.FromHours(12d), TimeSpan.FromHours(12d)),
                };

                var tutor = new EPuzzleTutor(userInfo, mondaiDocuments, TimeSpan.FromHours(12d), 10);
                CollectionAssert.AreEqual(mondaiDocuments, tutor.MondaiDocuments);
                Assert.AreEqual(10, tutor.NumberOfQuestionsThatYouHaveToDoToday);
                Assert.AreEqual(TimeSpan.FromHours(12f), tutor.この時間以内の問題は無視する);

                var t0 = new DateTime(2014, 1, 21, 15, 0, 0, DateTimeKind.Local);
                var t1 = t0 + TimeSpan.FromMinutes(5d);
                var t2 = t1 + TimeSpan.FromMinutes(5d);
            //				var t3 = t2 + TimeSpan.FromMinutes(5d);
                EPuzzleTime.Now = t2 + TimeSpan.FromHours(3d);

                var mondaiResult = new MondaiResult("c1", t0, TimeSpan.FromSeconds(1d), Difficulty.Normal);
                userInfo.MondaiResults.Add(mondaiResult);

                CollectionAssert.AreEqual(new []
                {
                    "c1",
                }, GetIds(tutor.SortChumonsByDateYouDidThem()));

                userInfo.MondaiResults.AddNew("c2", t1, TimeSpan.FromSeconds(1d));

                CollectionAssert.AreEqual(new []
                {
                    "c2", "c1",
                }, GetIds(tutor.SortChumonsByDateYouDidThem()));

                userInfo.MondaiResults.AddNew("c1", t2, TimeSpan.FromSeconds(1d));

                CollectionAssert.AreEqual(new []
                {
                    "c1", "c2",
                }, GetIds(tutor.SortChumonsByDateYouDidThem()));

                // 難易度についてのテストは今回は行わない。難易度制度を残さない可能性があるため。
            }
        }
        public void NumberOfQuestionsThatYouHaveToDoTodayTest()
        {
            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 mondaiDocuments = window.EPuzzleData.MondaiDocuments;

                var tutor = new EPuzzleTutor(userInfo, mondaiDocuments, TimeSpan.FromHours(12d), 30);
                CollectionAssert.AreEqual(mondaiDocuments, tutor.MondaiDocuments);

                Assert.AreEqual(30, tutor.NumberOfQuestionsThatYouHaveToDoToday);
            /*				Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    tutor.NumberOfQuestionsThatYouHaveToDoToday = 0;
                });
                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    tutor.NumberOfQuestionsThatYouHaveToDoToday = -1;
                });*/

                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon1", "chumon1",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                //

                // tutor.NumberOfQuestionsThatYouHaveToDoToday = 1;
                TestUtility.SetValue(tutor, "NumberOfQuestionsThatYouHaveToDoToday", 1);

                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon1",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                //

                //tutor.NumberOfQuestionsThatYouHaveToDoToday = 30;
                TestUtility.SetValue(tutor, "NumberOfQuestionsThatYouHaveToDoToday", 30);

                {
                    var chumons = TestUtility.Invoke<IEnumerable<Chumon>>(tutor, "GetChumons").ToArray();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1", "chumon1",
                    }, GetIds(chumons));

                    var t0 = new DateTime(2013, 6, 11, 0, 0, 0); // UTC
                    userInfo.MondaiResults.AddNew("d1_chumon1", t0, TimeSpan.FromSeconds(5d));
                    Assert.AreEqual("A", chumons.ElementAt(0).GetNewestGradeString(userInfo));
                    EPuzzleTime.Now = t0;
                }

                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon2", "chumon1",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));

                // tutor.NumberOfQuestionsThatYouHaveToDoToday = 1;
                TestUtility.SetValue(tutor, "NumberOfQuestionsThatYouHaveToDoToday", 1);

                CollectionAssert.AreEqual(Enumerable.Empty<string>(), GetIds(TestUtility.Inv(tutor, "GetChumons")));

                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon2",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons", false, 2)));

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    TestUtility.Inv(tutor, "GetChumons", false, -1);
                });
                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    TestUtility.Inv(tutor, "GetChumons", false, 0);
                });
            }
        }
        public void EPuzzleUserInfo_UseNewMethodThatGetsChumonsThatYouHaveDoneTodayへの対応テスト()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\mondai.xml", _mondai4);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocuments = window.EPuzzleData.MondaiDocuments;

                userInfo.UseNewMethodThatGetsChumonsThatYouHaveDoneToday = true;
                userInfo.TimeToChangeDay = new TimeSpan(3, 0, 0);

                // 期間における復習猶予期間の最大値を書き換える
                ((GradeProcessorB)userInfo.GradeProcessor).期間における復習猶予期間の最大値 = new []
                {
                    new Pair<TimeSpan, TimeSpan>(TimeSpan.FromHours(12d), TimeSpan.FromHours(12d)),
                };

                var tutor = new EPuzzleTutor(userInfo, mondaiDocuments, TimeSpan.FromHours(12d), 10);
                CollectionAssert.AreEqual(mondaiDocuments, tutor.MondaiDocuments);
                Assert.AreEqual(10, tutor.NumberOfQuestionsThatYouHaveToDoToday);
                Assert.AreEqual(TimeSpan.FromHours(12f), tutor.この時間以内の問題は無視する);

                var now = new DateTime(2014, 1, 21, 2, 0, 0, DateTimeKind.Local);

                // 表示される問題
                userInfo.MondaiResults.AddNew("c1", new DateTime(2014, 1, 10, 13, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(30d));
                userInfo.MondaiResults.AddNew("c1", new DateTime(2014, 1, 12, 14, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(30d));
                userInfo.MondaiResults.AddNew("c1", new DateTime(2014, 1, 20,  3, 1, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));

                userInfo.MondaiResults.AddNew("c2", new DateTime(2014, 1, 1,  1, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));
                userInfo.MondaiResults.AddNew("c2", new DateTime(2014, 1, 21,  1, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(30d));

                userInfo.MondaiResults.AddNew("c3", new DateTime(2014, 1, 1,  13, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));
                userInfo.MondaiResults.AddNew("c3", new DateTime(2014, 1, 6,  13, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));

                userInfo.MondaiResults.AddNew("c4", new DateTime(2014, 1, 10,  12, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));
                userInfo.MondaiResults.AddNew("c4", new DateTime(2014, 1, 19,  12, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));

                userInfo.MondaiResults.AddNew("c6", new DateTime(2013, 1, 10,  12, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(4d));
                userInfo.MondaiResults.AddNew("c6", new DateTime(2014, 1, 10,  12, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(4d));

                userInfo.MondaiResults.AddNew("c5", new DateTime(2014, 1, 10,  12, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));
                userInfo.MondaiResults.AddNew("c5", new DateTime(2014, 1, 20,  12, 0, 0, DateTimeKind.Local), TimeSpan.FromSeconds(2.9d));

                // 表示されない問題
                // "c8"

                EPuzzleTime.Now = now;

                CollectionAssert.AreEquivalent(new []
                {
                    "c1", "c2", "c3", "c4", "c5", "c6", "c7",
                }, GetIds(TestUtility.Inv(tutor, "GetChumons")));
            }
        }
        public void 問題がないときにKirokuBox2が表示される不具合()
        {
            using (var test = new EPuzzleTestManager())
            {
                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 t0 = new DateTime(2013, 8, 27, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);

            //				tutor.NumberOfQuestionsThatYouHaveToDoToday = 1;
                TestUtility.SetValue(tutor, "NumberOfQuestionsThatYouHaveToDoToday", 1);

                tutor.この時間以内の問題は無視する = TimeSpan.FromHours(12d);
                var tutorState = new TutorState(window, tutor);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                    window.State.CurrentItem = chumonButtons.ElementAt(0);

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

                    // CurrentItemは先頭のChumon
                    Assert.NotNull(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);

                    var kirokuBox = (KirokuBox2)TestUtility.GetValue(tutorState, "_kirokuBox");
                    Assert.AreEqual("d1_chumon1", kirokuBox.Chumon.Id);
                }
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.Null(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.Null(downButton);
                }
            /*				{
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.False(tutorState.OrderByGradeStrings);
                    Assert.AreEqual("復習猶予期間順", orderByGradeStringsButton.Text);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                }
                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.True(tutorState.OrderByGradeStrings);
                    Assert.AreEqual("最新の成績順", orderByGradeStringsButton.Text);
                }
                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                }
                Assert.False(tutorState.OrderByGradeStrings);
                */

                // Chumon開始

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    window.State.CurrentItem = chumonButtons.First();
                    Assert.IsInstanceOf<ChumonButton>(window.State.CurrentItem);
                }

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

                Assert.AreSame(tutorState, window.WindowStateWhichHasStartedChumon);

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "This is" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "a notebook" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "." == x.Text).First();
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(1d);
                window.State.Tick();
                window.State.Tick();

                test.FoFi();

                Assert.IsInstanceOf<ShomonState>(window.State);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "This" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "is" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "a" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "ball" == x.Text).First();
                window.State.OnAction0();

            //				EPuzzleTime.Now += TimeSpan.FromSeconds(10d);

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "." == x.Text).First();
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(1d);
                window.State.Tick();
                window.State.Tick();

                test.FoFi();

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

            //				EPuzzleTime.Now += TimeSpan.FromDays(1d);

                test.FoFi();

                Assert.IsInstanceOf<TutorState>(window.State);
                Assert.AreSame(tutorState, window.State);

                {
                    CollectionAssert.IsEmpty(window.State.GetAllItems().OfType<ChumonButton>());
                    Assert.Null(window.State.GetAllItems().OfType<KirokuBox2>().First().Chumon);
                    Assert.IsNotInstanceOf<ChumonButton>(window.State.CurrentItem);
                }
            }
        }
        public void マウスホイールテスト()
        {
            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];

            //				CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, EPuzzleTutor.GetMondaiDocumentsFromIds(window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", }).Select(x => x.Id));
                CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, GetIds(TestUtility.Inv(typeof(EPuzzleTutor), "GetMondaiDocumentsFromIds", window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", })));

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);
                var tutorState = new TutorState(window, tutor);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);
                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon1", "chumon1",
                }, window.State.GetAllItems().OfType<ChumonButton>().Select(x => x.Chumon.Id).ToArray());

                HelpWithScroll<Chumon> helpWithScroll = (HelpWithScroll<Chumon>)TestUtility.GetValue(tutorState, "_helpWithScroll");
                helpWithScroll.NumberOfItemsToBeShown = 1;
                tutorState.Refresh();

            //				Assert.AreEqual(0, tutorState.Index);
                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon1",
                }, window.State.GetAllItems().OfType<ChumonButton>().Select(x => x.Chumon.Id).ToArray());

                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);

                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon1",
                }, window.State.GetAllItems().OfType<ChumonButton>().Select(x => x.Chumon.Id).ToArray());

                // delta: -120

                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);

            //				Assert.AreEqual(1, helpWithScroll.Index);
                CollectionAssert.AreEqual(new []
                {
                    "chumon1",
                }, window.State.GetAllItems().OfType<ChumonButton>().Select(x => x.Chumon.Id).ToArray());

                // delta: -120

                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);
                window.MouseWheel(-120);

            //				Assert.AreEqual(1, tutorState.Index);
                CollectionAssert.AreEqual(new []
                {
                    "chumon1",
                }, window.State.GetAllItems().OfType<ChumonButton>().Select(x => x.Chumon.Id).ToArray());

                // delta: 120 x 2

                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);
                window.MouseWheel(120);

            //				Assert.AreEqual(0, tutorState.Index);
                CollectionAssert.AreEqual(new []
                {
                    "d1_chumon1",
                }, window.State.GetAllItems().OfType<ChumonButton>().Select(x => x.Chumon.Id).ToArray());
            }
        }
        public void ChumonButton記憶()
        {
            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.AddFile(@"help\help0.png", fileName => new Bitmap(100, 100).Save(fileName, System.Drawing.Imaging.ImageFormat.Png));
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondai2 = window.EPuzzleData.MondaiDocuments[0];
                var mondai3 = window.EPuzzleData.MondaiDocuments[1];
                var t0 = new DateTime(2013, 9, 5, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

            //				CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, EPuzzleTutor.GetMondaiDocumentsFromIds(window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", }).Select(x => x.Id));
                CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, GetIds(TestUtility.Inv(typeof(EPuzzleTutor), "GetMondaiDocumentsFromIds", window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", })));

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);
                var tutorState = new TutorState(window, tutor);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                    window.State.CurrentItem = chumonButtons.ElementAt(0);

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

                    // CurrentItemは先頭のChumon
                    Assert.NotNull(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);

                    var kirokuBox = (KirokuBox2)TestUtility.GetValue(tutorState, "_kirokuBox");
                    Assert.NotNull(kirokuBox);
                    Assert.NotNull(kirokuBox.Chumon);
                    Assert.AreEqual("d1_chumon1", kirokuBox.Chumon.Id);
                }
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.Null(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.Null(downButton);
                }
            /*				{
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                }*/

                // Chumon開始

                userInfo.MondaiResults.AddNew("d1_chumon1", t0 - TimeSpan.FromDays(2d), TimeSpan.FromSeconds(1d));
                tutorState.Refresh();

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    window.State.CurrentItem = chumonButtons.Skip(2).First();
                    Assert.IsInstanceOf<ChumonButton>(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);
                }

                var currentItemInfo = window.State.SaveCurrentItem();
                Assert.IsInstanceOf<ChumonButton>(currentItemInfo.Item);
                Assert.AreEqual("d1_chumon1", currentItemInfo.Item.Name);

                window.State.OnAction0();
                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                window.State.OnAction3();
                Assert.IsInstanceOf<TutorState>(window.State);
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());

                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Name));
                }
                Assert.IsInstanceOf<ChumonButton>(window.State.CurrentItem);
                Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);
            }
        }
        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.AddFile(@"help\help0.png", fileName => new Bitmap(100, 100).Save(fileName, System.Drawing.Imaging.ImageFormat.Png));
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondai2 = window.EPuzzleData.MondaiDocuments[0];
                var mondai3 = window.EPuzzleData.MondaiDocuments[1];

            //				CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, EPuzzleTutor.GetMondaiDocumentsFromIds(window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", }).Select(x => x.Id));
                CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, GetIds(TestUtility.Inv(typeof(EPuzzleTutor), "GetMondaiDocumentsFromIds", window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", })));

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);
                var tutorState = new TutorState(window, tutor);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                    window.State.CurrentItem = chumonButtons.ElementAt(0);

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

                    // CurrentItemは先頭のChumon
                    Assert.NotNull(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);

                    var kirokuBox = (KirokuBox2)TestUtility.GetValue(tutorState, "_kirokuBox");
                    Assert.AreEqual("d1_chumon1", kirokuBox.Chumon.Id);
                }
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.Null(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.Null(downButton);
                }
            /*				{
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.False(tutorState.OrderByGradeStrings);
                    Assert.AreEqual("復習猶予期間順", orderByGradeStringsButton.Text);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                }
                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.True(tutorState.OrderByGradeStrings);
                    Assert.AreEqual("最新の成績順", orderByGradeStringsButton.Text);
                }
                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                }

                Assert.False(tutorState.OrderByGradeStrings);
                */

                // Chumon開始

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    window.State.CurrentItem = chumonButtons.First();
                    Assert.IsInstanceOf<ChumonButton>(window.State.CurrentItem);
                }

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

                Assert.AreSame(tutorState, window.WindowStateWhichHasStartedChumon);

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "This is" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "a notebook" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "." == x.Text).First();
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(1d);
                window.State.Tick();
                window.State.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);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "This" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "is" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "a" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "ball" == x.Text).First();
                window.State.OnAction0();

                EPuzzleTime.Now += TimeSpan.FromSeconds(10d);

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "." == x.Text).First();
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(1d);
                window.State.Tick();
                window.State.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);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.State.OnAction0();
                window.Tick();

            //				EPuzzleTime.Now += TimeSpan.FromDays(1d);

                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<TutorState>(window.State);
                Assert.AreSame(tutorState, window.State);

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    Assert.AreEqual("B", chumonButtons.First(x => "d1_chumon1" == x.Chumon.Id).Chumon.GetNewestGradeString(userInfo));
                    Assert.AreEqual("-", chumonButtons.First(x => "d1_chumon2" == x.Chumon.Id).Chumon.GetNewestGradeString(userInfo));
                    Assert.AreEqual("-", chumonButtons.First(x => "chumon1" == x.Chumon.Id).Chumon.GetNewestGradeString(userInfo));
                }
                HelpWithScroll<Chumon> helpWithScroll = (HelpWithScroll<Chumon>)TestUtility.GetValue(tutorState, "_helpWithScroll");
                {
                    Assert.AreEqual(0, helpWithScroll.NumberOfUpperItems);
                    Assert.AreEqual(-15, helpWithScroll.NumberOfLowerItems);
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());

                    Assert.NotNull(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);
                }

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    helpWithScroll.NumberOfItemsToBeShown = 0;
                });

                helpWithScroll.NumberOfItemsToBeShown = 2;
                tutorState.Refresh();

                {
                    Assert.AreEqual(0, helpWithScroll.NumberOfUpperItems);
                    Assert.AreEqual(1, helpWithScroll.NumberOfLowerItems);
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.Null(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.NotNull(downButton);

                    window.State.CurrentItem = downButton;
                    window.State.OnAction0();
                }

                {
                    Assert.AreEqual(1, helpWithScroll.NumberOfUpperItems);
                    Assert.AreEqual(0, helpWithScroll.NumberOfLowerItems);
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.NotNull(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.Null(downButton);

                    window.State.CurrentItem = upButton;
                    window.State.OnAction0();
                }

                {
                    Assert.AreEqual(0, helpWithScroll.NumberOfUpperItems);
                    Assert.AreEqual(1, helpWithScroll.NumberOfLowerItems);
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.Null(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.NotNull(downButton);
                }

            /*				Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    helpWithScroll.Index = 0;
                    helpWithScroll.Index--;
                });
                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    helpWithScroll.Index = 1;
                    helpWithScroll.Index++;
                });*/

                helpWithScroll.ScrollUp(100);
            //				helpWithScroll.Index = 0;
                tutorState.Refresh();
                {
                    var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                    Assert.Null(upButton);
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.NotNull(downButton);
                }

                // Ctrl + Down
                window.State.OnActionDown();

                {
                    {
                        var upButton = window.State.GetAllItems().Where(x => "upButton" == x.Name).FirstOrDefault();
                        Assert.NotNull(upButton);
                        var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                        Assert.Null(downButton);
                    }

                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                window.State.OnActionDown();
                window.State.OnActionDown();
                window.State.OnActionDown();

                // Ctrl + Up
                window.State.OnActionUp();

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                window.State.OnActionUp();
                window.State.OnActionUp();
                window.State.OnActionUp();

                helpWithScroll.NumberOfItemsToBeShown = 3;
                tutorState.Refresh();

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2", "chumon1", "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());

                    CollectionAssert.AreEqual(new []
                    {
                        "-", "-", "B",
                    }, chumonButtons.Select(x => x.Chumon.GetGradeString(userInfo)));
                }

            /*				Assert.False(tutorState.OrderByGradeStrings);

                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                    Assert.True(tutorState.OrderByGradeStrings);

                    orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.AreEqual("最新の成績順", orderByGradeStringsButton.Text);
                }
                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                    Assert.False(tutorState.OrderByGradeStrings);

                    orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.AreEqual("復習猶予期間順", orderByGradeStringsButton.Text);
                }
                {
                    var orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    window.State.CurrentItem = orderByGradeStringsButton;
                    window.State.OnAction0();
                    Assert.True(tutorState.OrderByGradeStrings);

                    orderByGradeStringsButton = window.State.GetAllItems().First(x => "orderByGradeStringsButton" == x.Name);
                    Assert.AreEqual("最新の成績順", orderByGradeStringsButton.Text);
                }*/

                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGradeButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("成績順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);

                    // 成績順ボタンを押下
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1", "d1_chumon2", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());

                    CollectionAssert.AreEqual(new []
                    {
                        "B", "-", "-",
                    }, chumonButtons.Select(x => x.Chumon.GetGradeString(userInfo)));
                }

            //				helpWithScroll.NumberOfItemsToBeShown = 1;
                TestUtility.GetValue(window.State, "_gradeScrollHelper").NumberOfItemsToBeShown = 1;
                tutorState.Refresh();

                window.State.OnActionUp();
                window.State.OnActionUp();
                window.State.OnActionUp();
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.NotNull(downButton);
                    window.State.CurrentItem = downButton;
                    window.State.OnAction0();
                }
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon2",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());

                    var downButton = window.State.GetAllItems().Where(x => "downButton" == x.Name).FirstOrDefault();
                    Assert.NotNull(downButton);
                    Assert.AreSame(downButton, window.State.CurrentItem);
                }
            }
        }
        public void ShomonStateの戻るボタンの修正()
        {
            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];

            //				CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, EPuzzleTutor.GetMondaiDocumentsFromIds(window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", }).Select(x => x.Id));
                CollectionAssert.AreEqual(new [] { "mondaiDocument1", }, GetIds(TestUtility.Inv(typeof(EPuzzleTutor), "GetMondaiDocumentsFromIds", window.EPuzzleData.MondaiDocuments, new [] { "mondaiDocument1", })));

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);
                var tutorState = new TutorState(window, tutor);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "d1_chumon1", "chumon1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                    window.State.CurrentItem = chumonButtons.ElementAt(0);

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

                    // CurrentItemは先頭のChumon
                    Assert.NotNull(window.State.CurrentItem);
                    Assert.AreEqual("d1_chumon1", ((ChumonButton)window.State.CurrentItem).Chumon.Id);
                }

                // Chumon開始

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

                var backButton = window.State.GetAllItems().First(x => "back" == x.Name);
                window.State.CurrentItem = backButton;
                window.State.OnAction0();

                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<TutorState>(window.State);
            }
        }
        public void 試験順ボタンのテスト()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\mondai.xml", @"<?xml version=""1.0"" encoding=""utf-8""?>
            <mondai-document id=""doc1"" title=""DocumentB"">
            <daimon id=""d1"" title=""基礎I"">
            <chumon id=""c1"" title=""This is a pen."">
            <shomon id=""s1"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c2"" title=""This is a pen."">
            <shomon id=""s2"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            <chumon id=""c3"" title=""This is a pen."">
            <shomon id=""s3"">
                <mondaibun>[英訳] これはボールです。</mondaibun>
                <seikai>This is a ball.</seikai>
                <word>This is</word>
                <word>a ball.</word>
            </shomon>
            </chumon>
            </daimon>
            </mondai-document>");
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocuments = window.EPuzzleData.MondaiDocuments;
                var mondaiDocument = mondaiDocuments.First();

                userInfo.UseNewMethodThatGetsChumonsThatYouHaveDoneToday = true;
                userInfo.DoesNotShowChumonsYouHaveNeverDone = false;
                userInfo.TimeToChangeDay = new TimeSpan(3, 0, 0);
                userInfo.HideChumonsYouHaveGotGradeAToday = false;
                userInfo.Difficulty = Difficulty.Normal;
                userInfo.GradeProcessor = new TestGradeProcessor();
                Assert.IsInstanceOf<GradeProcessorB>(userInfo.GradeProcessor);

                // 期間における復習猶予期間の最大値を書き換える
                ((GradeProcessorB)userInfo.GradeProcessor).期間における復習猶予期間の最大値 = new []
                {
                    new Pair<TimeSpan, TimeSpan>(TimeSpan.FromHours(12d), TimeSpan.FromHours(12d)),
                };

                var tutor = new EPuzzleTutor(userInfo, window.EPuzzleData.MondaiDocuments, TimeSpan.FromHours(12d), 30);
                var tutorState = new TutorState(window, tutor);

                var t0 = new DateTime(2013, 9, 5, 0, 0, 0); // UTC
                var t1 = t0 + TimeSpan.FromMinutes(10d);
                var t2 = t1 + TimeSpan.FromMinutes(10d);
                EPuzzleTime.Now = t2 + TimeSpan.FromDays(1d);

                window.State = tutorState;
                Assert.IsInstanceOf<TutorState>(window.State);
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }

                // byDateYouDidThemButton
                // byGracePriodButton
                // byGradeButton

                userInfo.MondaiResults.AddNew("c1", t2, TimeSpan.FromSeconds(1d));
                userInfo.MondaiResults.AddNew("c2", t1, TimeSpan.FromSeconds(1.1d));
                userInfo.MondaiResults.AddNew("c3", t0, TimeSpan.FromSeconds(1.2d));

                var c1 = (Chumon)mondaiDocument.GetItem("c1");
                var c2 = (Chumon)mondaiDocument.GetItem("c2");
                var c3 = (Chumon)mondaiDocument.GetItem("c3");

                tutorState.Refresh();
                Assert.AreEqual(TutorStateSortType.GracePriod, TestUtility.GetValue(tutorState, "_sortType"));
                Assert.AreEqual(TimeSpan.FromDays(2d), c1.復習までの猶予期間を取得(userInfo));
                Assert.AreEqual(TimeSpan.FromDays(1d), c2.復習までの猶予期間を取得(userInfo));
                Assert.AreEqual(TimeSpan.FromDays(3d), c3.復習までの猶予期間を取得(userInfo));
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c2", "c1", "c3",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGracePriodButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("猶予順", button.Text);
                    Assert.False(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byDateYouDidThemButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("試験順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGradeButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("成績順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);

                    // 成績順ボタンを押下
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }

                Assert.AreEqual(TutorStateSortType.Grade, TestUtility.GetValue(tutorState, "_sortType"));
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c3", "c2", "c1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGracePriodButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("猶予順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGradeButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("成績順", button.Text);
                    Assert.False(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byDateYouDidThemButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("試験順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);

                    // 試験順ボタンを押下
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }

                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c1", "c2", "c3",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                Assert.AreEqual(TutorStateSortType.DateYouDidThem, TestUtility.GetValue(tutorState, "_sortType"));
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGradeButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("成績順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byDateYouDidThemButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("試験順", button.Text);
                    Assert.False(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGracePriodButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("猶予順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);

                    // 復習猶予期間順ボタンを押下
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }

                Assert.AreEqual(TutorStateSortType.GracePriod, TestUtility.GetValue(tutorState, "_sortType"));
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c2", "c1", "c3",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGracePriodButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("猶予順", button.Text);
                    Assert.False(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byDateYouDidThemButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("試験順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);
                }
                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGradeButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("成績順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);
                }

                // 各ボタンで、並び順が保存されているかどうかテストする。
                {
                    var scrollHelper = TestUtility.GetValue(tutorState, "_helpWithScroll");
                    scrollHelper.NumberOfItemsToBeShown = 2;
                    tutorState.Refresh();
                    Assert.AreEqual(0, TestUtility.GetValue(scrollHelper, "_index"));
                }
                Assert.AreEqual(TutorStateSortType.GracePriod, TestUtility.GetValue(tutorState, "_sortType"));
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c2", "c1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }

                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGradeButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("成績順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);

                    // 成績順ボタンを押下
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }

                // 成績順ボタン
                Assert.AreEqual(TutorStateSortType.Grade, TestUtility.GetValue(tutorState, "_sortType"));

                {
                    var scrollHelper = TestUtility.GetValue(tutorState, "_helpWithScroll");
                    scrollHelper.NumberOfItemsToBeShown = 2;
                    tutorState.Refresh();
                    Assert.AreEqual(0, TestUtility.GetValue(scrollHelper, "_index"));
                }
                {
                    var downButton = window.State.GetAllItems().FirstOrDefault(x => "downButton" == x.Name);

                    // 下スクロールボタンを押下
                    window.State.CurrentItem = downButton;
                    window.State.OnAction0();
                }
                {
                    var chumonButtons = window.State.GetAllItems().OfType<ChumonButton>();
                    CollectionAssert.AreEqual(new []
                    {
                        "c2", "c1",
                    }, chumonButtons.Select(x => x.Chumon.Id).ToArray());
                }

                {
                    var scrollHelper = TestUtility.GetValue(tutorState, "_helpWithScroll");
                    scrollHelper.NumberOfItemsToBeShown = 2;
                    tutorState.Refresh();

                    Assert.AreSame(scrollHelper, TestUtility.GetValue(tutorState, "_gradeScrollHelper"));
                    Assert.AreEqual(TutorStateSortType.Grade, TestUtility.GetValue(tutorState, "_sortType"));
                    Assert.AreEqual(1, TestUtility.GetValue(scrollHelper, "_index"));
                }

                {
                    var button = window.State.GetAllItems().FirstOrDefault(x => "byGracePriodButton" == x.Name);
                    Assert.NotNull(button);
                    Assert.AreEqual("猶予順", button.Text);
                    Assert.True(button.IsClickable);
                    Assert.True(button.IsVisible);

                    // 復習猶予期間順ボタンを押下
                    window.State.CurrentItem = button;
                    window.State.OnAction0();
                }

                // 復習猶予期間順ボタン
                Assert.AreEqual(TutorStateSortType.GracePriod, TestUtility.GetValue(tutorState, "_sortType"));
                {
                    var scrollHelper = TestUtility.GetValue(tutorState, "_helpWithScroll");
                    scrollHelper.NumberOfItemsToBeShown = 2;
                    tutorState.Refresh();

                    // 成績順ボタンを押下時に下スクロールしても、このボタンでスクロール位置が保存されているかどうか確認
                    Assert.AreEqual(0, TestUtility.GetValue(scrollHelper, "_index"));
                }
            }
        }