本文整理匯總了C#中System.IO.TempDirectory.CreateTempFile方法的典型用法代碼示例。如果您正苦於以下問題:C# TempDirectory.CreateTempFile方法的具體用法?C# TempDirectory.CreateTempFile怎麽用?C# TempDirectory.CreateTempFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.TempDirectory
的用法示例。
在下文中一共展示了TempDirectory.CreateTempFile方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetFile_throws_exception_if_more_than_one_file_matches
public void GetFile_throws_exception_if_more_than_one_file_matches()
{
using(var dir = new TempDirectory())
{
dir.CreateTempFile("test1.txt");
dir.CreateTempFile("test2.txt");
dir.DirectoryInfo.GetFile("test*.txt");
}
}
示例2: Can_create_temporary_file
public void Can_create_temporary_file()
{
using( var dir = new TempDirectory() )
{
var file = dir.CreateTempFile();
Assert.IsTrue(file.Exists);
}
}
示例3: 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");
}
}
示例4: 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);
}
}
示例5: Temporary_file_gets_removed_properly_when_out_of_scope
public void Temporary_file_gets_removed_properly_when_out_of_scope()
{
string filename;
using( var dir = new TempDirectory() )
{
var file = dir.CreateTempFile();
Assert.IsTrue(file.Exists);
filename = file.FullName;
}
Assert.IsFalse(File.Exists(filename));
}
示例6: IsFile
public void IsFile()
{
using( var dir = new TempDirectory())
{
// An existing directory is not a file
Assert.IsFalse(dir.DirectoryInfo.IsFile());
// A file without an extension that exists can still be detected as a file
var file = dir.CreateTempFile("tempfile");
Assert.IsTrue( new DirectoryInfo(file.FullName).IsFile() );
}
// A file without an extension and that doesn't exist can't be detected as a file
Assert.IsFalse( new DirectoryInfo(@"D:\test").IsFile() );
// A file that doesn't exist but has an extension is detected as a file
Assert.IsTrue(new DirectoryInfo(@"D:\test.extension").IsFile());
}
示例7: DateModified
public void DateModified()
{
using (var tempDir = new TempDirectory())
{
var tempFile = tempDir.CreateTempFile("firstFile.txt");
var dateTime = tempFile.LastWriteTime;
var data = new FindData();
using (var handle = Win32Api.IO.FindFirstFile(tempFile.FullName, data))
{
Assert.IsFalse(handle.IsInvalid);
Assert.IsFalse(handle.IsClosed);
var actualDateTime = data.LastWriteTime.ToDateTime();
Assert.AreEqual(dateTime, actualDateTime);
}
}
}
示例8: FileSize
public void FileSize()
{
using (var tempDir = new TempDirectory())
{
var tempFile = tempDir.CreateTempFile("firstFile.txt");
File.WriteAllText(tempFile.FullName, @"abcde12345");
var size = tempFile.Length;
var data = new FindData();
using (var handle = Win32Api.IO.FindFirstFile(tempFile.FullName, data))
{
Assert.IsFalse(handle.IsInvalid);
Assert.IsFalse(handle.IsClosed);
var fileSize = data.FileSize;
Assert.AreEqual(size, fileSize);
}
}
}
示例9: CreatedDate
public void CreatedDate()
{
using (var tempDir = new TempDirectory())
{
var tempFile = tempDir.CreateTempFile("firstFile.txt");
var creationTime = tempFile.CreationTime;
var data = new FindData();
using (var handle = Win32Api.IO.FindFirstFile(tempFile.FullName, data))
{
Assert.IsFalse(handle.IsInvalid);
Assert.IsFalse(handle.IsClosed);
var dataCreationTime = data.CreationTime.ToDateTime();
Assert.AreEqual(creationTime, dataCreationTime);
}
}
}