本文整理汇总了C#中System.IO.TempDirectory类的典型用法代码示例。如果您正苦于以下问题:C# TempDirectory类的具体用法?C# TempDirectory怎么用?C# TempDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TempDirectory类属于System.IO命名空间,在下文中一共展示了TempDirectory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:FileSystemWatcher.Renamed.cs
示例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"));
}
}
开发者ID:DavidMoore,项目名称:Foundation,代码行数:7,代码来源:DirectoryInfoExtensionsTests.cs
示例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");
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:FileSystemWatcher.Created.cs
示例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"));
}
}
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:27,代码来源:ResultImageManager2.test.cs
示例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");
}
}
开发者ID:prasanths,项目名称:cassette,代码行数:29,代码来源:BundleCache.cs
示例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);
}
}
开发者ID:jgreene,项目名称:KissCI,代码行数:35,代码来源:RobocopyTests.cs
示例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();
}
}
开发者ID:hempels,项目名称:cassette,代码行数:27,代码来源:BundleCache.cs
示例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);
}
开发者ID:TheCloudlessSky,项目名称:cassette,代码行数:30,代码来源:CreateBundlesWithRawFilesTests.cs
示例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");
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:FileSystemWatcher.IncludeSubDirectories.cs
示例10: GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse
public void GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse()
{
using (var path = new TempDirectory())
{
var dir = new FileSystemDirectory(path);
dir.DirectoryExists("sub").ShouldBeFalse();
}
}
开发者ID:jlopresti,项目名称:cassette,代码行数:8,代码来源:FileSystemDirectory.cs
示例11: WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue
public void WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue()
{
using (var path = new TempDirectory())
{
var dir = new FileSystemDirectory(path);
dir.DirectoryExists("~").ShouldBeTrue();
}
}
开发者ID:jlopresti,项目名称:cassette,代码行数:8,代码来源:FileSystemDirectory.cs
示例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);
}
开发者ID:chcosta,项目名称:corefx,代码行数:8,代码来源:TempConfig.cs
示例13: Can_create_temporary_file
public void Can_create_temporary_file()
{
using( var dir = new TempDirectory() )
{
var file = dir.CreateTempFile();
Assert.IsTrue(file.Exists);
}
}
开发者ID:DavidMoore,项目名称:Foundation,代码行数:8,代码来源:TempDirectoryFixture.cs
示例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>();
}
}
开发者ID:romanych,项目名称:cassette,代码行数:9,代码来源:FileSystemDirectory.cs
示例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"]);
}
}
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:56,代码来源:SecretManagerTests.cs
示例16: Can_write_to_temporary_file
public void Can_write_to_temporary_file()
{
using( var dir = new TempDirectory() )
{
var file = dir.CreateTempFile();
Assert.IsTrue(file.Exists);
File.WriteAllText(file.FullName, "Test\r\nLine2");
Assert.AreEqual(File.ReadAllText(file.FullName), "Test\r\nLine2");
}
}
开发者ID:DavidMoore,项目名称:Foundation,代码行数:10,代码来源:TempDirectoryFixture.cs
示例17: GivenEmptyDirectory_ThenCacheReadFails
public void GivenEmptyDirectory_ThenCacheReadFails()
{
using (var path = new TempDirectory())
{
var directory = new FileSystemDirectory(path);
var cache = new BundleCollectionCache(directory, b => deserializers[b]);
var result = cache.Read();
result.IsSuccess.ShouldBeFalse();
}
}
开发者ID:jlopresti,项目名称:cassette,代码行数:10,代码来源:BundleCollectionCache.Read.cs
示例18: Can_create_temporary_file_with_a_specific_filename
public void Can_create_temporary_file_with_a_specific_filename()
{
using( var dir = new TempDirectory() )
{
var file = dir.CreateTempFile("test.tmp");
Assert.IsTrue(file.Exists);
Assert.AreEqual(file.Name, "test.tmp");
Assert.AreEqual(Path.Combine(dir.DirectoryInfo.FullName, "test.tmp"), file.FullName);
}
}
开发者ID:DavidMoore,项目名称:Foundation,代码行数:10,代码来源:TempDirectoryFixture.cs
示例19: Site_NonNullSetEnablesRaisingEvents
public void Site_NonNullSetEnablesRaisingEvents()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var watcher = new TestFileSystemWatcher(testDirectory.Path, "*"))
{
TestSite site = new TestSite() { designMode = true };
watcher.Site = site;
Assert.True(watcher.EnableRaisingEvents);
}
}
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:FileSystemWatcher.netstandard17.cs
示例20: GivenSubDirectoryDoesNotExist_WhenGetDirectoryWithCreateTrue_ThenDirectoryIsCreated
public void GivenSubDirectoryDoesNotExist_WhenGetDirectoryWithCreateTrue_ThenDirectoryIsCreated()
{
using (var path = new TempDirectory())
{
var dir = new FileSystemDirectory(path);
dir.GetDirectory("sub", true);
Directory.Exists(Path.Combine(path, "sub")).ShouldBeTrue();
}
}
开发者ID:romanych,项目名称:cassette,代码行数:10,代码来源:FileSystemDirectory.cs
注:本文中的System.IO.TempDirectory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论