本文整理汇总了C#中FileManager.GetTempFileName方法的典型用法代码示例。如果您正苦于以下问题:C# FileManager.GetTempFileName方法的具体用法?C# FileManager.GetTempFileName怎么用?C# FileManager.GetTempFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager.GetTempFileName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTempFileNameReturnsNewFileName
public void GetTempFileNameReturnsNewFileName()
{
// Arrange.
const string TempDocumentUNC = @"z:\Temp\";
var guid1 = new Guid("{D98C2A44-FACF-4FD4-ACA8-EBBE3AD6A173}");
var guid2 = new Guid("{28FAEA09-F87A-42F4-B7AA-18079670C428}");
var fileManager = new FileManager();
var systemOptions = Mock.Create<ISystemOptionsInfo>();
Mock.Arrange(() => systemOptions.TempDocumentUNC).Returns(TempDocumentUNC);
Mock.Arrange(() => SystemOptionsInfo.GetSystemOptionsInfo()).Returns(systemOptions);
Mock.Arrange(() => Guid.NewGuid()).Returns(guid1).InSequence();
Mock.Arrange(() => Guid.NewGuid()).Returns(guid2).InSequence();
Mock.Arrange(() => Directory.Exists(TempDocumentUNC)).Returns(true);
Mock.Arrange(() => File.Create(Arg.AnyString)).Returns(() => Mock.Create<FileStream>(Behavior.Loose));
// Act.
var tempFile = fileManager.GetTempFileName(null);
var tempFileWithExtension = fileManager.GetTempFileName("tmp");
// Assert.
Assert.AreEqual(@"z:\Temp\D98C2A44-FACF-4FD4-ACA8-EBBE3AD6A173", tempFile);
Assert.AreEqual(@"z:\Temp\28FAEA09-F87A-42F4-B7AA-18079670C428.tmp", tempFileWithExtension);
Mock.Assert(() => File.Create(@"z:\Temp\D98C2A44-FACF-4FD4-ACA8-EBBE3AD6A173"), Occurs.Once());
Mock.Assert(() => File.Create(@"z:\Temp\28FAEA09-F87A-42F4-B7AA-18079670C428.tmp"), Occurs.Once());
// Expected exceptions.
Mock.Arrange(() => SystemOptionsInfo.GetSystemOptionsInfo()).Returns(() => null);
TestsHelper.VerifyThrow<SystemOptionsLoadException>(() => fileManager.GetTempFileName(null));
Mock.Arrange(() => systemOptions.TempDocumentUNC).Returns(string.Empty);
Mock.Arrange(() => SystemOptionsInfo.GetSystemOptionsInfo()).Returns(systemOptions);
TestsHelper.VerifyThrow<InvalidSystemOptionsException>(() => fileManager.GetTempFileName(null));
}