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 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 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 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 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 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 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) { } }
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 CreateFileSystemResourceWithPathName() { FileSystemResource fileSystemResource = CreateResourceInstance(TemporaryFileName); Assert.AreEqual(TemporaryFileName, fileSystemResource.File.Name); }
public void RelativeResourceTooManyBackLevels() { FileSystemResource res = CreateResourceInstance("/samples/artfair/dummy.txt"); Assert.Throws <UriFormatException>(() => res.CreateRelative("../../../index.html")); }
public void GetURL() { FileSystemResource fileSystemResource = CreateResourceInstance(TemporaryFileName); Assert.IsNotNull(fileSystemResource.Uri); }
public void RelativeUncResourceTooManyBackLevels() { FileSystemResource res = new FileSystemResource(@"\\server\share\samples\artfair\dummy.txt"); Assert.Throws <UriFormatException>(() => res.CreateRelative(@"..\..\..\index.html")); }