当前位置: 首页>>代码示例>>C#>>正文


C# TempDirectory.CreateTempFile方法代码示例

本文整理汇总了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");
            }
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:10,代码来源:DirectoryInfoExtensionsTests.cs

示例2: 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

示例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");
     }
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:10,代码来源:TempDirectoryFixture.cs

示例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);
     }
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:10,代码来源:TempDirectoryFixture.cs

示例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));
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:13,代码来源:TempDirectoryFixture.cs

示例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());
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:18,代码来源:DirectoryInfoExtensionsTests.cs

示例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);
                }
            }
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:19,代码来源:FindDataTests.cs

示例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);
                }
            }
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:20,代码来源:FindDataTests.cs

示例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);
                }
            }
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:20,代码来源:FindDataTests.cs


注:本文中的System.IO.TempDirectory.CreateTempFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。