public void When_TryGetFileInfo_and_resource_does_not_exist_then_should_not_get_file_info()
        {
            var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests.Resources");

            IFileInfo fileInfo;
            provider.TryGetFileInfo("/DoesNotExist.Txt", out fileInfo).ShouldBe(false);

            fileInfo.ShouldBe(null);
        }
        public void When_TryGetFileInfo_and_resource_does_not_exist_then_should_not_get_file_info()
        {
            var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests.Resources");

            IFileInfo fileInfo;

            provider.TryGetFileInfo("/DoesNotExist.Txt", out fileInfo).ShouldBe(false);

            fileInfo.ShouldBe(null);
        }
        public void When_TryGetFileInfo_and_resources_in_path_then_should_get_file_infos()
        {
            var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests");

            IFileInfo fileInfo;
            provider.TryGetFileInfo("/Resources.File.txt", out fileInfo).ShouldBe(true);

            fileInfo.ShouldNotBe(null);
            fileInfo.LastModified.ShouldNotBe(default(DateTime));
            fileInfo.Length.ShouldBeGreaterThan(0);
            fileInfo.IsDirectory.ShouldBe(false);
            fileInfo.PhysicalPath.ShouldBe(null);
            fileInfo.Name.ShouldBe("Resources.File.txt");
        }
Ejemplo n.º 4
0
        public bool TryGetFileInfo(string subpath, out IFileInfo fileInfo)
        {
            var result = inner.TryGetFileInfo(subpath, out IFileInfo tempFileInfo);

            if (tempFileInfo == null)
            {
                fileInfo = null;
            }
            else
            {
                fileInfo = new ReplaceableFileInfo(tempFileInfo, replaceDict);
            }
            return(result);
        }
        public void When_TryGetFileInfo_and_resources_in_path_then_should_get_file_infos()
        {
            var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests");

            IFileInfo fileInfo;

            provider.TryGetFileInfo("/Resources.File.txt", out fileInfo).ShouldBe(true);

            fileInfo.ShouldNotBe(null);
            fileInfo.LastModified.ShouldNotBe(default(DateTime));
            fileInfo.Length.ShouldBeGreaterThan(0);
            fileInfo.IsDirectory.ShouldBe(false);
            fileInfo.PhysicalPath.ShouldBe(null);
            fileInfo.Name.ShouldBe("Resources.File.txt");
        }
    public bool TryGetFileInfo(string subpath, out IFileInfo fileInfo)
    {
        if (string.IsNullOrEmpty(subpath) || subpath[0] != '/')
        {
            fileInfo = null;
            return(false);
        }

        var fixpath = (_baseNamespace + "." + subpath.Substring(1).Replace('/', '.').Replace('-', '_')).ToLower();

        fixpath = _resourceNames.FirstOrDefault(name => name.ToLower().Replace('-', '_') == fixpath);
        if (fixpath == null)
        {
            fileInfo = null;
            return(false);
        }

        fixpath = "/" + fixpath.Substring(_baseNamespace.Length + 1);
        return(_fileSystem.TryGetFileInfo(fixpath, out fileInfo));
    }