当前位置: 首页>>代码示例>>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;未经允许,请勿转载。