當前位置: 首頁>>代碼示例>>C#>>正文


C# TempDirectory.AddDirectory方法代碼示例

本文整理匯總了C#中System.IO.TempDirectory.AddDirectory方法的典型用法代碼示例。如果您正苦於以下問題:C# TempDirectory.AddDirectory方法的具體用法?C# TempDirectory.AddDirectory怎麽用?C# TempDirectory.AddDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.TempDirectory的用法示例。


在下文中一共展示了TempDirectory.AddDirectory方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: 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


注:本文中的System.IO.TempDirectory.AddDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。