示例#1
0
        public void RelativeResourceFromRoot()
        {
            FileSystemResource res = CreateResourceInstance(@"/dummy.txt");
            FileSystemResource res2;

            IResource rel0 = res.CreateRelative("/index.html");

            Assert.IsTrue(rel0 is FileSystemResource);
            res2 = CreateResourceInstance("/index.html");
            Assert.AreEqual(res2.File.FullName, rel0.File.FullName);

            IResource rel1 = res.CreateRelative(@"index.html");

            Assert.IsTrue(rel1 is FileSystemResource);
            res2 = CreateResourceInstance("/index.html");
            Assert.AreEqual(res2.File.FullName, rel1.File.FullName);

            IResource rel2 = res.CreateRelative(@"samples/artfair/index.html");

            Assert.IsTrue(rel2 is FileSystemResource);
            res2 = CreateResourceInstance("/samples/artfair/index.html");
            Assert.AreEqual(res2.File.FullName, rel2.File.FullName);

            IResource rel3 = res.CreateRelative(@"./samples/artfair/index.html");

            Assert.IsTrue(rel3 is FileSystemResource);
            res2 = CreateResourceInstance("/samples/artfair/index.html");
            Assert.AreEqual(res2.File.FullName, rel3.File.FullName);
        }
        public void LeadingProtocolIsNotTreatedRelative()
        {
            FileSystemResource res  = new FileSystemResource(@"file://\\server\share\samples\artfair\");
            FileSystemResource res2 = (FileSystemResource)res.CreateRelative(@"file://./index.html");

            Assert.AreEqual(new Uri(Path.Combine(Environment.CurrentDirectory, "index.html")).AbsolutePath, res2.Uri.AbsolutePath);
        }
示例#3
0
        public void CreateRelativeResourceIsEqualToOriginalAfterBouncingUpAndDownTheDirectoryTree()
        {
            IResource resource = new FileSystemResource(GetAssemblyLocation(Assembly.GetExecutingAssembly()).FullName);
            IResource relative =
                resource.CreateRelative("foo/bar/../../" + GetAssemblyLocation(Assembly.GetExecutingAssembly()).Name);

            Assert.IsTrue(relative.Exists);
            Assert.IsTrue(resource.Equals(relative));
        }
        public void RelativeUncResourceWhenNotRelative()
        {
            FileSystemResource res = new FileSystemResource(@"\\server\share\dummy.txt");

            IResource rel0 = res.CreateRelative(@"\\server\share\index.html");

            Assert.IsTrue(rel0 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\index.html]", rel0.Description);
        }
        public void RelativeLocalFileSystemResourceWhenNotRelative()
        {
            FileSystemResource res = new FileSystemResource(@"C:\dummy.txt");

            IResource rel0 = res.CreateRelative(@"c:\index.html");

            Assert.IsTrue(rel0 is FileSystemResource);
            Assert.AreEqual(@"file [c:\index.html]", rel0.Description);
        }
        public void RelativeUncResourceFromSubfolder()
        {
            FileSystemResource res = new FileSystemResource(@"\\server\share\samples\artfair\dummy.txt");

            IResource rel0 = res.CreateRelative(@"/index.html");

            Assert.IsTrue(rel0 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\index.html]", rel0.Description);

            IResource rel1 = res.CreateRelative(@"index.html");

            Assert.IsTrue(rel1 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\samples\artfair\index.html]", rel1.Description);

            IResource rel2 = res.CreateRelative(@"demo\index.html");

            Assert.IsTrue(rel2 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\samples\artfair\demo\index.html]", rel2.Description);

            IResource rel3 = res.CreateRelative(@"./demo/index.html");

            Assert.IsTrue(rel3 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\samples\artfair\demo\index.html]", rel3.Description);

            IResource rel4 = res.CreateRelative(@"../calculator/index.html");

            Assert.IsTrue(rel4 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\samples\calculator\index.html]", rel4.Description);

            IResource rel5 = res.CreateRelative(@"..\..\index.html");

            Assert.IsTrue(rel5 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\index.html]", rel5.Description);
        }
        public void RelativeUncResourceFromRoot()
        {
            FileSystemResource res = new FileSystemResource(@"\\server\share\dummy.txt");

            IResource rel0 = res.CreateRelative(@"\index.html");

            Assert.IsTrue(rel0 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\index.html]", rel0.Description);

            IResource rel1 = res.CreateRelative(@"index.html");

            Assert.IsTrue(rel1 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\index.html]", rel1.Description);

            IResource rel2 = res.CreateRelative(@"samples/artfair/index.html");

            Assert.IsTrue(rel2 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\samples\artfair\index.html]", rel2.Description);

            IResource rel3 = res.CreateRelative(@".\samples\artfair\index.html");

            Assert.IsTrue(rel3 is FileSystemResource);
            Assert.AreEqual(@"file [\\server\share\samples\artfair\index.html]", rel3.Description);
        }
        /// <summary>
        /// Helper method...
        /// </summary>
        private void _testCreateRelative(string rootPath, string targetPath, string relativePath)
        {
            string   filename = "stuff.txt";
            FileInfo file     = new FileInfo(Path.GetFullPath(Path.Combine(targetPath, filename)));
            // create a temporary file in whatever 'targetpath' dir we've been passed...
            StreamWriter writer = file.CreateText();
            // test that the CreateRelative () method works with the supplied 'relativePath'
            IResource resource = new FileSystemResource(rootPath);
            IResource relative = resource.CreateRelative(relativePath + filename);

            Assert.IsTrue(relative.Exists);
            if (file.Exists)
            {
                try
                {
                    writer.Close();
                    file.Delete();
                }
                catch (IOException)
                {
                }
            }
        }
示例#9
0
        public void RelativeResourceFromSubfolder()
        {
            FileSystemResource res = CreateResourceInstance(@"/samples/artfair/dummy.txt");
            FileSystemResource resExpected;

            IResource rel0 = res.CreateRelative(@"/index.html");

            Assert.IsTrue(rel0 is FileSystemResource);
            resExpected = CreateResourceInstance("/index.html");
            Assert.AreEqual(resExpected.File.FullName, rel0.File.FullName);

            IResource rel1 = res.CreateRelative(@"index.html");

            Assert.IsTrue(rel1 is FileSystemResource);
            resExpected = CreateResourceInstance("/samples/artfair/index.html");
            Assert.AreEqual(resExpected.File.FullName, rel1.File.FullName);

            IResource rel2 = res.CreateRelative(@"demo\index.html");

            Assert.IsTrue(rel2 is FileSystemResource);
            resExpected = CreateResourceInstance("/samples/artfair/demo/index.html");
            Assert.AreEqual(resExpected.File.FullName, rel2.File.FullName);

            IResource rel3 = res.CreateRelative(@"./demo/index.html");

            Assert.IsTrue(rel3 is FileSystemResource);
            resExpected = CreateResourceInstance("/samples/artfair/demo/index.html");
            Assert.AreEqual(resExpected.File.FullName, rel3.File.FullName);

            IResource rel4 = res.CreateRelative(@"../calculator/index.html");

            Assert.IsTrue(rel4 is FileSystemResource);
            resExpected = CreateResourceInstance("/samples/calculator/index.html");
            Assert.AreEqual(resExpected.File.FullName, rel4.File.FullName);

            IResource rel5 = res.CreateRelative(@"..\..\index.html");

            resExpected = CreateResourceInstance("/index.html");
            Assert.AreEqual(resExpected.File.FullName, rel5.File.FullName);
        }
示例#10
0
        public void RelativeResourceTooManyBackLevels()
        {
            FileSystemResource res = CreateResourceInstance("/samples/artfair/dummy.txt");

            Assert.Throws <UriFormatException>(() => res.CreateRelative("../../../index.html"));
        }
        public void RelativeUncResourceTooManyBackLevels()
        {
            FileSystemResource res = new FileSystemResource(@"\\server\share\samples\artfair\dummy.txt");

            Assert.Throws <UriFormatException>(() => res.CreateRelative(@"..\..\..\index.html"));
        }