public void FileSystemResourceOpenNonExistanceFile()
        {
            FileSystemResource fileSystemResource = CreateResourceInstance(TemporaryFileName);
            Stream             inputStream        = fileSystemResource.InputStream;

            inputStream.Close();
        }
        public void SupportsAndResolvesTheSpecialHomeCharacter_OnlyIfSpecialHomeCharacterIsFirstCharacter()
        {
            FileSystemResource res = CreateResourceInstance("foo~.txt");

            // must not have replaced ~; its only valid at the start of a resource name...
            Assert.AreEqual("foo~.txt", res.File.Name);
        }
        public void FileSystemResourceExists()
        {
            FileInfo           file = GetAssemblyLocation(Assembly.GetExecutingAssembly());
            FileSystemResource fileSystemResource = CreateResourceInstance("~/" + file.Name);

            Assert.IsTrue(fileSystemResource.Exists);
        }
        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);
        }
        public void GetDescription()
        {
            FileSystemResource fileSystemResource  = CreateResourceInstance(TemporaryFileName);
            string             expectedDescription = "file [" + fileSystemResource.File.FullName + "]";

            Assert.AreEqual(expectedDescription, fileSystemResource.Description);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public void FileSystemResourceOpenNonExistanceFile()
        {
            FileSystemResource fileSystemResource = CreateResourceInstance(TemporaryFileName);
            Stream             inputStream;

            Assert.Throws <FileNotFoundException>(() => inputStream = fileSystemResource.InputStream);
        }
Beispiel #9
0
        private void ConfigureIoC()
        {
            IResource input = new FileSystemResource(Server.MapPath("objects.xml"));
            IObjectFactory factory = new XmlObjectFactory(input);
            DependencyResolver.InitializeWith(new SpringDependencyResolver(factory));

            ControllerBuilder.Current.SetControllerFactory(typeof(IoCControllerFactory));
        }
        public void Resolution_WithProtocolAndSpecialHomeCharacter()
        {
            FileInfo  file = CreateFileForTheCurrentDirectory();
            IResource res  = new FileSystemResource("file://~/" + TemporaryFileName);

            Assert.AreEqual(file.FullName, res.File.FullName,
                            "The file name with file://~ must have resolved to a file " +
                            "in the current directory of the currently executing domain.");
        }
        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 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 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 FileSystemResourceValidInputStream()
        {
            FileInfo           file = GetAssemblyLocation(Assembly.GetExecutingAssembly());
            FileSystemResource fileSystemResource = CreateResourceInstance("~/" + file.Name);

            using (Stream inputStream = fileSystemResource.InputStream)
            {
                Assert.IsNotNull(inputStream);
            }
        }
        public void FileSystemResourceGivesOpenedInputStream()
        {
            FileInfo           file = GetAssemblyLocation(Assembly.GetExecutingAssembly());
            FileSystemResource fileSystemResource = CreateResourceInstance("~/" + file.Name);

            using (Stream inputStream = fileSystemResource.InputStream)
            {
                Assert.IsTrue(inputStream.CanRead);
            }
        }
        public void Resolution_WithProtocolAndSpecialHomeCharacterParentDirectory()
        {
            FileInfo file = new FileInfo(Path.GetFullPath(
                                             Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemporaryFileName)));
            IResource res = new FileSystemResource("file://~/../" + TemporaryFileName);
            string    fileNameOneDirectoryUp = file.Directory.Parent.FullName + "\\" + TemporaryFileName;

            Assert.AreEqual(fileNameOneDirectoryUp, res.File.FullName,
                            "The file name with file://~/.. must have resolved to a file " +
                            "in the parent directory of the currently executing domain.");
        }
 public void SPRNET_89_SupportUrlEncodedLocationsWithSpaces()
 {
     string path = Path.GetFullPath("spaced dir");
     Directory.CreateDirectory(path);
     string filePath = Path.Combine(path, "spaced file.txt");
     using (StreamWriter text = File.CreateText(filePath))
     {
         text.WriteLine("hello world");
     }
     FileSystemResource res = new FileSystemResource(new Uri(filePath).AbsoluteUri);
     using (Stream s = res.InputStream)
     {
         using (TextReader reader = new StreamReader(s))
         {
             Assert.AreEqual("hello world", reader.ReadLine());
         }
     }
 }
        public void SPRNET_89_SupportUrlEncodedLocationsWithSpaces()
        {
            string path = Path.GetFullPath("spaced dir");

            Directory.CreateDirectory(path);
            string filePath = Path.Combine(path, "spaced file.txt");

            using (StreamWriter text = File.CreateText(filePath))
            {
                text.WriteLine("hello world");
            }
            FileSystemResource res = new FileSystemResource(new Uri(filePath).AbsoluteUri);

            using (Stream s = res.InputStream)
            {
                using (TextReader reader = new StreamReader(s))
                {
                    Assert.AreEqual("hello world", reader.ReadLine());
                }
            }
        }
        public void SupportsSpecialUriCharacter()
        {
            string path = Path.GetFullPath("dir#");

            Directory.CreateDirectory(path);
            string filePath = Path.Combine(path, "file.txt");

            using (StreamWriter text = File.CreateText(filePath))
            {
                text.WriteLine("hello world");
            }
            FileSystemResource res = new FileSystemResource(new Uri(filePath).AbsoluteUri);

            using (Stream s = res.InputStream)
            {
                using (TextReader reader = new StreamReader(s))
                {
                    Assert.AreEqual("hello world", reader.ReadLine());
                }
            }
        }
        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);
        }
        public void SupportsAndResolvesTheSpecialHomeCharacter_SunnyDayEvenWithLeadingWhitespace()
        {
            FileInfo file =
                new FileInfo(Path.GetFullPath(
                                 Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemporaryFileName)));
            StreamWriter       writer = file.CreateText();
            FileSystemResource res    = CreateResourceInstance("    ~/" + TemporaryFileName);

            Assert.AreEqual(file.FullName.ToLower(), res.File.FullName.ToLower());
            try
            {
                writer.Close();
            }
            catch (IOException)
            {}
            try
            {
                file.Delete();
            }
            catch (IOException)
            {}
        }
        /// <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)
                {
                }
            }
        }
        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);
        }
        public void GetResourceThatSupportsTheSpecialHomeCharacter()
        {
            string   filename     = "foo.txt";
            FileInfo expectedFile =
                new FileInfo(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename)));
            StreamWriter       writer = expectedFile.CreateText();
            FileSystemResource res    = (FileSystemResource)loader.GetResource("~/" + filename);

            Assert.AreEqual(expectedFile.FullName, res.File.FullName);
            try
            {
                writer.Close();
            }
            catch (IOException)
            {
            }
            try
            {
                expectedFile.Delete();
            }
            catch (IOException)
            {
            }
        }
 /// <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)
         {
         }
     }
 }
 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 GetURL()
        {
            FileSystemResource fileSystemResource = CreateResourceInstance(TemporaryFileName);

            Assert.IsNotNull(fileSystemResource.Uri);
        }
        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 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 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);
        }
 public void SupportsSpecialUriCharacter()
 {
     string path = Path.GetFullPath("dir#");
     Directory.CreateDirectory(path);
     string filePath = Path.Combine(path, "file.txt");
     using (StreamWriter text = File.CreateText(filePath))
     {
         text.WriteLine("hello world");
     }
     FileSystemResource res = new FileSystemResource(new Uri(filePath).AbsoluteUri);
     using (Stream s = res.InputStream)
     {
         using (TextReader reader = new StreamReader(s))
         {
             Assert.AreEqual("hello world", reader.ReadLine());
         }
     }
 }
 public void RelativeUncResourceTooManyBackLevels()
 {
     FileSystemResource res = new FileSystemResource(@"\\server\share\samples\artfair\dummy.txt");
     res.CreateRelative(@"..\..\..\index.html");
 }
 public void RelativeUncResourceTooManyBackLevels()
 {
     FileSystemResource res = new FileSystemResource(@"\\server\share\samples\artfair\dummy.txt");
     Assert.Throws<UriFormatException>(() => res.CreateRelative(@"..\..\..\index.html"));
 }
        public void RelativeResourceTooManyBackLevels()
        {
            FileSystemResource res = CreateResourceInstance("/samples/artfair/dummy.txt");

            res.CreateRelative("../../../index.html");
        }
 public void Resolution_WithProtocolAndSpecialHomeCharacterParentDirectory()
 {
     FileInfo file = new FileInfo(Path.GetFullPath(
         Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemporaryFileName)));
     IResource res = new FileSystemResource("file://~/../" + TemporaryFileName);
     string fileNameOneDirectoryUp = file.Directory.Parent.FullName + "\\" + TemporaryFileName;
     Assert.AreEqual(fileNameOneDirectoryUp, res.File.FullName,
         "The file name with file://~/.. must have resolved to a file " +
         "in the parent directory of the currently executing domain.");
 }
        public void CreateFileSystemResourceWithPathName()
        {
            FileSystemResource fileSystemResource = CreateResourceInstance(TemporaryFileName);

            Assert.AreEqual(TemporaryFileName, fileSystemResource.File.Name);
        }
 public void Resolution_WithProtocolAndSpecialHomeCharacter()
 {
     FileInfo file = CreateFileForTheCurrentDirectory();
     IResource res = new FileSystemResource("file://~/" + TemporaryFileName);
     Assert.AreEqual(file.FullName, res.File.FullName,
         "The file name with file://~ must have resolved to a file " +
         "in the current directory of the currently executing domain.");
 }
        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");

            res.CreateRelative(@"..\..\..\index.html");
        }
 static void FileSystem()
 {
     IResource input = new FileSystemResource(@"D:\Objects.xml");  //实际物理路径
     IObjectFactory factory = new XmlObjectFactory(input);
     Console.WriteLine(factory.GetObject("PersonDao").ToString());
 }
        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 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);
 }
Beispiel #43
0
        public void RelativeUncResourceTooManyBackLevels()
        {
            FileSystemResource res = new FileSystemResource(@"\\server\share\samples\artfair\dummy.txt");

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