public void ShouldChangeExtension(string extension, string expected) { // Given NormalizedPath path = new NormalizedPath("temp/hello.txt"); // When path = path.ChangeExtension(extension); // Then Assert.AreEqual(expected, path.ToString()); }
public async Task <string> TryImportAsync(string requestedFile, string parentPath) { // Modify the requested file if we have an import path function string modifiedParentPath = null; if (_importPathFunc != null) { requestedFile = _importPathFunc(requestedFile); modifiedParentPath = _importPathFunc(parentPath); } if (string.IsNullOrWhiteSpace(requestedFile)) { return(null); } // Get the input relative path to the parent file // Make sure to try checking for a previously processed parent post-modification NormalizedPath parentFilePath = new NormalizedPath(parentPath); NormalizedPath requestedFilePath = new NormalizedPath(requestedFile); if (parentFilePath.IsRelative && !_parentAbsolutePaths.TryGetValue(parentFilePath, out parentFilePath) && (modifiedParentPath == null || !_parentAbsolutePaths.TryGetValue(modifiedParentPath, out parentFilePath))) { // Relative parent path and no available absolute path, try with the relative path parentFilePath = new NormalizedPath(parentPath); } // Try to get the relative path to the parent file from inside the input virtual file system // But if the parent file isn't under an input path, just use it directly NormalizedPath containingInputPath = _fileSystem.GetContainingInputPath(parentFilePath); NormalizedPath parentRelativePath = containingInputPath.IsNull ? parentFilePath : containingInputPath.GetRelativePath(parentFilePath); // Find the requested file by first combining with the parent NormalizedPath filePath = parentRelativePath.ChangeFileName(requestedFilePath); string scss = await GetFileVariationsAsync(filePath, requestedFilePath); if (scss != null) { return(scss); } // That didn't work so try it again as a relative path from the input folder scss = await GetFileVariationsAsync(requestedFilePath, requestedFilePath); if (!requestedFilePath.IsAbsolute && scss != null) { return(scss); } return(null); }
public void CanGetDirectoryForFilePath() { // Given NormalizedPath path = new NormalizedPath("temp/hello.txt"); // When NormalizedPath directory = path.Parent; // Then Assert.AreEqual("temp", directory.FullPath); }
public void ShouldReturnRootRelativePath(string fullPath, string expected) { // Given NormalizedPath path = new NormalizedPath(fullPath); // When NormalizedPath rootRelative = path.RootRelative; // Then Assert.AreEqual(expected, rootRelative.FullPath); }
public void ShouldReturnRootPath(string fullPath, string expected) { // Given NormalizedPath path = new NormalizedPath(fullPath); // When NormalizedPath root = path.Root; // Then root.FullPath.ShouldBe(expected); }
public void EmptyPath() { // Given, When NormalizedPath path = new NormalizedPath(string.Empty); // Then path.FullPath.ShouldBe(string.Empty); path.Segments.ShouldBeEmpty(); path.IsAbsolute.ShouldBeFalse(); path.IsEmpty.ShouldBeTrue(); }
public void ShouldReturnFilenameWithoutExtensionFromPath(string fullPath, string expected) { // Given NormalizedPath path = new NormalizedPath(fullPath); // When NormalizedPath result = path.FileNameWithoutExtension; // Then Assert.AreEqual(expected, result.FullPath); }
public void ShouldThrowIfPathIsNull() { // Given NormalizedPath path = new NormalizedPath("assets"); // When TestDelegate test = () => path.Combine(null); // Then Assert.Throws <ArgumentNullException>(test); }
public void CanGetFilenameFromPath() { // Given NormalizedPath path = new NormalizedPath("/input/test.txt"); // When NormalizedPath result = path.FileName; // Then Assert.AreEqual("test.txt", result.FullPath); }
public void GetsFileNameIfJustFileName() { // Given NormalizedPath path = new NormalizedPath("test.txt"); // When NormalizedPath result = path.FileName; // Then Assert.AreEqual("test.txt", result.FullPath); }
public void CanInsertPrefixToPath(string path, string prefix, string expected) { // Given NormalizedPath filePath = new NormalizedPath(path); // When filePath = filePath.InsertPrefix(prefix); // Then Assert.AreEqual(expected, filePath.FullPath); }
public void ShouldThrowIfPRefixIsNull() { // Given NormalizedPath path = new NormalizedPath("temp/hello.txt"); // When TestDelegate test = () => path.InsertPrefix(null); // Then Assert.Throws <ArgumentNullException>(test); }
public void CanAppendExtensionToPath(string extension, string expected) { // Given NormalizedPath path = new NormalizedPath("temp/hello.txt"); // When path = path.AppendExtension(extension); // Then Assert.AreEqual(expected, path.ToString()); }
public void ShouldThrowIfExtensionIsNull() { // Given NormalizedPath path = new NormalizedPath("temp/hello.txt"); // When TestDelegate test = () => path.AppendExtension(null); // Then Assert.Throws <ArgumentNullException>(test); }
public void ShouldReturnNullIfOnlyExtension(string fullPath) { // Given NormalizedPath path = new NormalizedPath(fullPath); // When NormalizedPath result = path.FileNameWithoutExtension; // Then result.FullPath.ShouldBeEmpty(); }
public void ShouldCombinePaths(string first, string second, string expected) { // Given NormalizedPath path = new NormalizedPath(first); // When NormalizedPath result = path.Combine(new NormalizedPath(second)); // Then Assert.AreEqual(expected, result.FullPath); }
public void ShouldChangeFileName(string fullPath, string fileName, string expected) { // Given NormalizedPath path = new NormalizedPath(fullPath); // When NormalizedPath result = path.ChangeFileName(fileName); // Then result.FullPath.ShouldBe(expected); }
public void OptimizesInstance() { // Given NormalizedPath path = new NormalizedPath("a/b/c/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~:?#[]@!$&'()*+,;=.html"); // When NormalizedPath result = path.OptimizeFileName(); // Then result.FullPath.ShouldBe("a/b/c/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789.html"); }
public void ShouldReturnDirectoryName(string directoryPath, string name) { // Given NormalizedPath path = new NormalizedPath(directoryPath); // When string result = path.Name; // Then Assert.AreEqual(name, result); }
public void ShouldReturnEmptyRootForExplicitRelativePath(string fullPath) { // Given NormalizedPath path = new NormalizedPath(fullPath, PathKind.Relative); // When NormalizedPath root = path.Root; // Then root.FullPath.ShouldBeEmpty(); }
public void ReturnsParent(string directoryPath, string expected) { // Given NormalizedPath path = new NormalizedPath(directoryPath); // When NormalizedPath parent = path.Parent; // Then Assert.AreEqual(expected, parent.FullPath); }
public void CanGetExtension(string fullPath, string expected) { // Given NormalizedPath result = new NormalizedPath(fullPath); // When string extension = result.Extension; // Then Assert.AreEqual(expected, extension); }
public void RelativeRootDirectoryReturnsEmptyParent(string directoryPath) { // Given NormalizedPath path = new NormalizedPath(directoryPath); // When NormalizedPath parent = path.Parent; // Then parent.FullPath.ShouldBeEmpty(); }
public void CanGetDirectoryForFilePathInRoot() { // Given NormalizedPath path = new NormalizedPath("hello.txt"); // When NormalizedPath directory = path.Parent; // Then directory.FullPath.ShouldBeEmpty(); }
public void AbsoluteRootDirectoryReturnsNull(string directoryPath) { // Given NormalizedPath path = new NormalizedPath(directoryPath); // When NormalizedPath parent = path.Parent; // Then parent.FullPath.ShouldBeNull(); }
public void ShouldReturnSelfForExplicitRelativePath(string fullPath) { // Given NormalizedPath path = new NormalizedPath(fullPath, PathKind.Relative); // When NormalizedPath rootRelative = path.RootRelative; // Then Assert.AreEqual(path.FullPath, rootRelative.FullPath); }
NormalizedPath WriteProjectFolder(NormalizedPath folder, ICodeProject project) { folder = folder.AppendPart(project.ProjectName); Directory.CreateDirectory(folder); project.CreateRootElement().Save(folder.AppendPart(project.ProjectName + ".csproj")); using (var source = new StreamWriter(folder.AppendPart("Program.cs"))) { project.Code.WriteGlobalSource(source); } return(folder); }
public void AddsExtensionToEmptyPath(string extension) { // Given NormalizedPath path = NormalizedPath.Empty; // When path = path.ChangeExtension(extension); // Then path.FullPath.ShouldBe(".foo"); }
public LocalDirectory(NormalizedPath path) { path.ThrowIfNull(nameof(path)); if (path.IsRelative) { throw new ArgumentException("Path must be absolute", nameof(path)); } Path = path; _directory = new System.IO.DirectoryInfo(Path.FullPath); }
public UserHost(IBasicApplicationLifetime lifetime, NormalizedPath userHostPath) { Directory.CreateDirectory(userHostPath); ApplicationLifetime = lifetime; CommandRegister = new CommandRegister(); _xTypedObjectfactory = new XTypedFactory(); UserKeyVault = new UserKeyVault(userHostPath); _worldMapping = new SimpleWorldLocalMapping(userHostPath.AppendPart("WorldLocalMapping.txt")); _store = new GitWorldStore(userHostPath, _worldMapping, UserKeyVault.KeyStore, CommandRegister); WorldSelector = new WorldSelector(_store, CommandRegister, _xTypedObjectfactory, UserKeyVault.KeyStore, lifetime); CommandRegister.Register(this); }