private string GetInitialDirectory() { var selectedFile = SelectedFile; var isSelectedRootedPath = !string.IsNullOrWhiteSpace(selectedFile) && System.IO.Path.IsPathRooted(selectedFile); string result = null; if (isSelectedRootedPath) { result = Path.GetParentDirectory(selectedFile); } if (!string.IsNullOrWhiteSpace(result) && Directory.Exists(result)) { return(result); } result = BaseDirectory; if (!string.IsNullOrWhiteSpace(result) && Directory.Exists(result)) { return(result); } return(string.Empty); }
private string GetUpdateExecutable() { var entryAssemblyDirectory = AssemblyHelper.GetEntryAssembly().GetDirectory(); var updateExe = Path.GetFullPath(UpdateExe, entryAssemblyDirectory); return(updateExe); }
private void UpdateSelectedFileDisplayName() { var selectedFile = SelectedFile; if (string.IsNullOrWhiteSpace(selectedFile) || !System.IO.Path.IsPathRooted(selectedFile)) { SelectedFileDisplayName = string.Empty; return; } var baseDirectory = BaseDirectory; if (string.IsNullOrWhiteSpace(baseDirectory) || !Directory.Exists(baseDirectory)) { SelectedFileDisplayName = selectedFile; return; } var selectedFileRoot = System.IO.Path.GetPathRoot(selectedFile); var baseDirectoryRoot = System.IO.Path.GetPathRoot(baseDirectory); if (!string.Equals(selectedFileRoot, baseDirectoryRoot, StringComparison.OrdinalIgnoreCase)) { SelectedFileDisplayName = selectedFile; return; } SelectedFileDisplayName = Path.GetRelativePath(selectedFile, baseDirectory); }
public void CombineUrls_NoValues() { // Call method string result = Path.CombineUrls(); // Validate Assert.AreEqual(@"", result); }
private string GetExampleFileName(string relativeFileName) { var rootDirectory = AssemblyDirectoryHelper.GetCurrentDirectory(); var path = Path.Combine(rootDirectory, "Models", relativeFileName); return(path); }
protected virtual string GetSnapshotFileName(string directory, ISnapshot snapshot) { Argument.IsNotNull(() => snapshot); var snapshotFile = Path.Combine(directory, $"{snapshot.Title.GetSlug()}{SnapshotExtension}"); return(snapshotFile); }
public void GetApplicationDataDirectory_CompanyAndApp() { string expected = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Assembly.GetExecutingAssembly().Company(), Assembly.GetExecutingAssembly().Product()); string result = Path.GetApplicationDataDirectory(Assembly.GetExecutingAssembly().Company(), Assembly.GetExecutingAssembly().Product()); Assert.AreEqual(expected, result); }
public KeyboardMappingsService(ICommandManager commandManager, IXmlSerializer xmlSerializer) { Argument.IsNotNull(() => commandManager); Argument.IsNotNull(() => xmlSerializer); _commandManager = commandManager; _xmlSerializer = xmlSerializer; _fileName = Path.Combine(Path.GetApplicationDataDirectory(), "keyboardmappings.xml"); }
public void GetApplicationDataDirectoryForAllUsers_AppOnly() { string expected = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Assembly.GetExecutingAssembly().Product()); string result = Path.GetApplicationDataDirectoryForAllUsers(Assembly.GetExecutingAssembly().Product()); Assert.AreEqual(expected, result); }
private static string GetLogDirectory() { var appDataService = ServiceLocator.Default.ResolveType <IAppDataService>(); var directory = Path.Combine(appDataService.GetApplicationDataDirectory(Catel.IO.ApplicationDataTarget.UserRoaming), "log"); Directory.CreateDirectory(directory); return(directory); }
public FileSystemSnapshotStorageService(IDirectoryService directoryService, IFileService fileService) { Argument.IsNotNull(() => directoryService); Argument.IsNotNull(() => fileService); _directoryService = directoryService; _fileService = fileService; Directory = Path.Combine(Path.GetApplicationDataDirectory(), "snapshots"); }
public void CombineUrls_1Value() { // Declare variables string path1 = @"http://www.catenalogic.com"; // Call method string result = Path.CombineUrls(path1); // Validate Assert.AreEqual(@"http://www.catenalogic.com", result); }
public void CombinePath_1Value() { // Declare variables string path1 = @"C:\Windows"; // Call method string result = Path.Combine(path1); // Validate Assert.AreEqual(@"C:\Windows", result); }
public void AppendTrailingBackslash_WithTrailingBackslash() { // Declare variables string path = @"C:\Windows\"; // Call method string result = Path.AppendTrailingSlash(path); // Validate Assert.AreEqual(@"C:\Windows\", result); }
public void AppendTrailingSlash_WithTrailingSlash() { // Declare variables string path = @"http://www.catenalogic.com/"; // Call method string result = Path.AppendTrailingSlash(path, '/'); // Validate Assert.AreEqual(@"http://www.catenalogic.com/", result); }
public void GetFileName_WithoutDirectory() { // Declare variables string input = @"notepad.exe"; string expectedOutput = "notepad.exe"; // Call method string output = Path.GetFileName(input); // Check result Assert.AreEqual(expectedOutput, output); }
public void GetParentDirectory_DirectoryNotEndingWithSlash() { // Declare variables string input = @"C:\MyPathThatDoesntExist\MyDirectory"; string expectedOutput = @"C:\MyPathThatDoesntExist"; // Call method string output = Path.GetParentDirectory(input); // Check result Assert.AreEqual(expectedOutput, output); }
public void CombineUrls_2Values() { // Declare variables string path1 = @"http://www.catenalogic.com"; string path2 = @"products"; // Call method string result = Path.CombineUrls(path1, path2); // Validate Assert.AreEqual(@"http://www.catenalogic.com/products", result); }
public void GetParentDirectory_EmptyInput() { // Declare variables string input = @""; string expectedOutput = @""; // Call method string output = Path.GetParentDirectory(input); // Check result Assert.AreEqual(expectedOutput, output); }
public void GetRelativePath_SameDirectoryLevelWithDifferentName() { // Declare variables string file = @"C:\Windows\MyTest\MyFile.exe"; string path = @"C:\Windows\MyTes"; // Call method string relative = Path.GetRelativePath(file, path); // Validate Assert.AreEqual(@"..\MyTest\MyFile.exe".ToLower(), relative.ToLower()); }
public void GetFullPath_RelativeDotsAndNameDirectory() { // Declare variables string file = @"..\Windows\notepad.exe"; string path = @"C:\Program Files\"; // Call method string full = Path.GetFullPath(file, path); // Validate Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), full.ToLower()); }
public void GetFullPath_FromRootDirectory() { // Declare variables string file = @"Windows\notepad.exe"; string path = @"C:\"; // Call method string full = Path.GetFullPath(file, path); // Validate Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), full.ToLower()); }
public void GetRelativePath_SingleDirectoryNotEndingWithSlash() { // Declare variables string file = @"C:\Windows\notepad.exe"; string path = @"C:\Windows"; // Call method string relative = Path.GetRelativePath(file, path); // Validate Assert.AreEqual(@"notepad.exe".ToLower(), relative.ToLower()); }
public void GetRelativePath_HigherDirectory() { // Declare variables string file = @"C:\Windows\"; string path = @"C:\Windows\Level1\Level2"; // Call method string relative = Path.GetRelativePath(file, path); // Validate Assert.AreEqual(@"..\..".ToLower(), relative.ToLower()); }
private string GetUpdateExecutable() { if (string.IsNullOrWhiteSpace(_updateExeLocation)) { var entryAssemblyDirectory = AssemblyHelper.GetEntryAssembly().GetDirectory(); _updateExeLocation = Path.GetFullPath(UpdateExe, entryAssemblyDirectory); Log.Debug($"Determined update executable path '{_updateExeLocation}', exists: {_fileService.Exists(_updateExeLocation)}"); } return(_updateExeLocation); }
public void GetRelativePath_DifferentRoot() { // Declare variables string file = @"C:\Windows\notepad.exe"; string path = @"D:\Windows\"; // Call method string relative = Path.GetRelativePath(file, path); // Validate Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), relative.ToLower()); }
public void GetRelativePath_DeeperDirectory() { // Declare variables string file = @"C:\Windows\notepad.exe"; string path = @"C:\Windows\Temp\"; // Call method string relative = Path.GetRelativePath(file, path); // Validate Assert.AreEqual(@"..\notepad.exe".ToLower(), relative.ToLower()); }
public void GetFullPath_FileNameOnlyAndDirectoryWithoutTrailingSlash() { // Declare variables string file = @"notepad.exe"; string path = @"C:\Windows"; // Call method string full = Path.GetFullPath(file, path); // Validate Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), full.ToLower()); }
private static string GetWindowStorageFile(this Window window) { Argument.IsNotNull(() => window); var appData = Path.GetApplicationDataDirectory(); var directory = Path.Combine(appData, "windows"); Directory.CreateDirectory(directory); var file = Path.Combine(directory, $"{window.GetType().FullName}.dat"); return(file); }
public void CombineUrls_3ValuesAnd1Empty() { // Declare variables string path1 = @"/products"; string path2 = @""; string path3 = @"/default.aspx"; // Call method string result = Path.CombineUrls(path1, path2, path3); // Validate Assert.AreEqual(@"/products/default.aspx", result); }