本文整理汇总了C#中Microsoft.AspNet.FileProviders.PhysicalFileProvider.GetDirectoryContents方法的典型用法代码示例。如果您正苦于以下问题:C# PhysicalFileProvider.GetDirectoryContents方法的具体用法?C# PhysicalFileProvider.GetDirectoryContents怎么用?C# PhysicalFileProvider.GetDirectoryContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.FileProviders.PhysicalFileProvider
的用法示例。
在下文中一共展示了PhysicalFileProvider.GetDirectoryContents方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AbsolutePathNotAllowed
public void AbsolutePathNotAllowed()
{
var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider;
var appEnvironment = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment));
var provider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, "sub"));
var applicationBase = appEnvironment.ApplicationBasePath;
var file1 = Path.Combine(applicationBase, "File.txt");
var info = provider.GetFileInfo(file1);
info.ShouldNotBe(null);
info.Exists.ShouldBe(false);
var file2 = Path.Combine(applicationBase, "sub", "File2.txt");
info = provider.GetFileInfo(file2);
info.ShouldNotBe(null);
info.Exists.ShouldBe(false);
var directory1 = Path.Combine(applicationBase, "sub");
var directoryContents = provider.GetDirectoryContents(directory1);
info.ShouldNotBe(null);
info.Exists.ShouldBe(false);
var directory2 = Path.Combine(applicationBase, "Does_Not_Exists");
directoryContents = provider.GetDirectoryContents(directory2);
info.ShouldNotBe(null);
info.Exists.ShouldBe(false);
}
示例2: AbsolutePathNotAllowed
public void AbsolutePathNotAllowed()
{
var provider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "sub"));
var applicationBase = Directory.GetCurrentDirectory();
var file1 = Path.Combine(applicationBase, "File.txt");
var info = provider.GetFileInfo(file1);
Assert.NotNull(info);
Assert.False(info.Exists);
var file2 = Path.Combine(applicationBase, "sub", "File2.txt");
info = provider.GetFileInfo(file2);
Assert.NotNull(info);
Assert.False(info.Exists);
var directory1 = Path.Combine(applicationBase, "sub");
var directoryContents = provider.GetDirectoryContents(directory1);
Assert.NotNull(info);
Assert.False(info.Exists);
var directory2 = Path.Combine(applicationBase, "Does_Not_Exists");
directoryContents = provider.GetDirectoryContents(directory2);
Assert.NotNull(info);
Assert.False(info.Exists);
}
示例3: GetDirectoryContents_FromRootPath_ForEmptyDirectoryName
public void GetDirectoryContents_FromRootPath_ForEmptyDirectoryName()
{
var provider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, "sub"));
var info = provider.GetDirectoryContents(string.Empty);
info.ShouldNotBe(null);
info.Exists.ShouldBe(true);
var firstDirectory = info.Where(f => f.IsDirectory).Where(f => f.Exists).FirstOrDefault();
Should.Throw<InvalidOperationException>(() => firstDirectory.CreateReadStream());
var fileInfo = info.Where(f => f.Name == "File2.txt").FirstOrDefault();
fileInfo.ShouldNotBe(null);
fileInfo.Exists.ShouldBe(true);
}
示例4: GetDirectoryContentsDoesNotReturnFileInfoForFileNameStartingWithPeriod
public void GetDirectoryContentsDoesNotReturnFileInfoForFileNameStartingWithPeriod()
{
using (var root = new DisposableFileSystem())
{
var directoryName = Guid.NewGuid().ToString();
var directoryPath = Path.Combine(root.RootPath, directoryName);
Directory.CreateDirectory(directoryPath);
var fileName = "." + Guid.NewGuid().ToString();
var filePath = Path.Combine(directoryPath, fileName);
File.Create(filePath);
using (var provider = new PhysicalFileProvider(root.RootPath))
{
var contents = provider.GetDirectoryContents(directoryName);
Assert.Empty(contents);
}
}
}
示例5: GetDirectoryContents_FromRootPath_ForEmptyDirectoryName
public void GetDirectoryContents_FromRootPath_ForEmptyDirectoryName()
{
var provider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "sub"));
var info = provider.GetDirectoryContents(string.Empty);
Assert.NotNull(info);
Assert.True(info.Exists);
var firstDirectory = info.Where(f => f.IsDirectory).Where(f => f.Exists).FirstOrDefault();
Assert.Throws<InvalidOperationException>(() => firstDirectory.CreateReadStream());
var fileInfo = info.Where(f => f.Name == "File2.txt").FirstOrDefault();
Assert.NotNull(fileInfo);
Assert.True(fileInfo.Exists);
}
示例6: GetDirectoryContentsDoesNotReturnFileInfoForSystemFile
public void GetDirectoryContentsDoesNotReturnFileInfoForSystemFile()
{
using (var root = new DisposableFileSystem())
{
var directoryName = Guid.NewGuid().ToString();
var directoryPath = Path.Combine(root.RootPath, directoryName);
Directory.CreateDirectory(directoryPath);
var fileName = Guid.NewGuid().ToString();
var filePath = Path.Combine(directoryPath, fileName);
File.Create(filePath);
var fileInfo = new FileInfo(filePath);
File.SetAttributes(filePath, fileInfo.Attributes | FileAttributes.System);
using (var provider = new PhysicalFileProvider(root.RootPath))
{
var contents = provider.GetDirectoryContents(directoryName);
Assert.Empty(contents);
}
}
}
示例7: GetDirectoryContentsReturnsRootDirectoryContentsForEmptyPath
public void GetDirectoryContentsReturnsRootDirectoryContentsForEmptyPath()
{
using (var root = new DisposableFileSystem())
{
File.Create(Path.Combine(root.RootPath, "File" + Guid.NewGuid().ToString()));
Directory.CreateDirectory(Path.Combine(root.RootPath, "Dir" + Guid.NewGuid().ToString()));
using (var provider = new PhysicalFileProvider(root.RootPath))
{
var contents = provider.GetDirectoryContents(string.Empty);
Assert.Collection(contents.OrderBy(c => c.Name),
item => Assert.IsType<PhysicalDirectoryInfo>(item),
item => Assert.IsType<PhysicalFileInfo>(item));
}
}
}
示例8: GetDirectoryContentsReturnsNotFoundDirectoryContentsForNonExistingDirectory
public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNonExistingDirectory()
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var contents = provider.GetDirectoryContents(Guid.NewGuid().ToString());
Assert.IsType(typeof(NotFoundDirectoryContents), contents);
}
}
示例9: GetDirectoryContentsReturnsNotFoundDirectoryContentsForNullPath
public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNullPath()
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var contents = provider.GetDirectoryContents(null);
Assert.IsType(typeof(NotFoundDirectoryContents), contents);
}
}
示例10: InvalidPath_DoesNotThrowGeneric_GetDirectoryContents
public void InvalidPath_DoesNotThrowGeneric_GetDirectoryContents(string path)
{
using (var provider = new PhysicalFileProvider(Directory.GetCurrentDirectory()))
{
var info = provider.GetDirectoryContents(path);
Assert.NotNull(info);
Assert.IsType<NotFoundDirectoryContents>(info);
}
}