本文整理汇总了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);
}
}
}