public void Add_lettersThatAreDisplayedOnCard_elementToShomon()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\Mondai4.xml", TestResources._mondai04);
                test.Initialize();
                var window = test.Window;
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondai = window.EPuzzleData.MondaiDocuments[0];
                var daimon = (Daimon)mondai.Items.First();
                var chumon = (Chumon)daimon.Items.First();
                var shomon = (Shomon)chumon.Items.First();

                Assert.AreEqual(LettersThatAreDisplayedOnCard.All, shomon.LettersThatAreDisplayedOnCard);
                shomon = (Shomon)shomon.NextItem;
                Assert.AreEqual(LettersThatAreDisplayedOnCard.Default, shomon.LettersThatAreDisplayedOnCard);

                using (var tempFile = new TempFile())
                {
                    mondai.Save(tempFile.Name, "1.0");
                    FileAssert.AreEqual(test.GetFullPath(@"mondai\Mondai4.xml"), tempFile.Name);
                }
            }
        }
        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 AddPronunChumonsTest()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);
                test.Initialize();
                var window = test.Window;
                window.EPuzzleData.発音情報ファイルのパス = test.GetFullPath("PronunciationInfoContainer.xml");
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;

                ChumonCreator.AddPronChumonsTo(window.EPuzzleData.PronunciationInfoContainer, mondaiDocument);
                var newDocument = mondaiDocument;
                Assert.NotNull(newDocument);

            /*
            public const string PronunciationInfoContainerXml =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <pronunciationInfoContainer>
            <pronunciationInfo>
            <text>a</text>
            <onsetsu>@</onsetsu>
            <kigou>ət</kigou>
            </pronunciationInfo>
            <pronunciationInfo>
            <text>this</text>
            <onsetsu>this</onsetsu>
            <kigou>ðís</kigou>
            </pronunciationInfo>
            <pronunciationInfo>
            <text>notebook</text>
            <onsetsu>note・book</onsetsu>
            <kigou>nóʊtb`ʊk</kigou>
            <kigou>nˈəʊt‐</kigou>
            </pronunciationInfo>
            <pronunciationInfo>
            <text>ball</text>
            <onsetsu>ball</onsetsu>
            <kigou>bˈɔːl</kigou>
            </pronunciationInfo>
            </pronunciationInfoContainer>";

            */

                {
                    var daimon = newDocument.GetItem("daimon1");
                    Assert.NotNull(daimon);

                    Assert.AreEqual(3, daimon.Items.Count());
                    int i = 0;
                    {
                        var chumon = (Chumon)daimon.Items[i++];
                        Assert.AreEqual("d1_chumon1", chumon.Id);
                    }
                    {
                        var chumon = (Chumon)daimon.Items[i++];
                        Assert.AreEqual("~pron~d1_chumon1", chumon.Id);
                    }
                    {
                        var chumon = (Chumon)daimon.Items[i++];
                        Assert.AreEqual("d1_chumon2", chumon.Id);
                    }
                }
                {
                    var daimon = newDocument.GetItem("daimon3");
                    Assert.NotNull(daimon);

                    Assert.AreEqual(2, daimon.Items.Count());
                    int i = 0;
                    {
                        var chumon = (Chumon)daimon.Items[i++];
                        Assert.AreEqual("3-1", chumon.Id);
                    }
                    {
                        var chumon = (Chumon)daimon.Items[i++];
                        Assert.AreEqual("3-2", chumon.Id);
                    }
                }
                {
                    var daimon = newDocument.GetItem("daimon1");
                    Assert.NotNull(daimon);

                    var chumon = (Chumon)daimon.Items[0];

                    Assert.Null(chumon.PreviousItem);
                    Assert.AreEqual("d1_chumon1", chumon.Id);
                    Assert.AreEqual("~pron~d1_chumon1", chumon.NextItem.Id);
                    Assert.AreSame(daimon, chumon.Parent);
                    Assert.AreNotEqual(TimeSpan.Zero, chumon.GetTimeLimit(userInfo));

                    chumon = (Chumon)chumon.NextItem;
                    Assert.AreEqual("d1_chumon1", chumon.PreviousItem.Id);
                    Assert.AreEqual("~pron~d1_chumon1", chumon.Id);
                    Assert.AreEqual("d1_chumon2", chumon.NextItem.Id);
                    Assert.AreSame(daimon, chumon.Parent);
                    Assert.True(chumon.IsOptional);
                    Assert.AreNotEqual(TimeSpan.Zero, chumon.GetTimeLimit(userInfo));

                    chumon = (Chumon)chumon.NextItem;
                    Assert.AreEqual("~pron~d1_chumon1", chumon.PreviousItem.Id);
                    Assert.AreEqual("d1_chumon2", chumon.Id);
                    Assert.Null(chumon.NextItem);
                    Assert.AreSame(daimon, chumon.Parent);
                    Assert.AreNotEqual(TimeSpan.Zero, chumon.GetTimeLimit(userInfo));
                }
            }
        }
        public void 発音問題が作れない場合はnullを返す()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);
                test.Initialize();
                var window = test.Window;
                window.EPuzzleData.発音情報ファイルのパス = test.GetFullPath("PronunciationInfoContainer.xml");
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                Assert.NotNull(window.EPuzzleData.PronunciationInfoContainer);
                var chumonCreator = new ChumonCreator(window.EPuzzleData.PronunciationInfoContainer);

                Assert.Null(chumonCreator.GetPronunciationChumon((Chumon)mondaiDocument.GetItem("7-2")));

                var chumon = chumonCreator.GetPronunciationChumon((Chumon)mondaiDocument.GetItem("7-1"));
                Assert.NotNull(chumon);

                // ShomonのParentプロパティを設定する

                Assert.AreEqual(3, chumon.Items.Count());
                Assert.AreSame(chumon, chumon.Items[0].Parent);
                Assert.AreSame(chumon, chumon.Items[1].Parent);
                Assert.AreSame(chumon, chumon.Items[2].Parent);

                // 前後のShomonを設定する

                Assert.AreSame(null, chumon.Items[0].PreviousItem);
                Assert.AreSame(chumon.Items[1], chumon.Items[0].NextItem);

                Assert.AreSame(chumon.Items[0], chumon.Items[1].PreviousItem);
                Assert.AreSame(chumon.Items[2], chumon.Items[1].NextItem);

                Assert.AreSame(chumon.Items[1], chumon.Items[2].PreviousItem);
                Assert.AreSame(null, chumon.Items[2].NextItem);

                // ChumonのParentプロパティを設定する

                Assert.AreSame(((Chumon)mondaiDocument.GetItem("7-1")).Parent, chumon.Parent);
            }
        }
        public void GetPronunciationShomonsTest()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);
                test.Initialize();
                var window = test.Window;
                window.EPuzzleData.発音情報ファイルのパス = test.GetFullPath("PronunciationInfoContainer.xml");
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var chumon = (Chumon)mondaiDocument.GetItem("chumon1");
                var shomon = (Shomon)chumon.Items.First();

                // userInfo.MondaiResults.Add(new MondaiResult(chumon.Id, t0, TimeSpan.FromSeconds(11d)));

                Assert.NotNull(window.EPuzzleData.PronunciationInfoContainer);

            //				var chumonCreator = new ChumonCreator();
                var shomons = ChumonCreator.GetPronunciationShomons(window.EPuzzleData.PronunciationInfoContainer, shomon).ToArray();
                Assert.NotNull(shomons);
            /*
            <shomon id=""1-1-1"">
                <mondaibun>[英訳] これはノートです。</mondaibun>
                <seikai>This is a notebook.</seikai>
                <word>This</word>
                <word>is</word>
                <word>a notebook</word>
                <word>.</word>
            </shomon>

            <pronunciationInfo>
            <text>notebook</text>
            <onsetsu>note・book</onsetsu>
            <kigou>nóʊtb`ʊk</kigou>
            <kigou>nˈəʊt‐</kigou>
            </pronunciationInfo>

            */
            /*				foreach (var s in shomons)
                {
                    Console.WriteLine(s.Mondaibun);
                }*/
                Assert.AreEqual(3, shomons.Count());
                {
                    var s = shomons[0];
                    Assert.AreEqual("~pron~0~1-1-1", s.Id);
                    Assert.AreEqual("this", s.Mondaibun);
                    CollectionAssert.AreEqual
                    (
                        new []
                        {
                            "ðís",
                        },
                        s.CorrectAnswers.Select(x => x.Text)
                    );
                    CollectionAssert.AreEqual
                    (
                        new []
                        {
                            new MondaiWord("ð", false, true),
                            new MondaiWord("í", true, true),
                            new MondaiWord("s", true, false),
                        },
                        s.MondaiWords
                    );
                }
                {
                    var s = shomons[2];
                    Assert.AreEqual("~pron~2~1-1-1", s.Id);
                    Assert.AreEqual("notebook", s.Mondaibun);
                    CollectionAssert.AreEqual
                    (
                        new []
                        {
                            "nóʊtb`ʊk",
                            "nˈəʊt‐",
                        },
                        s.CorrectAnswers.Select(x => x.Text)
                    );
                    CollectionAssert.AreEquivalent
                    (
                        new []
                        {
                            new MondaiWord("n", false, true),
                            new MondaiWord("ó", true, true),
                            new MondaiWord("ʊ", true, true),
                            new MondaiWord("t", true, true),
                            new MondaiWord("b", true, true),
                            new MondaiWord("`", true, true),
                            new MondaiWord("ʊ", true, true),
                            new MondaiWord("k", true, false),

            //							new MondaiWord("n", false, true), // 重複要素
                            new MondaiWord("ˈ", true, true),
                            new MondaiWord("ə", true, true),
            //							new MondaiWord("ʊ", true, true), // 重複要素
            //							new MondaiWord("t", true, true), // 重複要素
                            new MondaiWord("‐", true, false),
                        },
                        s.MondaiWords
                    );
                }

            }
        }
        public void GetPronunciationChumonTest()
        {
            using (var test = new EPuzzleTestManager())
            {
                test.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                test.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
                test.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);
                test.Initialize();
                var window = test.Window;
                window.EPuzzleData.発音情報ファイルのパス = test.GetFullPath("PronunciationInfoContainer.xml");
                var userInfo = window.EPuzzleData.CurrentUserInfo;
                var mondaiDocument = window.EPuzzleData.CurrentMondaiDocument;
                var chumon = (Chumon)mondaiDocument.GetItem("chumon1");

                Assert.AreEqual(2, chumon.Items.Count());

                // userInfo.MondaiResults.Add(new MondaiResult(chumon.Id, t0, TimeSpan.FromSeconds(11d)));

                Assert.NotNull(window.EPuzzleData.PronunciationInfoContainer);

            //				var chumonCreator = new ChumonCreator();
                var result = ChumonCreator.GetPronunciationChumon(window.EPuzzleData.PronunciationInfoContainer, chumon);
                Assert.NotNull(result);

                Assert.AreEqual("This is a pen. - 発音", result.Name);
                Assert.AreEqual("~pron~chumon1", result.Id);
            //				Assert.AreEqual(4, result.Items.Count());

                CollectionAssert.AreEquivalent
                (
                    new [] { "this", "a", "notebook", "ball", },
                    result.Items.Cast<Shomon>().Select(x => x.Mondaibun)
                );
            }
        }