本文整理汇总了C#中System.IO.TempDirectory类的典型用法代码示例。如果您正苦于以下问题:C# TempDirectory类的具体用法?C# TempDirectory怎么用?C# TempDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TempDirectory类属于System.IO命名空间,在下文中一共展示了TempDirectory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileSystemWatcher_Renamed_Negative
public void FileSystemWatcher_Renamed_Negative()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
using (var watcher = new FileSystemWatcher(testDirectory.Path))
{
// put everything in our own directory to avoid collisions
watcher.Path = Path.GetFullPath(dir.Path);
watcher.Filter = "*.*";
AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Renamed);
watcher.EnableRaisingEvents = true;
// run all scenarios together to avoid unnecessary waits,
// assert information is verbose enough to trace to failure cause
// create a file
using (var testFile = new TempFile(Path.Combine(dir.Path, "file")))
using (var testDir = new TempDirectory(Path.Combine(dir.Path, "dir")))
{
// change a file
File.WriteAllText(testFile.Path, "changed");
// deleting a file & directory by leaving the using block
}
ExpectNoEvent(eventOccurred, "created");
}
}
示例2: GetFile_returns_null_when_file_not_found
public void GetFile_returns_null_when_file_not_found()
{
using(var dir = new TempDirectory())
{
Assert.IsNull(dir.DirectoryInfo.GetFile("does_not_exist.txt"));
}
}
示例3: FileSystemWatcher_Created_MoveDirectory
public void FileSystemWatcher_Created_MoveDirectory()
{
// create two test directories
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (TempDirectory originalDir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
using (TempDirectory targetDir = new TempDirectory(originalDir.Path + "_target"))
using (var watcher = new FileSystemWatcher(testDirectory.Path))
{
string testFileName = GetTestFileName();
// watch the target dir
watcher.Path = Path.GetFullPath(targetDir.Path);
watcher.Filter = testFileName;
AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Created);
string sourceFile = Path.Combine(originalDir.Path, testFileName);
string targetFile = Path.Combine(targetDir.Path, testFileName);
// create a test file in source
File.WriteAllText(sourceFile, "test content");
watcher.EnableRaisingEvents = true;
// move the test file from source to target directory
File.Move(sourceFile, targetFile);
ExpectEvent(eventOccurred, "created");
}
}
示例4: 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"));
}
}
示例5: GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset
public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset()
{
using (var cacheDir = new TempDirectory())
{
File.WriteAllText(
Path.Combine(cacheDir, "container.xml"),
"<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"1\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
);
File.WriteAllText(
Path.Combine(cacheDir, "test.bundle"),
"asset"
);
var bundleWithAsset = new TestableBundle("~/test");
var asset = StubAsset();
bundleWithAsset.Assets.Add(asset.Object);
var sourceBundles = new[] { bundleWithAsset };
var settings = new CassetteSettings
{
SourceDirectory = Mock.Of<IDirectory>(),
CacheDirectory = new FileSystemDirectory(cacheDir)
};
var cache = new BundleCache("VERSION", settings);
var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);
result.ShouldBeTrue();
bundleWithAsset.Assets[0].OpenStream().ReadToEnd().ShouldEqual("asset");
}
}
示例6: CanRobocopy
public void CanRobocopy()
{
var executableDirectory = DirectoryHelper.ExecutingDirectory();
var outputDirectory = Path.Combine(executableDirectory.FullName, "Robo");
var tasks = TaskHelper.Start()
.AddTask("Initialize directories", (ctx, arg) => {
var tempDir1 = new TempDirectory(outputDirectory, ctx.ProjectName);
var tempDir2 = new TempDirectory(outputDirectory, ctx.ProjectName);
File.AppendAllText(Path.Combine(tempDir1.DirectoryPath, "testfile.txt"), "test data");
ctx.RegisterCleanup(() => { tempDir1.Dispose(); tempDir2.Dispose(); });
return new RobocopyArgs(tempDir1.DirectoryPath, tempDir2.DirectoryPath);
})
.Robocopy()
.AddStep((ctx, arg) => {
var exists = File.Exists(Path.Combine(arg.CopiedToDirectory, "testfile.txt"));
Assert.IsTrue(exists);
return exists;
})
.Finalize();
var command = new KissCommand("build", tasks);
var project = new KissProject("TestProject", "UI", command);
using (var projectService = TestHelper.GetService())
{
projectService.RegisterProject(project);
ProjectHelper.Run(project, command, projectService);
}
}
示例7: GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnTrue
public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnTrue()
{
using (var cacheDir = new TempDirectory())
{
File.WriteAllText(
Path.Combine(cacheDir, "container.xml"),
"<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
);
File.WriteAllText(
Path.Combine(cacheDir, "test.bundle"),
"asset"
);
var bundle = new TestableBundle("~/test");
var sourceBundles = new[] { bundle };
var settings = new CassetteSettings("")
{
SourceDirectory = Mock.Of<IDirectory>(),
CacheDirectory = new FileSystemDirectory(cacheDir)
};
var cache = new BundleCache("VERSION", settings);
var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);
result.ShouldBeTrue();
}
}
示例8: CreateBundlesWithRawFilesTests
public CreateBundlesWithRawFilesTests()
{
root = new TempDirectory();
CreateDirectory("source");
CreateDirectory("source\\bin");
CreateDirectory("output");
WriteFile("source\\test.css", @"p { background: url(test.png); } .other { background: url(notfound.png); }");
WriteFile("source\\test.png", "image");
var configurationDll = CompileConfigurationDll();
File.Move(configurationDll, PathUtilities.Combine(root, "source", "bin", "test.dll"));
File.Copy("Cassette.dll", PathUtilities.Combine(root, "source", "bin", "Cassette.dll"));
File.Copy("Cassette.pdb", PathUtilities.Combine(root, "source", "bin", "Cassette.pdb"));
File.Copy("AjaxMin.dll", PathUtilities.Combine(root, "source", "bin", "AjaxMin.dll"));
#if NET35
File.Copy("Iesi.Collections.dll", PathUtilities.Combine(root, "source", "bin", "Iesi.Collections.dll"));
#endif
var command = new CreateBundlesCommand(
PathUtilities.Combine(root, "source"),
PathUtilities.Combine(root, "source", "bin"),
PathUtilities.Combine(root, "output"),
true
);
CreateBundlesCommand.ExecuteInSeparateAppDomain(command);
}
示例9: FileSystemWatcher_IncludeSubDirectories_Directory
public void FileSystemWatcher_IncludeSubDirectories_Directory()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
using (var watcher = new FileSystemWatcher(Path.GetFullPath(dir.Path)))
{
string dirPath = Path.GetFullPath(dir.Path);
string subDirPath = Path.Combine(dirPath, "subdir");
watcher.Path = dirPath;
watcher.IncludeSubdirectories = true;
AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Created);
Directory.CreateDirectory(subDirPath);
watcher.EnableRaisingEvents = true;
Directory.CreateDirectory(Path.Combine(subDirPath, "1"));
ExpectEvent(eventOccurred, "created");
watcher.IncludeSubdirectories = false;
Directory.CreateDirectory(Path.Combine(subDirPath, "2"));
ExpectNoEvent(eventOccurred, "created");
watcher.IncludeSubdirectories = true;
Directory.CreateDirectory(Path.Combine(subDirPath, "3"));
ExpectEvent(eventOccurred, "created");
}
}
示例10: GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse
public void GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse()
{
using (var path = new TempDirectory())
{
var dir = new FileSystemDirectory(path);
dir.DirectoryExists("sub").ShouldBeFalse();
}
}
示例11: WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue
public void WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue()
{
using (var path = new TempDirectory())
{
var dir = new FileSystemDirectory(path);
dir.DirectoryExists("~").ShouldBeTrue();
}
}
示例12: TempConfig
public TempConfig(string contents)
{
_directory = new TempDirectory();
ExePath = Path.Combine(_directory.Path, Path.GetRandomFileName() + ".exe");
File.WriteAllText(ExePath, "dummy exe");
ConfigPath = ExePath + ".config";
File.WriteAllText(ConfigPath, contents);
}
示例13: Can_create_temporary_file
public void Can_create_temporary_file()
{
using( var dir = new TempDirectory() )
{
var file = dir.CreateTempFile();
Assert.IsTrue(file.Exists);
}
}
示例14: GivenFileDoesNotExist_WhenGetFile_ThenReturnFileSystemFile
public void GivenFileDoesNotExist_WhenGetFile_ThenReturnFileSystemFile()
{
using (var path = new TempDirectory())
{
var dir = new FileSystemDirectory(path);
var file = dir.GetFile("test.txt");
file.ShouldBeType<FileSystemFile>();
}
}
示例15: MergedSecrets_PrioritizesFunctionSecrets
public void MergedSecrets_PrioritizesFunctionSecrets()
{
using (var directory = new TempDirectory())
{
string hostSecrets =
@"{
'masterKey': {
'name': 'master',
'value': '1234',
'encrypted': false
},
'functionKeys': [
{
'name': 'Key1',
'value': 'HostValue1',
'encrypted': false
},
{
'name': 'Key3',
'value': 'HostValue3',
'encrypted': false
}
]
}";
string functionSecrets =
@"{
'keys': [
{
'name': 'Key1',
'value': 'FunctionValue1',
'encrypted': false
},
{
'name': 'Key2',
'value': 'FunctionValue2',
'encrypted': false
}
]
}";
File.WriteAllText(Path.Combine(directory.Path, ScriptConstants.HostMetadataFileName), hostSecrets);
File.WriteAllText(Path.Combine(directory.Path, "testfunction.json"), functionSecrets);
IDictionary<string, string> result;
using (var secretManager = new SecretManager(_settingsManager, directory.Path, NullTraceWriter.Instance))
{
result = secretManager.GetFunctionSecrets("testfunction", true);
}
Assert.Contains("Key1", result.Keys);
Assert.Contains("Key2", result.Keys);
Assert.Contains("Key3", result.Keys);
Assert.Equal("FunctionValue1", result["Key1"]);
Assert.Equal("FunctionValue2", result["Key2"]);
Assert.Equal("HostValue3", result["Key3"]);
}
}