public void CreateFromImageFilesTest()
 {
     using (var tempDirectory = new TempDirectory(true))
     {
         tempDirectory.AddFile("help0.png", "");
         tempDirectory.AddFile("help1.png", "");
         var helpDocument = HelpDocument.CreateFromImageFiles(new [] { tempDirectory.FullPath("help0.png"), tempDirectory.FullPath("help1.png"), });
         CollectionAssert.AreEqual(new [] { "help0", "help1" }, helpDocument.Items.Select(item => item.Id));
         CollectionAssert.AreEqual(new [] { "help0.png", "help1.png" }, helpDocument.Items.Select(item => item.ImageFile));
     }
 }
        public void Test0()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                EPuzzlePronuncer.Instance.DirectoryName = tempDirectory.Name;
                Assert.Null(EPuzzlePronuncer.Instance.FindSoundFile("pronunce"));

                tempDirectory.AddFile("pronunce.wav", "");
                Assert.AreEqual(tempDirectory.GetFullPath("pronunce.wav"), EPuzzlePronuncer.Instance.FindSoundFile("pronunce"));
                Assert.AreEqual(tempDirectory.GetFullPath("Pronunce.wav"), EPuzzlePronuncer.Instance.FindSoundFile("Pronunce"));
            }
        }
 public void Test1()
 {
     var player = new EPuzzleSoundPlayer();
     using (var tempDir = new TempDirectory(true))
     using (var tempDir2 = new TempDirectory(true))
     {
         tempDir2.AddFile("test.wav", "");
         player.Directories.Add(tempDir.Name);
         player.Directories.Add(tempDir2.Name);
         Assert.AreEqual(tempDir2.FullPath("test.wav"), TestUtility.Inv(player, "FindFile", "test.wav"));
         Assert.Null(TestUtility.Inv(player, "FindFile", "test_xxxx.wav"));
     }
 }
        public void 並び順テスト()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                var manager = new ResultImageManager();

                tempDirectory.AddFile(@"A\file0.png", "");
                tempDirectory.AddFile(@"A\file1.png", "");
                tempDirectory.AddFile(@"A\file2.png", "");
                var now = new DateTime(2013, 7, 11, 0, 0, 0); // UTC
                EPuzzleTime.Now = now;

                var file0 = tempDirectory.GetFullPath(@"A\file0.png");
                var file1 = tempDirectory.GetFullPath(@"A\file1.png");
                var file2 = tempDirectory.GetFullPath(@"A\file2.png");

                Assert.False(manager.最後に表示してからもっとも時間が経過しているファイルから表示する);
                manager.DirectoryName = tempDirectory.Name;
                manager.最後に表示してからもっとも時間が経過しているファイルから表示する = true;
                Assert.True(manager.最後に表示してからもっとも時間が経過しているファイルから表示する);

                manager.UpdateAccessTime(file1, now + TimeSpan.FromSeconds(1d));
                manager.UpdateAccessTime(file0, now + TimeSpan.FromSeconds(2d));
                manager.UpdateAccessTime(file2, now + TimeSpan.FromSeconds(3d));

                Assert.AreEqual(file1, manager.GetFile("A"));
                Assert.AreEqual(file0, manager.GetFile("A"));
                Assert.AreEqual(file2, manager.GetFile("A"));

                Assert.AreEqual(file1, manager.GetFile("A"));
                Assert.AreEqual(file0, manager.GetFile("A"));
                Assert.AreEqual(file2, manager.GetFile("A"));

                EPuzzleTime.Now = now + TimeSpan.FromMinutes(1d);

                manager.UpdateAccessTime(file1);

                Assert.AreEqual(file0, manager.GetFile("A"));
                Assert.AreEqual(file2, manager.GetFile("A"));
                Assert.AreEqual(file1, manager.GetFile("A"));

                Assert.AreEqual(file0, manager.GetFile("A"));
                Assert.AreEqual(file2, manager.GetFile("A"));
                Assert.AreEqual(file1, manager.GetFile("A"));

                using (var tempFile = new TempFile())
                {
                    manager.ImageInfoContainerFileName = tempFile.Name;
                    manager.Save();

                    var manager2 = new ResultImageManager();
                    manager2.最後に表示してからもっとも時間が経過しているファイルから表示する = true;
                    manager2.DirectoryName = tempDirectory.Name;
                    manager2.ImageInfoContainerFileName = tempFile.Name;
                    manager2.Load();

                    Assert.AreEqual(file0, manager2.GetFile("A"));
                    Assert.AreEqual(file2, manager2.GetFile("A"));
                    Assert.AreEqual(file1, manager2.GetFile("A"));
                }
                using (var tempFile = new TempFile())
                {
                    // 消したファイルの情報は保存しない

                    manager.ImageInfoContainerFileName = tempFile.Name;
                    tempDirectory.DeleteFile(@"A\file1.png");
                    tempDirectory.DeleteFile(@"A\file2.png");

                    manager.Save();

                    var manager2 = new ResultImageManager();
                    manager2.最後に表示してからもっとも時間が経過しているファイルから表示する = true;
                    manager2.DirectoryName = tempDirectory.Name;
                    manager2.ImageInfoContainerFileName = tempFile.Name;
                    manager2.Load();

                    var imageInfoContainer = (ImageInfoContainer)TestUtility.GetValue(manager2, "_imageInfoContainer");
                    Assert.NotNull(imageInfoContainer);
                    Assert.AreEqual(1, imageInfoContainer.ImageInfos.Count());
                    CollectionAssert.AreEqual(new [] { file0, }, imageInfoContainer.ImageInfos.Keys);
                }

                // UpdateAccessTimeにnullなどを渡した場合

                Assert.Throws<ArgumentNullException>(() =>
                {
                    manager.UpdateAccessTime(null);
                });
                Assert.Throws<ArgumentException>(() =>
                {
                    manager.UpdateAccessTime(" ");
                });
                Assert.Throws<ArgumentException>(() =>
                {
                    manager.UpdateAccessTime("");
                });
            }
        }
        public void PrepareForImagesTest()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                var manager = new ResultImageManager();
                manager.DirectoryName = tempDirectory.Name;

                // ファイルがない場合
                manager.PrepareForImages();
                {
                    Assert.Null(manager.GetImage("A"));
                    Assert.Null(manager.GetImage("A"));
                }

                // ファイルがある場合
                tempDirectory.AddFile(@"A\a.bmp", new Bitmap(10, 10));
                tempDirectory.AddFile(@"B\b.bmp", new Bitmap(11, 10));
                tempDirectory.AddFile(@"cdef.bmp", new Bitmap(12, 10));

                Assert.True(File.Exists(tempDirectory.FullPath(@"A\a.bmp")));
                Assert.True(File.Exists(tempDirectory.FullPath(@"B\b.bmp")));
                Assert.True(File.Exists(tempDirectory.FullPath(@"cdef.bmp")));

                Assert.Null(manager.PeekCache_TESTONLY("A"));
                Assert.Null(manager.PeekCache_TESTONLY("B"));
                Assert.Null(manager.PeekCache_TESTONLY("C"));

                {
                    manager.PrepareForImages();
            //					var task = manager.GetTask_TESTONLY();
            //					task.Wait();
                }

                var imageA0 = manager.PeekCache_TESTONLY("A");
                Assert.AreEqual(10, imageA0.Width);
                Assert.AreEqual(11, manager.PeekCache_TESTONLY("B").Width);
                Assert.AreEqual(12, manager.PeekCache_TESTONLY("C").Width);
                Assert.AreEqual(12, manager.PeekCache_TESTONLY("D").Width);
                Assert.AreEqual(12, manager.PeekCache_TESTONLY("F").Width);

                var imageA1 = manager.GetImage("A");
                Assert.AreSame(imageA0, imageA1);
                Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), imageA0.Tag);

                Assert.Null(manager.PeekCache_TESTONLY("A"));

                {
                    manager.PrepareForImages();
            //					var task = manager.GetTask_TESTONLY();
            //					task.Wait();
                }

                Assert.AreEqual(10, manager.PeekCache_TESTONLY("A").Width);

                {
                    var image0 = manager.GetImage("A");
                    var image1 = manager.GetImage("A");
                    Assert.AreNotSame(image0, image1);
                    Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), image0.Tag);
                    Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), image1.Tag);
                }
            }
        }
        public void Test1()
        {
            WindowState.NowObject = new TestNowObject();
            WindowState.NowObject.Now = DateTime.MinValue;

            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"mondai\MondaiDocument2.xml", TestResources.Mondai03);

                {
                    var data56 = EPuzzleData.Create(tempDirectory.Name);
                    data56.Save();
                }

                var data = EPuzzleData.Create(tempDirectory.Name);
                var userInfo = data.CurrentUserInfo;
                var window = new EPuzzleWindow(data);

                Assert.AreEqual("DocumentA", data.MondaiDocuments[0].Name);
                Assert.AreEqual("DocumentB", data.MondaiDocuments[1].Name);

                var mondaiDocumentMenuState = new MondaiDocumentMenuState(window, data.MondaiDocuments);
                window.State = mondaiDocumentMenuState;

                {
                    var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
                    Assert.AreEqual(2, buttons.Count());

                    Assert.AreEqual("DocumentA", buttons[0].Text);
                    Assert.AreSame(data.MondaiDocuments[0], buttons[0].Tag);

                    Assert.AreEqual("DocumentB", buttons[1].Text);
                    Assert.AreSame(data.MondaiDocuments[1], buttons[1].Tag);
                }

                var daimonA1 = (Daimon)data.MondaiDocuments[0].Items[1];
                var daimonB1 = (Daimon)data.MondaiDocuments[1].Items[1];

                Assert.AreEqual("daimon2", daimonA1.Id);
                Assert.AreSame(data.MondaiDocuments[0], daimonA1.Parent);
                Assert.AreEqual("daimon2", daimonB1.Id);
                Assert.AreSame(data.MondaiDocuments[1], daimonB1.Parent);

                userInfo.SetLastDaimonInfo(daimonA1);
                userInfo.SetLastDaimonInfo(daimonB1);

                // button[0]
                {
                    var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
                    window.State.CurrentItem = buttons[0];
                    window.State.OnAction0();

                    Assert.AreSame(data.MondaiDocuments[0], window.EPuzzleData.CurrentMondaiDocument);

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

                    Assert.IsInstanceOf<DaimonState>(window.State);
                    Assert.AreSame(daimonA1, ((DaimonState)window.State).Daimon);
                }

                // button[1]
                {
                    window.State = mondaiDocumentMenuState;
                    var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();

                    window.State.CurrentItem = buttons[1];
                    window.State.OnAction0();

                    Assert.AreSame(data.MondaiDocuments[1], window.EPuzzleData.CurrentMondaiDocument);

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

                    Assert.IsInstanceOf<DaimonState>(window.State);
                    Assert.AreSame(daimonB1, ((DaimonState)window.State).Daimon);
                }

                // マウスクリックで遷移テスト
                {
                    window.State = mondaiDocumentMenuState;
                    var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
                    var button = buttons[0];
                    Assert.IsInstanceOf<MondaiDocumentMenuState>(window.State);
                    window.State.CurrentItem = button;
                    Assert.True(window.State.CurrentItem.Contains(button.BorderLeft, button.BorderTop));
                    window.MouseUp(button.BorderLeft, button.BorderTop, MouseButtons.Left);

                    Assert.AreSame(data.MondaiDocuments[0], window.EPuzzleData.CurrentMondaiDocument);
                    Assert.IsInstanceOf<FadeoutState>(window.State);
                }
            }
        }
        public void ファイルが消されていた場合の処理()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                var manager = new ResultImageManager();

                tempDirectory.AddFile(@"A\a0.bmp", new Bitmap(10, 10));
                tempDirectory.AddFile(@"A\a1.bmp", new Bitmap(11, 10));
                tempDirectory.AddFile(@"A\a2.bmp", new Bitmap(12, 10));

                manager.DirectoryName = tempDirectory.Name;
                {
                    manager.PrepareForImages();
            //					var task = manager.GetTask_TESTONLY();
            //					task.Wait();
                }

                tempDirectory.DeleteFile(@"A\a0.bmp");
                tempDirectory.DeleteFile(@"A\a1.bmp");
                tempDirectory.DeleteFile(@"A\a2.bmp");

                {
                    manager.PrepareForImages();
            //					var task = manager.GetTask_TESTONLY();
            //					task.Wait();
                }
                Assert.NotNull(manager.GetImage("A"));
                Assert.Null(manager.GetImage("A"));
            }
        }
        public void GetImageTest()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                var manager = new ResultImageManager2();
                manager.DirectoryName = tempDirectory.Name;

                tempDirectory.AddFile(@"A\a0.bmp", new Bitmap(10, 10));

                {
                    var image = manager.GetImage("A");
                    Assert.NotNull(image);
                    Assert.AreEqual(tempDirectory.FullPath(@"A\a0.bmp"), image.Tag);
                }

                tempDirectory.AddFile(@"A\a1.bmp", new Bitmap(11, 10));
                tempDirectory.AddFile(@"A\a2.bmp", new Bitmap(12, 10));

                manager.PrepareForImages();
                CollectionAssert.AreEquivalent(new []
                {
                    tempDirectory.FullPath(@"A\a0.bmp"),
                    tempDirectory.FullPath(@"A\a1.bmp"),
                    tempDirectory.FullPath(@"A\a2.bmp"),
                }, manager.Files);

                manager.PrepareForImages();
                tempDirectory.DeleteFile(@"A\a0.bmp");
                CollectionAssert.AreEquivalent(new []
                {
                    tempDirectory.FullPath(@"A\a1.bmp"),
                    tempDirectory.FullPath(@"A\a2.bmp"),
                }, new [] { manager.GetImage("A").Tag, manager.GetImage("A").Tag, }.Cast<string>());

                manager.PrepareForImages();
                tempDirectory.DeleteFile(@"A\a1.bmp");
                CollectionAssert.AreEquivalent(new []
                {
                    tempDirectory.FullPath(@"A\a2.bmp"),
                    tempDirectory.FullPath(@"A\a2.bmp"),
                }, new [] { manager.GetImage("A").Tag, manager.GetImage("A").Tag, }.Cast<string>());

                manager.PrepareForImages();
                tempDirectory.DeleteFile(@"A\a2.bmp");
                Assert.Null(manager.GetImage("A"));
                Assert.Null(manager.GetImage("A"));
            }
        }
        public void ファイルを暗号化してディレクトリをバックアップする([Values(true, false)] bool verify)
        {
            using (var dir1 = new TempDirectory(true))
            using (var dir2 = new TempDirectory(true))
            {
                var password = "******";
                var backup = new EncryptionDirectoryBackup(dir1.Name, dir2.Name, password, verify);

                var file1 = "a.txt";
                var file2 = "b.txt";
                var text = "abc";

                {
                    var a = dir1.FullPath(file1);
                    var b = dir2.FullPath(file1);
                    FileUtility.Save(a, text);
                    Assert.AreEqual(text, FileUtility.Load(a));

                    TestUtility.Inv(backup, "Copy", a, b);
                    Assert.True(File.Exists(b));

                    Assert.AreEqual(File.GetLastWriteTime(a), File.GetLastWriteTime(b));
                    FileAssert.AreNotEqual(a, b);

                    var tt = FileUtility.Load(b, StreamOptions.Encryption3, password);
                    Assert.AreEqual(FileUtility.Load(a), tt);
                    Assert.AreEqual(text, tt);

                    FileUtility.Load(b, sb =>
                    {
                        using (var sr = new StreamReader(sb))
                        {
                            Assert.AreEqual(text, sr.ReadToEnd());
                        }
                    }, StreamOptions.Encryption3, password);

                    TestUtility.Inv(backup, "Verify", a, b);
                }
                {
                    var a = dir1.FullPath(file1);
                    var b = dir2.FullPath(file2);
                    FileUtility.Save(b, text);
                    FileAssert.AreEqual(a, b);
                    Assert.Throws<System.Security.Cryptography.CryptographicException>(() =>
                    {
                        TestUtility.Inv(backup, "Verify", a, b);
                    });
                }
                {
                    var a = dir1.FullPath(file1);
                    var b = dir2.FullPath(file2);
                    FileUtility.Save(a, "abc");
                    FileUtility.Save(b, "abd", StreamOptions.Encryption3, password);
                    FileAssert.AreNotEqual(a, b);
                    Assert.Throws<ApplicationException>(() =>
                    {
                        TestUtility.Inv(backup, "Verify", a, b);
                    });
                }
                {
                    var a = dir1.FullPath("c.txt");
                    var b = dir2.FullPath("d.txt");
                    var c = dir2.FullPath("e.txt");
                    var t1 = new DateTime(2014, 3, 1, 0, 0, 0); // UTC
                    var t2 = new DateTime(2013, 3, 1, 0, 0, 0); // UTC

                    FileUtility.Save(a, "abc");
                    FileUtility.Save(b, "defg");
                    FileUtility.Save(c, "hijkl");

                    File.SetLastWriteTime(a, t1);
                    File.SetLastWriteTime(b, t1);
                    File.SetLastWriteTime(c, t2);

                    Assert.False(TestUtility.Inv(backup, "AreDifferent", a, b));
                    Assert.True(TestUtility.Inv(backup, "AreDifferent", a, c));
                }
            }

            using (var dirA = new TempDirectory(true))
            using (var dirB = new TempDirectory(true))
            {
                var fileName = "a.txt";
                var text = "abc";
                var password = "******";
                dirA.AddFile(fileName, text);

                var a = dirA.FullPath(fileName);
                var b = dirB.FullPath(fileName);

                var backup = new EncryptionDirectoryBackup(dirA.Name, dirB.Name, password, verify);
                backup.Start();

                Assert.True(File.Exists(b));
                TestUtility.Inv(backup, "Verify", a, b);

                Assert.AreEqual(FileUtility.Load(a), FileUtility.Load(b, StreamOptions.Encryption3, password));
            }
        }
        public void Chumon遷移テスト()
        {
            EPuzzleWindow window = null;
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                // 問題メニューに戻る
                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);
            }
        }
        public void 新しいグレード指定フォーマット()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                {
                    var manager = new ResultImageManager2();
                    manager.DirectoryName = tempDirectory.Name;

                    tempDirectory.AddFile(@"A\file0.png", "");
                    tempDirectory.AddFile(@"x[A]x[B]x\file0.bmp", "");
                    tempDirectory.AddFile(@"x[AB]x\file2.bmp", "");

                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),

                    }, new []
                    {
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                    });

                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
                        tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),

                    }, new []
                    {
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                    });
                }
            }
        }
        public void EPuzzleData2_問題ファイル以外何も用意しない場合のテスト()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                {
                    tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                    tempDirectory.AddFile(@"mondai\MondaiDocument2.xml", TestResources.Mondai03);
                    tempDirectory.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    EPuzzleTime.NowObject = new TestNowObject();

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

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

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

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

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

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

                    Assert.AreEqual(TimeSpan.FromHours(6d), data2.家庭教師モードにてこの時間以内の問題は無視する);
                }
            }
        }
        public void D評価なら次のDaimonに遷移しない()
        {
            EPuzzleWindow window = null;
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Assert.IsInstanceOf<DaimonState>(window.State);
                Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);
                Assert.AreEqual("daimon1", ((DaimonState)window.State).Daimon.Id);
            }
        }
 public void 同じ問題で同じ時間のとき例外が発生する不具合()
 {
     using (var tempDirectory = new TempDirectory(true))
     {
         tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
         var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
         WindowState.NowObject = new TestNowObject();
         WindowState.NowObject.Now = DateTime.MinValue;
         var window = new EPuzzleWindow(ePuzzleData);
         var userInfo = ePuzzleData.CurrentUserInfo;
         userInfo.MondaiResults.AddNew("d1_chumon1", DateTime.MinValue, TimeSpan.FromSeconds(1d));
         userInfo.MondaiResults.AddNew("d1_chumon1", DateTime.MinValue, TimeSpan.FromSeconds(1d));
     }
 }
        public void 合格判定テスト()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
                WindowState.NowObject = new TestNowObject();
                WindowState.NowObject.Now = DateTime.MinValue;
                var window = new EPuzzleWindow(ePuzzleData);
                var userInfo = ePuzzleData.CurrentUserInfo;
                userInfo.GradeProcessor = GradeProcessorA.Instance;

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

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

                userInfo.MondaiResults.AddNew(chumon0.Id, DateTime.MinValue, TimeSpan.FromSeconds(1d));
                Assert.True(chumon0.合格判定(userInfo));
            }
        }
        public void GetRankTest()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
                var userInfo = ePuzzleData.CurrentUserInfo;
                var daimon2 = ePuzzleData.CurrentMondaiDocument.Items[1];

                Assert.Throws<ArgumentNullException>(() =>
                {
                    daimon2.Items[0].GetGradeString(null);
                });

                Assert.AreEqual("-", daimon2.Items[0].GetGradeString(userInfo));
            }
        }
        public void ResultImageManagerCoreATest()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                {
                    var manager = new ResultImageManagerCoreA(tempDirectory.Name);

                    tempDirectory.AddFile(@"A\file0.png", "");
                    tempDirectory.AddFile(@"x[A]x[B]x\file0.bmp", "");
                    tempDirectory.AddFile(@"x[AB]x\file2.bmp", "");

                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath("A"),
                        tempDirectory.GetFullPath("x[A]x[B]x"),

                    }, manager.GetDirectories("A"));

                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
                    }, manager.GetNamesOfImageFilesFromDirectories("A"));

                    Assert.AreEqual("A", manager.GetDirectoryName(tempDirectory.GetFullPath(@"A\file0.png")));
                    Assert.AreEqual("", manager.GetDirectoryName(tempDirectory.GetFullPath(@"file0.png")));

                    tempDirectory.AddFile(@"c\file4.png", "");
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"c\file4.png"),
                    }, manager.GetNamesOfImageFilesFromDirectories("C"));
                }
            }
        }
        public void 状態遷移テスト正常ケース()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Assert.IsInstanceOf<StartGameState>(window.State);
            }
        }
        public void Test1()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                {
                    var manager = new ResultImageManager2();
                    manager.DirectoryName = tempDirectory.Name;

                    tempDirectory.AddFile(@"A\file0.png", "");
                    tempDirectory.AddFile(@"B\file0.bmp", "");
                    tempDirectory.AddFile(@"D\file0.txt", "");
                    manager.PrepareForImages();
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"B\file0.bmp"),

                    }, manager.Files);

                    Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"B\file0.bmp"),

                    }, manager.Files);

                    Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));

                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("D"));
                    Assert.Null(manager.GetFile("D"));
                    Assert.Null(manager.GetFile("D"));

                    tempDirectory.AddFile(@"file3.jpg", "");
            /*					Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
                    Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
                    */
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("C"));
                    Assert.Null(manager.GetFile("D"));
                    Assert.Null(manager.GetFile("D"));
                }
                {
                    var manager = new ResultImageManager2();
                    manager.DirectoryName = tempDirectory.Name;

                    tempDirectory.AddFile(@"A\file1.png", "");
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"A\file1.png"),
                        tempDirectory.GetFullPath(@"A\file1.png"),

                    }, new []
                    {
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                    });
                }
            }
        }
        public void AnkimonStateへの遷移()
        {
            EPuzzleWindow window = null;
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
                tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Assert.IsInstanceOf<AnkimonState>(window.State);
            }
        }
        public void 正しい挙動()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddFile(@"A\file0.png", "");
                tempDirectory.AddFile(@"A\file1.png", "");
                tempDirectory.AddFile(@"A\file2.png", "");
                tempDirectory.AddFile(@"B,C,D\file3.png", "");
                tempDirectory.AddFile(@"B,C,D\file4.png", "");
                tempDirectory.AddFile(@"B,C,D\file5.png", "");
                tempDirectory.AddFile(@"C,D\file6.png", "");
                tempDirectory.AddFile(@"C,D\file7.png", "");
                tempDirectory.AddFile(@"C,D\file8.png", "");

                {
                    var manager = new ResultImageManager2(tempDirectory.Name);
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"A\file1.png"),
                        tempDirectory.GetFullPath(@"A\file2.png"),
                        tempDirectory.GetFullPath(@"A\file0.png"),
                        tempDirectory.GetFullPath(@"A\file1.png"),
                        tempDirectory.GetFullPath(@"A\file2.png"),

                    }, new []
                    {
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                        manager.GetFile("A"),
                    });
                }
                {
                    var manager = new ResultImageManager2(tempDirectory.Name);
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                    }, new []
                    {
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                    });
                }
                {
                    var manager = new ResultImageManager2(tempDirectory.Name);
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"C,D\file6.png"),
                        tempDirectory.GetFullPath(@"C,D\file7.png"),
                        tempDirectory.GetFullPath(@"C,D\file8.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"C,D\file6.png"),
                        tempDirectory.GetFullPath(@"C,D\file7.png"),
                        tempDirectory.GetFullPath(@"C,D\file8.png"),
                    }, new []
                    {
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                    });
                }
                {
                    var manager = new ResultImageManager2(tempDirectory.Name);
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"C,D\file6.png"),
                        tempDirectory.GetFullPath(@"C,D\file7.png"),
                        tempDirectory.GetFullPath(@"C,D\file8.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"C,D\file6.png"),
                        tempDirectory.GetFullPath(@"C,D\file7.png"),
                        tempDirectory.GetFullPath(@"C,D\file8.png"),
                    }, new []
                    {
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                    });
                }
                {
                    var manager = new ResultImageManager2(tempDirectory.Name);
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"C,D\file6.png"),
                        tempDirectory.GetFullPath(@"C,D\file7.png"),
                        tempDirectory.GetFullPath(@"C,D\file8.png"),
                    }, new []
                    {
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                    });
                }
                {
                    var manager = new ResultImageManager2(tempDirectory.Name);
                    CollectionAssert.AreEquivalent(new []
                    {
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file3.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file4.png"),
                        tempDirectory.GetFullPath(@"B,C,D\file5.png"),
                        tempDirectory.GetFullPath(@"C,D\file6.png"),
                        tempDirectory.GetFullPath(@"C,D\file7.png"),
                        tempDirectory.GetFullPath(@"C,D\file8.png"),
                    }, new []
                    {
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("B"),
                        manager.GetFile("C"),
                        manager.GetFile("C"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                        manager.GetFile("D"),
                    });
                }
            }
        }
        public void ReadOnlyFileを正しく削除する()
        {
            using (var dirA = new TempDirectory(true))
            using (var dirB = new TempDirectory(true))
            {
                dirA.AddFile("a.txt", "a");
                dirB.AddFile("a.txt", "bb");

                var file = dirB.FullPath("a.txt");
                File.SetAttributes(file, File.GetAttributes(file) | FileAttributes.ReadOnly);

                var backup = new DirectoryBackup(dirA.Name, dirB.Name);
                backup.Start();

                Assert.AreEqual("a", FileUtility.Load(file));
            }
        }
        public void Test1()
        {
            var text = "abc";
            using (var dir = new TempDirectory(true))
            using (var copiedDir = new TempDirectory(true))
            {
                try
                {
                    var a = "a.cs";
                    dir.AddFile(a, "abc");
                    Assert.False(File.Exists(copiedDir.FullPath(a)));

                    FishLibUpdate.Update(dir.Name, copiedDir.Name, "*.cs");
                    FileAssert.AreEqual(dir.FullPath(a), copiedDir.FullPath(a));

                    // コピーしたファイルはReadOnly属性に変える

                    Assert.AreEqual(FileAttributes.ReadOnly, File.GetAttributes(copiedDir.FullPath(a)) & FileAttributes.ReadOnly);
                }
                finally
                {
                    全ファイルのReadOnly属性の解除(copiedDir.Name);
                }
            }
            using (var dir = new TempDirectory(true))
            using (var copiedDir = new TempDirectory(true))
            {
                try
                {
                    // 更新日時が古いものは上書きコピーする
                    var b = "b.cs";

                    dir.AddFile(b, text);
                    copiedDir.AddFile(b, text);

                    var t0 = new DateTime(2014, 3, 4, 0, 0, 0); // UTC
                    var t1 = new DateTime(2013, 3, 4, 0, 0, 0); // UTC
                    var db = dir.FullPath(b);
                    var cb = copiedDir.FullPath(b);
                    File.SetLastWriteTime(db, t0);
                    File.SetLastWriteTime(cb, t1);

                    File.SetAttributes(cb, FileAttributes.ReadOnly);

                    FishLibUpdate.Update(dir.Name, copiedDir.Name);
                    Assert.AreEqual(t0, File.GetLastWriteTime(cb));
                }
                finally
                {
                    全ファイルのReadOnly属性の解除(copiedDir.Name);
                }
            }
            using (var dir = new TempDirectory(true))
            using (var copiedDir = new TempDirectory(true))
            {
                try
                {
                    // 更新日時が新しいものは例外
                    var c = "c.cs";

                    dir.AddFile(c, text);
                    copiedDir.AddFile(c, text);

                    var dc = dir.FullPath(c);
                    var cc = copiedDir.FullPath(c);

                    var t0 = new DateTime(2013, 3, 4, 0, 0, 0); // UTC
                    var t1 = new DateTime(2014, 3, 4, 0, 0, 0); // UTC

                    File.SetLastWriteTime(dc, t0);
                    File.SetLastWriteTime(cc, t1);

                    File.SetAttributes(cc, FileAttributes.ReadOnly);

                    Assert.Throws<ApplicationException>(() =>
                    {
                        FishLibUpdate.Update(dir.Name, copiedDir.Name);
                    });
                }
                finally
                {
                    全ファイルのReadOnly属性の解除(copiedDir.Name);
                }
            }
            using (var dir = new TempDirectory(true))
            using (var copiedDir = new TempDirectory(true))
            {
                try
                {
                    // 更新日時が同じで中身が違うものは例外
                    var d = "d.cs";

                    dir.AddFile(d, text);
                    copiedDir.AddFile(d, text + text);

                    var dd = dir.FullPath(d);
                    var cd = copiedDir.FullPath(d);

                    var t0 = new DateTime(2013, 3, 4, 0, 0, 0); // UTC

                    File.SetLastWriteTime(dd, t0);
                    File.SetLastWriteTime(cd, t0);

                    File.SetAttributes(cd, FileAttributes.ReadOnly);

                    Assert.Throws<ApplicationException>(() =>
                    {
                        FishLibUpdate.Update(dir.Name, copiedDir.Name);
                    });
                }
                finally
                {
                    全ファイルのReadOnly属性の解除(copiedDir.Name);
                }
            }
            using (var dir = new TempDirectory(true))
            using (var copiedDir = new TempDirectory(true))
            {
                try
                {
                    // 更新日時が同じで中身が同じファイルは無視
                    var f = "f.cs";

                    dir.AddFile(f, text);
                    copiedDir.AddFile(f, text);

                    var df = dir.FullPath(f);
                    var cf = copiedDir.FullPath(f);

                    var t0 = new DateTime(2013, 3, 4, 0, 0, 0); // UTC

                    File.SetLastWriteTime(df, t0);
                    File.SetLastWriteTime(cf, t0);

                    File.SetAttributes(cf, FileAttributes.ReadOnly);

                    FishLibUpdate.Update(dir.Name, copiedDir.Name);
                }
                finally
                {
                    全ファイルのReadOnly属性の解除(copiedDir.Name);
                }
            }
        }
        public void Test0()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                var manager = new ResultImageManager();

                tempDirectory.AddFile(@"A\file0.png", "");
                tempDirectory.AddFile(@"B\file0.bmp", "");
                tempDirectory.AddFile(@"D\file0.txt", "");
                manager.DirectoryName = tempDirectory.Name;
                Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
                Assert.Null(manager.GetFile("C"));
                Assert.Null(manager.GetFile("C"));
                Assert.Null(manager.GetFile("C"));
                Assert.Null(manager.GetFile("D"));
                Assert.Null(manager.GetFile("D"));
                Assert.Null(manager.GetFile("D"));

                tempDirectory.AddFile(@"file3.jpg", "");
                Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
                Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));

                tempDirectory.AddFile(@"A\file1.png", "");
                manager.Refresh();
                CollectionAssert.AreEquivalent(new []
                {
                    tempDirectory.GetFullPath(@"A\file0.png"),
                    tempDirectory.GetFullPath(@"A\file0.png"),
                    tempDirectory.GetFullPath(@"A\file1.png"),
                    tempDirectory.GetFullPath(@"A\file1.png"),

                }, new []
                {
                    manager.GetFile("A"),
                    manager.GetFile("A"),
                    manager.GetFile("A"),
                    manager.GetFile("A"),
                });

                manager.Refresh();
                var file = manager.GetFile("A", false);
                Assert.AreEqual(file, manager.GetFile("A", false));
                Assert.AreEqual(file, manager.GetFile("A", false));
                Assert.AreEqual(file, manager.GetFile("A", false));
                Assert.AreEqual(file, manager.GetFile("A", false));
                Assert.AreEqual(file, manager.GetFile("A", false));
                Assert.AreEqual(file, manager.GetFile("A", false));
            }
        }
        public void SaveToTest()
        {
            using (var dir = new TempDirectory(true))
            {
                dir.AddFile("Settings.fd48c0a4.xml", SettingsFileAccessor1_0Test.Xml1);
                dir.AddFile("Settings.ad283732.xml", SettingsFileAccessor1_0Test.Xml2);
                dir.AddFile("Results.fd48c0a4.dat", ResultsFileAccessor1_0Test.Xml1, StreamOptions.GZip);
                dir.AddFile("Results.ad283732.dat", ResultsFileAccessor1_0Test.Xml2, StreamOptions.GZip);

                var container = EPuzzleUserInfoContainer.LoadAllFilesFrom(dir.Name);
                var infos = container.Items;
                Assert.AreEqual(2, container.Items.Count());

                CollectionAssert.AreEqual(new []
                {
                    new Guid("fd48c0a4-95fc-4797-94a1-adcfd38fbdc2"),
                    new Guid("ad283732-c719-4306-b569-64c1eea59c85"),
                }, infos.Select(x => x.UserId));

                CollectionAssert.AreEqual(new []
                {
                    "User01", "User02",

                }, infos.Select(x => x.UserName));

                var info = container.GetUserInfo(Guid.Parse("fd48c0a4-95fc-4797-94a1-adcfd38fbdc2"));
                var lastDaimonInfos = info.GetLastDaimonInfos();
                CollectionAssert.AreEqual(new [] { "document0", "document1", }, lastDaimonInfos.Select(x => x.DocumentId));
                CollectionAssert.AreEqual(new [] { "daimonA1", "daimonA2", }, lastDaimonInfos.Select(x => x.DaimonId));
                CollectionAssert.AreEqual(new [] { DateTime.Parse("2012-11-22T10:09:57+09:00"), DateTime.Parse("2012-11-23T10:09:57+09:00"), }, lastDaimonInfos.Select(x => x.CreationTime));

                Assert.AreEqual(1, info.MondaiResults.Count());
                var result = info.MondaiResults.First();
                Assert.AreEqual("mondai001", result.MondaiId);
                Assert.AreEqual(DateTime.Parse("2012-10-06T18:23:46.199375+09:00"), result.StartTime);
                Assert.AreEqual(TimeSpan.FromMinutes(1.5d), result.所要時間);

                using (var dir2 = new TempDirectory(true))
                {
                    container.SaveAllFilesTo(dir2.Name, "1.0", "1.0");
                    FileAssert.AreEqual(dir.FullPath("Settings.fd48c0a4.xml"), dir2.FullPath("Settings.fd48c0a4.xml"));
                    FileAssert.AreEqual(dir.FullPath("Settings.ad283732.xml"), dir2.FullPath("Settings.ad283732.xml"));
                    FileAssert.AreEqual(dir.FullPath("Results.fd48c0a4.dat"), dir2.FullPath("Results.fd48c0a4.dat"));
                    FileAssert.AreEqual(dir.FullPath("Results.ad283732.dat"), dir2.FullPath("Results.ad283732.dat"));
                }
            }
        }
        public void BackupDirectoryTest()
        {
            using (var dirX = new TempDirectory(true))
            using (var dirY = new TempDirectory(true))
            {
                var t0 = new DateTime(2014, 1, 30, 0, 0, 0); // UTC
                var t1 = t0.AddSeconds(1d);

                {
                    // XとYにあってサイズが違う。
                    var fileA = @"a.txt";
                    dirX.AddFile(fileA, "abc");
                    dirY.AddFile(fileA, "ab");

                    new FileInfo(dirX.FullPath(fileA)).LastWriteTime = t0;
                    new FileInfo(dirY.FullPath(fileA)).LastWriteTime = t0;

                    Assert.AreEqual(new FileInfo(dirX.FullPath(fileA)).LastWriteTime, t0);
                    Assert.AreEqual(new FileInfo(dirX.FullPath(fileA)).LastWriteTime, new FileInfo(dirY.FullPath(fileA)).LastWriteTime);

                    FileAssert.AreNotEqual(dirX.FullPath(fileA), dirY.FullPath(fileA));

                    var backup = new DirectoryBackup(dirX.Name, dirY.Name);
                    backup.Start();

                    FileAssert.AreEqual(dirX.FullPath(fileA), dirY.FullPath(fileA));
                }
                {
                    // XとYにあって更新日時が違う。
                    var fileB = @"s\t\b.txt";
                    dirX.AddFile(fileB, "abc");
                    dirY.AddFile(fileB, "abc");

                    new FileInfo(dirX.FullPath(fileB)).LastWriteTime = t0;
                    new FileInfo(dirY.FullPath(fileB)).LastWriteTime = t1;

                    Assert.AreEqual(new FileInfo(dirX.FullPath(fileB)).LastWriteTime, t0);
                    Assert.AreNotEqual(new FileInfo(dirX.FullPath(fileB)).LastWriteTime, new FileInfo(dirY.FullPath(fileB)).LastWriteTime);

                    var backup = new DirectoryBackup(dirX.Name, dirY.Name);
                    backup.Start();

                    FileAssert.AreEqual(dirX.FullPath(fileB), dirY.FullPath(fileB));
                    Assert.AreEqual(new FileInfo(dirX.FullPath(fileB)).LastWriteTime, new FileInfo(dirY.FullPath(fileB)).LastWriteTime);
                }
                {
                    // XにあってYにない
                    var fileC = @"u\v\c.txt";
                    dirX.AddFile(fileC, "abc");

                    Assert.True(File.Exists(dirX.FullPath(fileC)));
                    Assert.False(File.Exists(dirY.FullPath(fileC)));

                    var backup = new DirectoryBackup(dirX.Name, dirY.Name);
                    backup.Start();

                    Assert.True(File.Exists(dirX.FullPath(fileC)));
                    Assert.True(File.Exists(dirY.FullPath(fileC)));
                }
                {
                    // YにあってXにない
                    var fileD = @"w\x\d.txt";
                    dirY.AddFile(fileD, "abc");

                    Assert.False(File.Exists(dirX.FullPath(fileD)));
                    Assert.True(File.Exists(dirY.FullPath(fileD)));

                    var backup = new DirectoryBackup(dirX.Name, dirY.Name);
                    backup.Start();

                    Assert.False(File.Exists(dirX.FullPath(fileD)));
                    Assert.False(File.Exists(dirY.FullPath(fileD)));
                }
                {
                    // XにあってYにないディレクトリの作成
                    var dir1 = @"xxxx\yyyy";
                    dirX.AddDirectory(dir1);

                    Assert.True(Directory.Exists(dirX.FullPath(dir1)));
                    Assert.False(Directory.Exists(dirY.FullPath(dir1)));

                    var backup = new DirectoryBackup(dirX.Name, dirY.Name);
                    backup.Start();

                    Assert.True(Directory.Exists(dirX.FullPath(dir1)));
                    Assert.True(Directory.Exists(dirY.FullPath(dir1)));
                }
                {
                    // YにあってXにないディレクトリの削除
                    var dir2 = @"ssss\tttt";
                    dirY.AddDirectory(dir2);

                    Assert.False(Directory.Exists(dirX.FullPath(dir2)));
                    Assert.True(Directory.Exists(dirY.FullPath(dir2)));

                    var backup = new DirectoryBackup(dirX.Name, dirY.Name);
                    backup.Start();

                    Assert.False(Directory.Exists(dirX.FullPath(dir2)));
                    Assert.False(Directory.Exists(dirY.FullPath(dir2)));
                }
            }
        }