Index: Core/Common/src/Core.Common.Gui/Settings/ISettingsHelper.cs =================================================================== diff -u -rd74518566abeb501ea88b25f3111f9749853c5ed -r1c29823d3914c54b0b85d4787a80b68be804f523 --- Core/Common/src/Core.Common.Gui/Settings/ISettingsHelper.cs (.../ISettingsHelper.cs) (revision d74518566abeb501ea88b25f3111f9749853c5ed) +++ Core/Common/src/Core.Common.Gui/Settings/ISettingsHelper.cs (.../ISettingsHelper.cs) (revision 1c29823d3914c54b0b85d4787a80b68be804f523) @@ -41,9 +41,9 @@ /// /// Gets the application local user settings directory. /// - /// The postfix path to use after the local application data folder (if any). + /// The sub path to use after the local application data folder (if any). /// Directory path where the user settings can be found. /// Thrown when the application local user settings directory could not be created. - string GetApplicationLocalUserSettingsDirectory(string postfix); + string GetApplicationLocalUserSettingsDirectory(params string[] subPath); } } \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs =================================================================== diff -u -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 -r1c29823d3914c54b0b85d4787a80b68be804f523 --- Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs (.../SettingsHelper.cs) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) +++ Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs (.../SettingsHelper.cs) (revision 1c29823d3914c54b0b85d4787a80b68be804f523) @@ -20,8 +20,10 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using Core.Common.Gui.Properties; using Core.Common.Utils.Reflection; @@ -64,23 +66,33 @@ /// /// Gets the name of the application. /// - public string ApplicationName { get; private set; } + public string ApplicationName { get; } /// /// Gets the version of the application. /// - public string ApplicationVersion { get; private set; } + public string ApplicationVersion { get; } /// /// Gets the application local user settings directory. /// - /// The postfix path to use after the local application data folder (if any). + /// The postfix path to use after the local application data folder (if any). /// Directory path where the user settings can be found. /// Thrown when the application local user settings directory could not be created. - public string GetApplicationLocalUserSettingsDirectory(string postfix) + public string GetApplicationLocalUserSettingsDirectory(params string[] subPath) { - var appSettingsDirectoryPath = string.IsNullOrWhiteSpace(postfix) ? localSettingsDirectoryPath : Path.Combine(localSettingsDirectoryPath, postfix); + var directorypath = new List + { + localSettingsDirectoryPath + }; + if (subPath != null) + { + directorypath.AddRange(subPath.ToList()); + } + + string appSettingsDirectoryPath = Path.Combine(directorypath.ToArray()); + if (Directory.Exists(appSettingsDirectoryPath)) { return appSettingsDirectoryPath; Index: Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs =================================================================== diff -u -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 -r1c29823d3914c54b0b85d4787a80b68be804f523 --- Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs (.../SettingsHelperTest.cs) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) +++ Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs (.../SettingsHelperTest.cs) (revision 1c29823d3914c54b0b85d4787a80b68be804f523) @@ -42,6 +42,7 @@ // Assert Assert.AreSame(expected, actual); } + [Test] public void ApplicationName_ReturnsProductNameOfExecutingAssembly() { @@ -63,21 +64,36 @@ } [Test] - [TestCase(null)] - [TestCase("")] - [TestCase(" ")] - [TestCase("some directory name")] - public void GetApplicationLocalUserSettingsDirectory_VariousPostfixes_ReturnsApplicationLocalUserSettingsDirectory(string postfix) + public void GetApplicationLocalUserSettingsDirectory_WithoutSubFolder_ReturnsApplicationLocalUserSettingsDirectory() { - // Setup + // Call + var pathFromSettings = SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(); + + // Assert var localSettingsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - var appSettingsDirectoryPath = string.IsNullOrWhiteSpace(postfix) ? localSettingsDirectoryPath : Path.Combine(localSettingsDirectoryPath, postfix); + Assert.AreEqual(localSettingsDirectoryPath, pathFromSettings); + } + [Test] + public void GetApplicationLocalUserSettingsDirectoryWithExpectedDirectory_WithPostfix_ReturnsRootFolderWithPostfix() + { + // Setup + string subFolder = Path.GetRandomFileName(); + string subSubFolder = Path.GetRandomFileName(); + // Call - var pathFromSettings = SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(postfix); + string directory = SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(subFolder, subSubFolder); // Assert - Assert.AreEqual(appSettingsDirectoryPath, pathFromSettings); + string userSettingsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + + string testDataPath = Path.Combine(userSettingsDirectory, subFolder, subSubFolder); + Assert.AreEqual(testDataPath, directory); + + string testDataPathParent = Path.Combine(userSettingsDirectory, subFolder); + Assert.IsTrue(Directory.Exists(testDataPathParent)); + Assert.IsTrue(Directory.Exists(testDataPath)); + Directory.Delete(testDataPathParent, true); } [Test] Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/Settings/TestSettingsHelperTest.cs =================================================================== diff -u -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 -r1c29823d3914c54b0b85d4787a80b68be804f523 --- Core/Common/test/Core.Common.Gui.TestUtil.Test/Settings/TestSettingsHelperTest.cs (.../TestSettingsHelperTest.cs) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) +++ Core/Common/test/Core.Common.Gui.TestUtil.Test/Settings/TestSettingsHelperTest.cs (.../TestSettingsHelperTest.cs) (revision 1c29823d3914c54b0b85d4787a80b68be804f523) @@ -94,21 +94,25 @@ public void GetApplicationLocalUserSettingsDirectoryWithExpectedDirectory_WithPostfix_ReturnsRootFolderWithPostfix() { // Setup - string postfix = Path.GetRandomFileName(); + string subFolder = Path.GetRandomFileName(); + string subSubFolder = Path.GetRandomFileName(); const string userSettingsDirectory = "someFolder"; var settingsHelper = new TestSettingsHelper { ExpectedApplicationLocalUserSettingsDirectory = userSettingsDirectory }; // Call - string directory = settingsHelper.GetApplicationLocalUserSettingsDirectory(postfix); + string directory = settingsHelper.GetApplicationLocalUserSettingsDirectory(subFolder, subSubFolder); // Assert - string testDataPath = Path.Combine(userSettingsDirectory, postfix); + string testDataPath = Path.Combine(userSettingsDirectory, subFolder, subSubFolder); Assert.AreEqual(testDataPath, directory); + + string testDataPathParent = Path.Combine(userSettingsDirectory, subFolder); + Assert.IsTrue(Directory.Exists(testDataPathParent)); Assert.IsTrue(Directory.Exists(testDataPath)); - Directory.Delete(testDataPath); + Directory.Delete(testDataPathParent, true); } [Test] Index: Core/Common/test/Core.Common.Gui.TestUtil/Settings/TestSettingsHelper.cs =================================================================== diff -u -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 -r1c29823d3914c54b0b85d4787a80b68be804f523 --- Core/Common/test/Core.Common.Gui.TestUtil/Settings/TestSettingsHelper.cs (.../TestSettingsHelper.cs) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) +++ Core/Common/test/Core.Common.Gui.TestUtil/Settings/TestSettingsHelper.cs (.../TestSettingsHelper.cs) (revision 1c29823d3914c54b0b85d4787a80b68be804f523) @@ -20,7 +20,9 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using Core.Common.Gui.Settings; using Core.Common.TestUtil; @@ -72,12 +74,20 @@ public string ApplicationVersion { get; private set; } - public string GetApplicationLocalUserSettingsDirectory(string postfix) + public string GetApplicationLocalUserSettingsDirectory(params string[] subPath) { - var settingsDirectoryPath = string.IsNullOrWhiteSpace(postfix) - ? ExpectedApplicationLocalUserSettingsDirectory - : Path.Combine(ExpectedApplicationLocalUserSettingsDirectory, postfix); + var directorypath = new List + { + ExpectedApplicationLocalUserSettingsDirectory + }; + if (subPath != null) + { + directorypath.AddRange(subPath.ToList()); + } + + string settingsDirectoryPath = Path.Combine(directorypath.ToArray()); + if (Directory.Exists(settingsDirectoryPath)) { return settingsDirectoryPath;