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


C# PhysicalFileProvider.GetDirectoryContents方法代码示例

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

示例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);
        }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:26,代码来源:PhysicalFileProviderTests.cs

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

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

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

示例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);
                }
            }
        }
开发者ID:leloulight,项目名称:FileSystem,代码行数:21,代码来源:PhysicalFileProviderTests.cs

示例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));
                }
            }
        }
开发者ID:leloulight,项目名称:FileSystem,代码行数:16,代码来源:PhysicalFileProviderTests.cs

示例8: GetDirectoryContentsReturnsNotFoundDirectoryContentsForNonExistingDirectory

 public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNonExistingDirectory()
 {
     using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
     {
         var contents = provider.GetDirectoryContents(Guid.NewGuid().ToString());
         Assert.IsType(typeof(NotFoundDirectoryContents), contents);
     }
 }
开发者ID:leloulight,项目名称:FileSystem,代码行数:8,代码来源:PhysicalFileProviderTests.cs

示例9: GetDirectoryContentsReturnsNotFoundDirectoryContentsForNullPath

 public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNullPath()
 {
     using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
     {
         var contents = provider.GetDirectoryContents(null);
         Assert.IsType(typeof(NotFoundDirectoryContents), contents);
     }
 }
开发者ID:leloulight,项目名称:FileSystem,代码行数:8,代码来源:PhysicalFileProviderTests.cs

示例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);
     }
 }
开发者ID:leloulight,项目名称:FileSystem,代码行数:9,代码来源:PhysicalFileProviderTests.cs


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