当前位置: 首页>>代码示例>>C#>>正文


C# TempDirectory.FullPath方法代码示例

本文整理汇总了C#中System.IO.TempDirectory.FullPath方法的典型用法代码示例。如果您正苦于以下问题:C# TempDirectory.FullPath方法的具体用法?C# TempDirectory.FullPath怎么用?C# TempDirectory.FullPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.TempDirectory的用法示例。


在下文中一共展示了TempDirectory.FullPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFromImageFilesTest

 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));
     }
 }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:11,代码来源:HelpDocument.test.cs

示例2: AddFileNamesTest

        public void AddFileNamesTest()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddDirectory("A");

                var manager = new ResultImageManager2(tempDirectory.Name);
                manager.AddFileNames(new []
                {
                    tempDirectory.FullPath(@"A\file0.png"),
                    tempDirectory.FullPath(@"A\file1.png"),
            //					tempDirectory.FullPath(@"file2.png"),
                });

                CollectionAssert.AreEquivalent(new []
                {
                    tempDirectory.FullPath(@"A\file0.png"),
                    tempDirectory.FullPath(@"A\file1.png"),
            //					tempDirectory.FullPath(@"file2.png"),
                }, manager.Files);

            //				Assert.AreEqual(tempDirectory.FullPath(@"file2.png"), manager.GetFile("B"));
                Assert.Null(manager.GetFile("B"));
                Assert.AreEqual(tempDirectory.FullPath(@"A\file0.png"), manager.GetFile("A"));
                Assert.AreEqual(tempDirectory.FullPath(@"A\file1.png"), manager.GetFile("A"));
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:27,代码来源:ResultImageManager2.test.cs

示例3: Test1

 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"));
     }
 }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:13,代码来源:EPuzzleSoundPlayer.test.cs

示例4: Test1

        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

//.........这里部分代码省略.........
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:101,代码来源:FishLibUpdate.test.cs

示例5: GetImageTest

        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"));
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:48,代码来源:ResultImageManager2.test.cs

示例6: PrepareForImagesTest

        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);
                }
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:63,代码来源:ResultImageManager.test.cs

示例7: SaveToTest

        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"));
                }
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:47,代码来源:EPuzzleUserInfoContainer.test.cs

示例8: using

        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);
//.........这里部分代码省略.........
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:101,代码来源:EPuzzleData.test.cs

示例9: BackupDirectoryTest

        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)));
//.........这里部分代码省略.........
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:101,代码来源:DirectoryBackup.test.cs

示例10: using

        public void ファイルを暗号化してディレクトリをバックアップする([Values(true, false)] bool verify)
        {
            using (var dir1 = new TempDirectory(true))
            using (var dir2 = new TempDirectory(true))
            {
                var password = "xxx";
                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 = "xxx";
                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));
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:99,代码来源:DirectoryBackup.test.cs


注:本文中的System.IO.TempDirectory.FullPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。