本文整理汇总了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"));
}
}
示例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)));
//.........这里部分代码省略.........