public void Action3で続けるボタン()
        {
            using (var testManager = new EPuzzleTestManager())
            {
                testManager.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                testManager.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                testManager.AddFile(@"help\help0.png", fileName => new Bitmap(100, 100).Save(fileName, System.Drawing.Imaging.ImageFormat.Png));
                testManager.Initialize();

                var window = testManager.Window;
                var helpDocumentSet = window.EPuzzleData.HelpDocumentSet;
                Assert.NotNull(helpDocumentSet);
                Assert.AreEqual("name0", helpDocumentSet.GetItem("help0").Name);

                var daimon = (Daimon)window.EPuzzleData.MondaiDocuments[0].GetItem("daimon1");
                var daimonState = new DaimonState(window, daimon);
                window.State = daimonState;
                var chumonButton = (ChumonButton)window.State.GetAllItems().OfType<ChumonButton>().First();
                var chumon = (Chumon)chumonButton.Chumon;
                Assert.AreEqual("chumon1", chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();

                testManager.AddTime(10);
                window.Tick();
                testManager.AddTime(10);
                window.Tick();

                Assert.IsInstanceOf<HelpItemState>(window.State);

                // 続けるボタン
                var tsudukeru = window.State.GetAllItems().First(x => "tsudukeru" == x.Name);
                window.State.CurrentItem = tsudukeru;
                window.State.OnAction3();
                window.Tick();

                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
            }
        }
        public void ChumonIdと同じHelpIdを見つけたら指定がなくても読み込む()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                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.AddFile(@"help\chumon1.png", fileName => new Bitmap(100, 100).Save(fileName, System.Drawing.Imaging.ImageFormat.Png));
                test.Initialize();

                var window = test.Window;
                var helpDocumentSet = window.EPuzzleData.HelpDocumentSet;
                Assert.NotNull(helpDocumentSet);
                Assert.AreEqual("name0", helpDocumentSet.GetItem("help0").Name);

                var daimon = (Daimon)window.EPuzzleData.MondaiDocuments[0].GetItem("daimon1");
                var daimonState = new DaimonState(window, daimon);
                window.State = daimonState;
                var chumonButton = (ChumonButton)window.State.GetAllItems().OfType<ChumonButton>().First();
                var chumon = (Chumon)chumonButton.Chumon;
                Assert.AreEqual("chumon1", chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();

                test.AddTime(10);
                window.Tick();
                test.AddTime(10);
                window.Tick();

                // help0
                {
                    Assert.IsInstanceOf<HelpItemState>(window.State);

                    Assert.AreEqual("help0", ((HelpItemState)window.State).HelpItem.Id);
                    var previousButton = window.State.GetAllItems().OfType<PreviousButton>().FirstOrDefault();
                    var nextButton = window.State.GetAllItems().OfType<NextButton>().FirstOrDefault();
                    Assert.Null(previousButton);
                    Assert.NotNull(nextButton);

                    window.State.CurrentItem = nextButton;
                    window.State.OnAction0();
                }
                // help1
                {
                    Assert.IsInstanceOf<HelpItemState>(window.State);

                    Assert.AreEqual("help1", ((HelpItemState)window.State).HelpItem.Id);
                    var previousButton = window.State.GetAllItems().OfType<PreviousButton>().FirstOrDefault();
                    var nextButton = window.State.GetAllItems().OfType<NextButton>().FirstOrDefault();
                    Assert.NotNull(previousButton);
                    Assert.NotNull(nextButton);

                    window.State.CurrentItem = nextButton;
                    window.State.OnAction0();
                }
                // chumon1
                {
                    Assert.IsInstanceOf<HelpItemState>(window.State);

                    Assert.AreEqual("chumon1", ((HelpItemState)window.State).HelpItem.Id);
                    var previousButton = window.State.GetAllItems().OfType<PreviousButton>().FirstOrDefault();
                    var nextButton = window.State.GetAllItems().OfType<NextButton>().FirstOrDefault();
                    Assert.NotNull(previousButton);
                    Assert.Null(nextButton);
                }
            }
        }
        public void CurrentItemがnullだとキーボードでのカーソル移動ができなくなる不具合()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                Assert.AreEqual(Difficulty.Normal, userInfo.Difficulty);
                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

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

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                window.State.OnAction0();

                Assert.True(window.State.ClickableItems.First().IsClickable);
                Assert.True(window.State.ClickableItems.First().IsVisible);

                window.State.CurrentItem = null;
                window.KeyDown(Keys.Right);
                Assert.NotNull(window.State.CurrentItem);
            //				Assert.AreSame(window.State.ClickableItems.First(), window.State.CurrentItem);

                window.State.CurrentItem = null;
                window.KeyDown(Keys.Left);
                Assert.NotNull(window.State.CurrentItem);
            //				Assert.AreSame(window.State.ClickableItems.First(), window.State.CurrentItem);

                window.State.CurrentItem = null;
                window.KeyDown(Keys.Up);
                Assert.NotNull(window.State.CurrentItem);
            //				Assert.AreSame(window.State.ClickableItems.First(), window.State.CurrentItem);

                window.State.CurrentItem = null;
                window.KeyDown(Keys.Down);
                Assert.NotNull(window.State.CurrentItem);
            //				Assert.AreSame(window.State.ClickableItems.First(), window.State.CurrentItem);
            }
        }
        public void ヘルプの表示は初回のみ()
        {
            using (var testManager = new EPuzzleTestManager())
            {
                testManager.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                testManager.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                testManager.AddFile(@"help\help0.png", fileName => new Bitmap(100, 100).Save(fileName, System.Drawing.Imaging.ImageFormat.Png));
                testManager.Initialize();

                var window = testManager.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var helpDocumentSet = window.EPuzzleData.HelpDocumentSet;
                Assert.NotNull(helpDocumentSet);
                Assert.AreEqual("name0", helpDocumentSet.GetItem("help0").Name);

                var daimon = (Daimon)window.EPuzzleData.MondaiDocuments[0].GetItem("daimon1");
                var daimonState = new DaimonState(window, daimon);
                window.State = daimonState;
                var chumonButton = (ChumonButton)window.State.GetAllItems().OfType<ChumonButton>().First();
                var chumon = (Chumon)chumonButton.Chumon;
                Assert.AreEqual("chumon1", chumon.Id);

                // クリア済み
                testManager.Unlock("chumon1");

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();

                testManager.AddTime(10);
                window.Tick();
                testManager.AddTime(10);
                window.Tick();

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

                // 情報ボタンの押下でヘルプページに遷移する

                Assert.IsInstanceOf<ShomonState>(window.State);
                var shomonState = (ShomonState)window.State;
                Assert.AreEqual(2, shomonState.Shomon.Parent.HelpIds.Count());

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

                Assert.IsInstanceOf<HelpItemState>(window.State);
                var helpItems = (HelpItemBase[])TestUtility.GetValue(window.State, "_helpItems");
                Assert.AreEqual("help0", helpItems[0].Id);
            }
        }
        public void ShomonStateTest()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

            //				Assert.False(ShomonState.ShowStars);
            //				ShomonState.ShowStars = true;

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

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

                var shomonState0 = (ShomonState)window.State;
                var card = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                window.State.CurrentItem = card;
                window.State.OnAction0();

                var xxxx = window.State.GetAllItems().OfType<Star>();
                Assert.AreEqual(1, xxxx.Count());
                var star = xxxx.First();
                Assert.AreEqual(DrawingObjectPosition.Absolute, star.Position);
                Assert.True(star.IsVisible);
                Assert.False(star.IsClickable);
                Assert.AreEqual(t0, star.StartTime);
                Assert.AreEqual(t0 + star.LifeTime, star.EndTime);
                Assert.AreEqual(card.BorderLeft + card.BorderWidth / 2f, star.BorderLeft);
                Assert.AreEqual(card.BorderTop + card.BorderHeight / 2f, star.BorderTop);

                var combo = window.State.GetAllItems().OfType<Combo>().Single();
                Assert.AreEqual(DrawingObjectPosition.Absolute, combo.Position);
                Assert.True(combo.IsVisible);
                Assert.False(combo.IsClickable);
                Assert.AreEqual(t0, combo.StartTime);
                Assert.AreEqual(t0 + combo.LifeTime, combo.EndTime);
            //				Assert.AreEqual(card.BorderLeft, combo.BorderLeft);
            //				Assert.AreEqual(card.BorderTop - combo.BorderHeight, combo.BorderTop);

                EPuzzleTime.Now += TimeSpan.FromMinutes(1d);
                window.State.Tick();
                CollectionAssert.DoesNotContain(window.State.GetAllItems(), star);
                Assert.AreEqual(0, window.State.GetAllItems().OfType<Star>().Count());

                CollectionAssert.DoesNotContain(window.State.GetAllItems(), combo);
                Assert.AreEqual(0, window.State.GetAllItems().OfType<Combo>().Count());

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

                {
                    var perfects = shomonState0.GetAllItems().OfType<Perfect>().ToArray();
                    Assert.AreEqual(0, perfects.Count());
                }

                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.AreEqual(0, window.State.GetAllItems().OfType<Star>().Count());

                Assert.IsInstanceOf<ShomonState>(window.State);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "I" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "have" == x.Text).First();
                window.State.OnAction0();

                {
                    var stars = window.State.GetAllItems().OfType<Star>().ToArray();
                    Assert.AreEqual(3, stars.Count());
                    CollectionAssert.AllItemsAreUnique(stars);

                    var combos = window.State.GetAllItems().OfType<Combo>().ToArray();
                    Assert.AreEqual(2, combos.Count());
                    CollectionAssert.AllItemsAreUnique(combos);

                    Assert.AreEqual(1, combos[0].Number);
                    Assert.AreEqual(2, combos[1].Number);
                }

                var shomonState = (ShomonState)window.State;

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

                {
                    var t1 = EPuzzleTime.Now;
                    var perfect = shomonState.GetAllItems().OfType<Perfect>().Single();
                    Assert.AreEqual(DrawingObjectPosition.Absolute, perfect.Position);
                    Assert.True(perfect.IsVisible);
                    Assert.False(perfect.IsClickable);
                    Assert.AreEqual(t1, perfect.StartTime);
                    Assert.AreEqual(t1 + perfect.LifeTime, perfect.EndTime);
                    Assert.AreEqual(0f, perfect.BorderLeft);
                    Assert.AreEqual(0f, perfect.BorderTop);
                    Assert.AreEqual(window.State.DrawingObjectRoot.Width, perfect.Width);
                    Assert.AreEqual(window.State.DrawingObjectRoot.Height, perfect.Height);
                }

                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);

                {
                    CollectionAssert.AreEqual
                    (
                        new [] { false, true, },
                        window.ChumonResult.ShomonResults.Select(x => x.IsPerfect)
                    );

                    var stars = window.State.GetAllItems().OfType<Pentagram>().ToArray();
                    Assert.AreEqual(2, stars.Count());
                    var shootingStars = window.State.GetAllItems().OfType<ShootingStar>().ToArray();
                    Assert.AreEqual(1, shootingStars.Count());

                    {
                        var sstar = shootingStars[0];
                        Assert.AreEqual(1024d, sstar.OuterLeft);
                        Assert.LessOrEqual(sstar.OuterTop, -30d);
                        Assert.AreEqual(stars[0].Height, sstar.Height);
                    }

                    Assert.AreEqual(0, stars[0].OuterLeft);
                    Assert.AreEqual(stars[0].OuterWidth, stars[1].OuterLeft);

                    Assert.AreEqual(window.State.DrawingObjectRoot.Height - stars[0].OuterHeight, stars[0].OuterTop);
                    Assert.AreEqual(window.State.DrawingObjectRoot.Height - stars[0].OuterHeight, stars[1].OuterTop);

                    Assert.AreEqual(DrawingObjectPosition.Absolute, stars[0].Position);
                    Assert.True(stars[0].IsVisible);
                    Assert.False(stars[0].IsClickable);
                    Assert.AreEqual(EPuzzleColors.PerfectStarOnChumonResultState, stars[0].Color);

                    Assert.False((bool)stars[0].Tag);
                    Assert.True((bool)stars[1].Tag);

                    Assert.AreEqual(Color.Empty, stars[0].BackColor);
                    Assert.AreEqual(Color.Empty, stars[1].BackColor);

                    {
                        // 星が落ちた直後に発動する星
                        var stars2 = window.State.GetAllItems().OfType<Star>().ToArray();
                        Assert.AreEqual(10, stars2.Count());
                        CollectionAssert.AreEqual(Enumerable.Range(0, stars2.Count()).Select(x => false), stars2.Select(x => x.IsVisible));

                        window.State.Tick();
                        var s = stars2.First();

                        Assert.AreEqual(shootingStars.First().EndTime, s.StartTime);
                        Assert.AreEqual(10, window.State.DrawingPreparers.Where(x => x.Name == "Star").Count());
                    }

                    int a = 0;
                    {
                        // 星が落ちた直後に発動する星
                        var stars2 = window.State.GetAllItems().OfType<Star>().ToArray();
                        Assert.AreEqual(10, stars2.Count());

                        var s = stars2.First();

            //						Assert.False((bool)TestUtility.GetValue((Animation)window.State.GetAllItems().OfType<Star>().First(), "_startedEventHasBeenCalled"));
            //						Assert.False(((Star)window.State.GetAllItems().OfType<Star>().First())._startedEventHasBeenCalled);
                        s.Started += (sender, e) =>
                        {
                            a++;
                        };

                        Assert.AreEqual(shootingStars.Single().EndTime, s.StartTime);
                    }

                    // 星が落ちた直後

                    window.Tick();
                    Assert.AreEqual(0, a);
                    var endTime = shootingStars.Single().EndTime;
                    Assert.Greater(endTime, EPuzzleTime.Now);
                    EPuzzleTime.Now = endTime;

                    window.Tick();
                    Assert.AreEqual(1, a);

                    {
                        var stars2 = window.State.GetAllItems().OfType<Star>().ToArray();
                        Assert.AreEqual(10, stars2.Count());
                        CollectionAssert.AreEqual(Enumerable.Range(0, stars2.Count()).Select(x => true), stars2.Select(x => x.IsVisible));

                        var star2 = stars2.First();

                        Assert.AreEqual(stars[1].OuterLeft, star2.OuterLeft);
                        Assert.AreEqual(stars[1].OuterTop, star2.OuterTop);
                    }

                    EPuzzleTime.Now += TimeSpan.FromHours(1d);
                    window.Tick();

                    Assert.AreEqual(Color.Empty, stars[0].BackColor);
                    Assert.AreNotEqual(Color.Empty, stars[1].BackColor);

                    window.State.OnAction0();
                    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<DaimonState>(window.State);
                Assert.AreEqual("基礎II", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon2", ((DaimonState)window.State).Daimon.Id);

                var mondaiResult = userInfo.MondaiResults.GetItems("2-1").Single();

                Assert.AreEqual(t0, mondaiResult.StartTime);
                Assert.AreEqual(TimeSpan.FromSeconds(2d), mondaiResult.所要時間);
                */
            }
        }
        public void 画面遷移中は時間を進めない()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();
                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                window.State.OnAction0();
                Assert.IsInstanceOf<ShomonState>(window.State);
                var shomonState0 = (ShomonState)window.State;
                Assert.AreEqual(TimeSpan.FromSeconds(0d), window.ChumonResult.Chumon時間調整);

                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 ball." == x.Text).First();
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(1d);
                Assert.IsInstanceOf<ShomonState>(window.State);
                window.State.Tick();
                window.State.Tick();
                Assert.AreEqual(t0 + TimeSpan.FromSeconds(1d), shomonState0.LeaveTime);

                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(TimeSpan.FromSeconds(2d), window.ChumonResult.Chumon時間調整);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "I" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "have" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "no" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "cousins" == 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<ChumonResultState>(window.State);
                WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
                window.State.OnAction0();
                window.Tick();

            //				Assert.AreEqual(TimeSpan.FromSeconds(4d), window.Chumon時間調整); //

                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<DaimonState>(window.State);
                Assert.AreEqual("基礎II", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon2", ((DaimonState)window.State).Daimon.Id);

                var mondaiResult = userInfo.MondaiResults.GetItems("2-1").Single();

                Assert.AreEqual(t0, mondaiResult.StartTime);
                Assert.AreEqual(TimeSpan.FromSeconds(2d), mondaiResult.所要時間);
            }
        }
        public void test0()
        {
            string xml =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <mondaiDocument version=""1.1"" id=""mondaiDocument1"">
            <title>Mondai Document 1</title>
            <description>Mondai Document 1の説明</description>
            <daimon id=""daimon1"">
            <title>Daimon 1</title>
            <description>Daimon 1の説明</description>
            <chumon id=""chumon1"">
            <title>Chumon 1</title>
            <description>Chumon 1の説明</description>
            <shomon id=""shomon2"">
                <question>[英訳] これはボールです。</question>
                <correctAnswer>This is a ball.</correctAnswer>
                <description></description>
                <inputMethod>typing</inputMethod>
                <soundFile when=""start"" numberOfTimes=""2"">sound1.wav</soundFile>
            </shomon>
            <shomon id=""shomon3"">
                <question>[英訳] これはボールです。</question>
                <correctAnswer>This is a ball.</correctAnswer>
                <description></description>
                <inputMethod>typing</inputMethod>
                <soundFile when=""start"" numberOfTimes=""2"">sound1.wav</soundFile>
                <soundFile when=""userRequest"" numberOfTimes=""2"">sound1.wav</soundFile>
            </shomon>
            </chumon>
            </daimon>
            </mondaiDocument>";

            string helpDocumentXml =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <ePuzzleHelpDocument>
            <helpItem id=""help0"" name=""name0"">
            <image file=""help0.png"" />
            </helpItem>
            <helpItem id=""help1"" name=""name1"" />
            <helpItem id=""help2"" name=""name2"" />
            <helpItem id=""chumonxxx"" name=""name3"">
            <image file=""chumon1.png"" />
            </helpItem>
            </ePuzzleHelpDocument>";

            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", xml);
                test.AddFile(@"help\HelpDocument.xml", helpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon1");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                userInfo.Difficulty = Difficulty.Hard;

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("chumon1", chumonButton.Chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();
                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                window.State.OnAction0();

                {
                    Assert.IsInstanceOf<ShomonStateTyping>(window.State);
                    Assert.AreEqual("shomon2", ((ShomonStateTyping)window.State).Shomon.Id);
                    var shomonState = (ShomonStateBase)window.State;
                    Assert.NotNull(shomonState.Shomon.NextItem);

                    window.State.CurrentItem = null;
                    window.InputDevice = InputDevice.Keyboard;

                    var answerBox = (EigoTestLabelItem)window.State.GetAllItems().Where(x => "answerBox" == x.Name).Single();
            //				var answerBox = (EigoTestLabelItem)TestUtility.GetValue(window.State, "AnswerBox");
            //				Assert.NotNull(answerBox);

                    // UserRequestが指定されていないときは音声再生ボタンを表示しない。
                    Assert.False(window.State.GetAllItems().Where(x => "playSound" == x.Name).Any());

                    window.KeyPress('A');
                    Assert.AreEqual("A", answerBox.Text);

                    window.KeyPress('b');
                    Assert.AreEqual("Ab", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    Assert.AreEqual("A", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    Assert.AreEqual("", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    Assert.AreEqual("", answerBox.Text);

                    window.KeyPress('b');
                    window.KeyPress('b');
                    window.KeyPress('b');
                    window.KeyPress('b');
                    window.KeyPress('b');
                    window.KeyPress('b');
                    Assert.AreEqual("bbbbbb", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    window.KeyPress('\u0008');
                    Assert.AreEqual("bbbbb", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    window.KeyPress('\u0008');
                    Assert.AreEqual("bbbb", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    window.KeyPress('\u0008');
                    Assert.AreEqual("bbb", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    window.KeyPress('\u0008');
                    Assert.AreEqual("bb", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    window.KeyPress('\u0008');
                    Assert.AreEqual("b", answerBox.Text);

                    window.KeyDown(Keys.Back);
                    window.KeyPress('\u0008');
                    Assert.AreEqual("", answerBox.Text);

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

                    // This is a ball.
                    window.KeyPress('T');
                    window.KeyPress('h');
                    window.KeyPress('i');
                    window.KeyPress('s');
                    window.KeyPress(' ');
                    window.KeyPress('i');
                    window.KeyPress('s');
                    window.KeyPress(' ');
                    window.KeyPress('a');
                    window.KeyPress(' ');
                    window.KeyPress('b');
                    window.KeyPress('a');
                    window.KeyPress('l');
                    window.KeyPress('l');
                    window.KeyPress('.');

                    Assert.AreEqual("This is a ball.", answerBox.Text);
                    Assert.True(shomonState.Shomon.正解判定(answerBox.Text));
                }

                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<ShomonStateTyping>(window.State);
                    Assert.AreEqual("shomon3", ((ShomonStateTyping)window.State).Shomon.Id);
                    var shomonState = (ShomonStateBase)window.State;

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

                    // UserRequestが指定されているときは音声再生ボタンを表示する
                    Assert.True(window.State.GetAllItems().Where(x => "playSound" == x.Name).Any());

                    // This is a ball.
                    window.KeyPress('T');
                    window.KeyPress('h');
                    window.KeyPress('i');
                    window.KeyPress('s');
                    window.KeyPress(' ');
                    window.KeyPress('i');
                    window.KeyPress('s');
                    window.KeyPress(' ');
                    window.KeyPress(' ');
                    window.KeyPress('a');
                    window.KeyPress(' ');
                    window.KeyPress('b');
                    window.KeyPress('a');
                    window.KeyPress('l');
                    window.KeyPress('l');
                    window.KeyPress('.');
                }

                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();

                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<DaimonState>(window.State);
                Assert.AreEqual("Daimon 1", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon1", ((DaimonState)window.State).Daimon.Id);

                // 所要時間が正しく記録されているか。
                var mondaiResult = userInfo.MondaiResults.GetItems("chumon1").Single();
                Assert.AreEqual(t0, mondaiResult.StartTime);
                Assert.AreEqual(TimeSpan.FromSeconds(9.9d), mondaiResult.所要時間);
            }
        }
        public void カードを戻したらPERFECTにはならない_カードを全部戻した場合()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

            //				Assert.False(ShomonState.ShowStars);
            //				ShomonState.ShowStars = true;

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

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

                var shomonState0 = (ShomonState)window.State;
                var card = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                window.State.CurrentItem = card;
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(0.4d);
                window.State.Tick();
                window.State.Tick();

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

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                window.State.OnAction0();

                {
                    Assert.AreEqual(2, window.State.GetAllItems().OfType<Star>().Count());
                }

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

                {
                    var perfects = shomonState0.GetAllItems().OfType<Perfect>().ToArray();
                    Assert.AreEqual(0, perfects.Count());
                }
                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();
            }
        }
        public void GetMedalTest()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                var shomonStates = new List<ShomonState>();
                EPuzzleTime.Now = t0;

                userInfo.Difficulty = Difficulty.Hard;
                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();
                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                window.State.OnAction0();
                Assert.IsInstanceOf<ShomonState>(window.State);
                shomonStates.Add((ShomonState)window.State);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "a ball." == 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);
                shomonStates.Add((ShomonState)window.State);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "I" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "have" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "no" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "cousins" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && 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();

                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<DaimonState>(window.State);
                Assert.AreEqual("基礎II", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon2", ((DaimonState)window.State).Daimon.Id);

                CollectionAssert.AreEqual(new [] { true, true, }, shomonStates.Select(x => x.IsPerfect));
                Assert.AreEqual(1, userInfo.Medals.Count());
                Assert.AreEqual(Difficulty.Hard, userInfo.Medals.First().Difficulty);

                var mondaiResult = userInfo.MondaiResults.GetItems("2-1").Single();

                Assert.AreEqual(t0, mondaiResult.StartTime);
                Assert.AreEqual(TimeSpan.FromSeconds(2d), mondaiResult.所要時間);
            }
        }
        public void test0()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                userInfo.Difficulty = Difficulty.Hard;

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();
                Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
                window.State.OnAction0();
                Assert.IsInstanceOf<ShomonStateHard>(window.State);

                window.State.CurrentItem = null;
                window.InputDevice = InputDevice.Keyboard;

                var wordCard0 = (WordCard)window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                var wordCard1 = (WordCard)window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "a ball." == x.Text).First();

                Assert.AreEqual(LettersThatAreShown.Nothing, wordCard0.LettersThatAreShown);
                Assert.AreEqual(LettersThatAreShown.Nothing, wordCard1.LettersThatAreShown);

                window.InputDevice = InputDevice.Mouse;
                Assert.AreEqual(LettersThatAreShown.FirstCharacter, wordCard0.LettersThatAreShown);
                Assert.AreEqual(LettersThatAreShown.FirstCharacter, wordCard1.LettersThatAreShown);

                window.InputDevice = InputDevice.Keyboard;
                window.State.CurrentItem = wordCard0;
                Assert.AreEqual(LettersThatAreShown.All, wordCard0.LettersThatAreShown);
                Assert.AreEqual(LettersThatAreShown.Nothing, wordCard1.LettersThatAreShown);

                window.InputDevice = InputDevice.Mouse;
                Assert.AreEqual(LettersThatAreShown.All, wordCard0.LettersThatAreShown);
                Assert.AreEqual(LettersThatAreShown.FirstCharacter, wordCard1.LettersThatAreShown);

                window.InputDevice = InputDevice.Keyboard;
                window.State.OnAction0();

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

                Assert.Null(window.State.CurrentItem);

                var kaitouBox = (CardBox)TestUtility.GetValue((ShomonStateHard)window.State, "_kaitouBox");
                Assert.NotNull(kaitouBox);
                var wordCard0b = (WordCard)kaitouBox.GetAllItems().OfType<WordCard>().Where(x => !x.IsClickable && "This is" == x.Text).First();
                Assert.AreEqual(LettersThatAreShown.All, wordCard0b.LettersThatAreShown);

                var sentakuBox = (CardBox)TestUtility.GetValue((ShomonStateHard)window.State, "_sentakuBox");
                Assert.NotNull(sentakuBox);
                var wordCard0c = (WordCard)sentakuBox.GetAllItems().OfType<WordCard>().Where(x => !x.IsClickable && "This is" == x.Text).First();
                Assert.AreEqual(LettersThatAreShown.All, wordCard0c.LettersThatAreShown);

                window.State.CurrentItem = wordCard1;
                Assert.AreEqual(LettersThatAreShown.All, wordCard0.LettersThatAreShown);
                Assert.False(wordCard0.IsClickable);
                Assert.AreEqual(LettersThatAreShown.All, wordCard1.LettersThatAreShown);
                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<ShomonStateHard>(window.State);
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "I" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "have" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "no" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "cousins" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && 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();

                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<DaimonState>(window.State);
                Assert.AreEqual("基礎II", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon2", ((DaimonState)window.State).Daimon.Id);

                var mondaiResult = userInfo.MondaiResults.GetItems("2-1").Single();

                Assert.AreEqual(t0, mondaiResult.StartTime);
                Assert.AreEqual(TimeSpan.FromSeconds(3d), mondaiResult.所要時間);
            }
        }
        public void ShomonStateHardとの違いの確認()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon2");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                Assert.AreEqual(Difficulty.Normal, userInfo.Difficulty);

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("2-1", chumonButton.Chumon.Id);

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

                var wordCard0 = (WordCard)window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "This is" == x.Text).First();
                var wordCard1 = (WordCard)window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "a ball." == x.Text).First();

                Assert.AreEqual(LettersThatAreShown.All, wordCard0.LettersThatAreShown);
                Assert.AreEqual(LettersThatAreShown.All, wordCard1.LettersThatAreShown);

                window.State.CurrentItem = wordCard0;
                Assert.AreEqual(LettersThatAreShown.All, wordCard0.LettersThatAreShown);
                Assert.AreEqual(LettersThatAreShown.All, wordCard1.LettersThatAreShown);
                window.State.OnAction0();

            /*
                window.State.CurrentItem = wordCard1
                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.IsClickable && x is WordCard && "I" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "have" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "no" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "cousins" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && 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();

                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<DaimonState>(window.State);
                Assert.AreEqual("基礎II", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon2", ((DaimonState)window.State).Daimon.Id);

                var mondaiResult = userInfo.MondaiResults.GetItems("2-1").Single();

                Assert.AreEqual(t0, mondaiResult.StartTime);
                Assert.AreEqual(TimeSpan.FromSeconds(2d), mondaiResult.所要時間);
                */
            }
        }
        public void PlayingSoundsTest()
        {
            var mondaiXml =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <mondaiDocument version=""1.1"" id=""mondaiDocument1"">
            <title>Mondai Document 1</title>
            <description>Mondai Document 1の説明</description>
            <daimon id=""daimon1"">
            <title>Daimon 1</title>
            <description>Daimon 1の説明</description>
            <chumon id=""chumon_xxx"">
            <title>Chumon 1</title>
            <description>Chumon 1の説明</description>
            <optional />
            <shuffle />
            <shomon id=""shomon1"">
                <question>彼はその翌日そこに行くといいました。</question>
                <correctAnswer>He said that he would go there the next day.</correctAnswer>
                <correctAnswer>He said he would go there the next day.</correctAnswer>
                <description>英語は単語を空白で区切ります。</description>
                <inputMethod>card</inputMethod>
                <display>nothing</display>
                <soundFile when=""start"" numberOfTimes=""2"">sound1.wav</soundFile>
                <soundFile when=""start"" numberOfTimes=""2"">sound1.1.wav</soundFile>
                <soundFile when=""userRequest"" repeat=""true"">sound1.wav</soundFile>
                <soundFile when=""end"">sound2.wav</soundFile>
                <card>
                    <display>all</display>
                    <soundFile numberOfTimes=""2"">He said.wav</soundFile>
                    <text>He said</text>
                </card>
                <card>
                    <display>firstCharacterOnly</display>
                    <text>that</text>
                </card>
                <card>
                    <text>he would go there</text>
                </card>
                <card>
                    <rightJoint />
                    <text>i</text>
                </card>
                <card>
                    <rightJoint />
                    <leftJoint />
                    <text>ni</text>
                </card>
                <card>
                    <leftJoint />
                    <text>tial</text>
                </card>
                <card>
                    <text>the next day.</text>
                </card>
            </shomon>
            </chumon>
            </daimon>
            </mondaiDocument>";

            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", mondaiXml);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.AddFile("sound1.wav", "");
                test.AddFile("sound1.1.wav", "");
                test.AddFile("He said.wav", "");
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                userInfo.SoundPlayer = new TestSoundPlayer();
                userInfo.SoundPlayer.Directories.Add(test.GetFullPath(""));
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon1");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2014, 6, 13, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;

                userInfo.SoundPlayer.IsEnabled = true;
                Assert.IsInstanceOf<TestSoundPlayer>(userInfo.SoundPlayer);
                Assert.True(userInfo.SoundPlayer.IsEnabled);

                window.State = daimonState;

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("chumon_xxx", chumonButton.Chumon.Id);

                window.State.CurrentItem = chumonButton;
                window.State.OnAction0();

                ShomonState shomonState = (ShomonState)TestUtility.Get("nextShomonState");
                Assert.NotNull(shomonState);
                Assert.AreEqual("shomon1", shomonState.Shomon.Id);
                NeedToPlaySoundsEventArgs needToPlaySoundsEventArgs = null;
                shomonState.NeedToPlaySounds += (sender, e) =>
                {
                    needToPlaySoundsEventArgs = e;
                };
                Assert.Null(needToPlaySoundsEventArgs);

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

                // Shomon開始時に音声を再生する。
                Assert.NotNull(needToPlaySoundsEventArgs);
                Assert.AreEqual(2, needToPlaySoundsEventArgs.Sounds.Count());
                Assert.AreEqual("sound1.wav", needToPlaySoundsEventArgs.Sounds[0].FileName);
                Assert.AreEqual("sound1.1.wav", needToPlaySoundsEventArgs.Sounds[1].FileName);
                Assert.AreEqual(2, needToPlaySoundsEventArgs.Sounds[0].NumberOfTimes);

                // ユーザーリクエストで再生する。
                needToPlaySoundsEventArgs = null;
                window.State.OnAction4();
                Assert.NotNull(needToPlaySoundsEventArgs);
                Assert.AreEqual(1, needToPlaySoundsEventArgs.Sounds.Count());
                Assert.AreEqual("sound1.wav", needToPlaySoundsEventArgs.Sounds[0].FileName);
                Assert.True(needToPlaySoundsEventArgs.Sounds[0].IsRepeated);

                // UserRequestが指定されているときは音声再生ボタンを表示する
                Assert.True(window.State.GetAllItems().Where(x => "playSound" == x.Name).Any());

                // 音声再生ボタンで再生する。
                needToPlaySoundsEventArgs = null;
                var playSoundButton = window.State.GetAllItems().Where(x => "playSound" == x.Name).Single();
                window.State.CurrentItem = playSoundButton;
                window.State.OnAction0();
                Assert.NotNull(needToPlaySoundsEventArgs);
                Assert.AreEqual(1, needToPlaySoundsEventArgs.Sounds.Count());
                Assert.AreEqual("sound1.wav", needToPlaySoundsEventArgs.Sounds[0].FileName);
                Assert.True(needToPlaySoundsEventArgs.Sounds[0].IsRepeated);

                // カードに設定された音声を再生する。
                needToPlaySoundsEventArgs = null;
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "He said" == x.Text).First();
                window.State.OnAction0();
                Assert.NotNull(needToPlaySoundsEventArgs);
                Assert.AreEqual(1, needToPlaySoundsEventArgs.Sounds.Count());
                Assert.AreEqual("He said.wav", needToPlaySoundsEventArgs.Sounds[0].FileName);
                Assert.False(needToPlaySoundsEventArgs.Sounds[0].IsRepeated);
                Assert.AreEqual(2, needToPlaySoundsEventArgs.Sounds[0].NumberOfTimes);

                // 最初以外音声を再生しない。
                needToPlaySoundsEventArgs = null;
                window.State.OnAction3();
                Assert.IsInstanceOf<PauseState>(window.State);
                window.State.OnAction3();
                Assert.IsInstanceOf<ShomonState>(window.State);
                Assert.Null(needToPlaySoundsEventArgs);

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "that" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "he would go there" == x.Text).First();
                window.State.OnAction0();
                window.State.CurrentItem = window.State.GetAllItems().Where(x => x.IsClickable && x is WordCard && "the next day." == x.Text).First();
                window.State.OnAction0();
                EPuzzleTime.Now += TimeSpan.FromSeconds(1d);
                window.State.Tick();
                window.State.Tick();

                // ShomonState終了ごとに、再生キューをクリアする。
                Assert.AreEqual(0, ((TestSoundPlayer)userInfo.SoundPlayer).Queue.Count());

                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();

                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<DaimonState>(window.State);
                Assert.AreEqual("Daimon 1", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon1", ((DaimonState)window.State).Daimon.Id);
            }
        }
        public void 最後の問題を解いたあと次の画面に遷移しないオプションのテスト()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var daimon = (Daimon)mondaiDocument.GetItem("daimon5");
                var daimonState = new DaimonState(window, daimon);
                var t0 = new DateTime(2013, 3, 25, 0, 0, 0); // UTC
                EPuzzleTime.Now = t0;
                window.EPuzzleData.Settings.SetValue("最後の問題を解いたあと次の画面に遷移しない", true);

                window.State = daimonState;
                Assert.AreEqual("daimon5", daimonState.Daimon.Id);

                var chumonButton = (ChumonButton)window.State.GetAllItems().Where(x => x is ChumonButton).First();
                Assert.AreEqual("5-1", chumonButton.Chumon.Id);

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

                // 5-1-1

                window.State.CurrentItem = window.State.GetAllItems().Where(x => x is WordCard && "a" == 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();

                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<DaimonState>(window.State);
                Assert.AreEqual("daimon5", ((DaimonState)window.State).Daimon.Id);
            }
        }