Index: Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs =================================================================== diff -u -rd74518566abeb501ea88b25f3111f9749853c5ed -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 --- Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs (.../SettingsHelper.cs) (revision d74518566abeb501ea88b25f3111f9749853c5ed) +++ Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs (.../SettingsHelper.cs) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -30,10 +30,10 @@ /// /// Class that defines helper methods related to user settings. /// - public class SettingsHelper + public class SettingsHelper : ISettingsHelper { private readonly string localSettingsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - private static SettingsHelper instance; + private static ISettingsHelper instance; /// /// Creates a new instance of . @@ -49,7 +49,7 @@ /// /// Gets the singleton instance of . /// - public static SettingsHelper Instance + public static ISettingsHelper Instance { get { Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r45440093089496f59ed420e772136756c229e30b -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 45440093089496f59ed420e772136756c229e30b) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -163,6 +163,10 @@ {f49bd8b2-332a-4c91-a196-8cce0a2c7d98} Core.Common.Utils + + {26214BD0-DAFB-4CFC-8EB2-80C5D53C859E} + Core.Common.Gui.TestUtil + {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil Index: Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs =================================================================== diff -u -r50962d0d185e4e52a634dd932590c02960ccf2b1 -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 --- Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs (.../SettingsHelperTest.cs) (revision 50962d0d185e4e52a634dd932590c02960ccf2b1) +++ Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs (.../SettingsHelperTest.cs) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -31,6 +31,18 @@ public class SettingsHelperTest { [Test] + public void Instance_CalledTwice_ReturnsSameInstance() + { + // Setup + ISettingsHelper expected = SettingsHelper.Instance; + + // Call + ISettingsHelper actual = SettingsHelper.Instance; + + // Assert + Assert.AreSame(expected, actual); + } + [Test] public void ApplicationName_ReturnsProductNameOfExecutingAssembly() { // Call Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 --- Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj (.../Core.Common.Gui.TestUtil.Test.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj (.../Core.Common.Gui.TestUtil.Test.csproj) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -52,6 +52,7 @@ Code + Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/Settings/TestSettingsHelperTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.TestUtil.Test/Settings/TestSettingsHelperTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.TestUtil.Test/Settings/TestSettingsHelperTest.cs (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -0,0 +1,148 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.IO; +using Core.Common.Gui.Settings; +using Core.Common.Gui.TestUtil.Settings; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Core.Common.Gui.TestUtil.Test.Settings +{ + [TestFixture] + public class TestSettingsHelperTest + { + [Test] + public void Constructor_ExpectedProperties() + { + // Call + var settingsHelper = new TestSettingsHelper(); + + // Assert + Assert.IsInstanceOf(settingsHelper); + Assert.IsEmpty(settingsHelper.ApplicationName); + Assert.IsEmpty(settingsHelper.ApplicationVersion); + } + + [Test] + public void GetApplicationLocalUserSettingsDirectory_NullPostfix_ReturnsRootFolder() + { + // Setup + var settingsHelper = new TestSettingsHelper(); + + // Call + string directory = settingsHelper.GetApplicationLocalUserSettingsDirectory(null); + + // Assert + string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Core.Common.Gui.Path); + Assert.AreEqual(testDataPath, directory); + } + + [Test] + public void GetApplicationLocalUserSettingsDirectoryWithExpectedDirectory_NullPostfix_ReturnsRootFolder() + { + // Setup + const string userSettingsDirectory = "someFolder"; + var settingsHelper = new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = userSettingsDirectory + }; + + // Call + string directory = settingsHelper.GetApplicationLocalUserSettingsDirectory(null); + + // Assert + Assert.AreEqual(userSettingsDirectory, directory); + } + + [Test] + public void GetApplicationLocalUserSettingsDirectory_WithPostfix_ReturnsRootFolderWithPostfix() + { + // Setup + var settingsHelper = new TestSettingsHelper(); + string postfix = Path.GetRandomFileName(); + + // Call + string directory = settingsHelper.GetApplicationLocalUserSettingsDirectory(postfix); + + // Assert + string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Core.Common.Gui.Path, postfix); + Assert.AreEqual(testDataPath, directory); + Assert.IsTrue(Directory.Exists(testDataPath)); + Directory.Delete(testDataPath); + } + + [Test] + public void GetApplicationLocalUserSettingsDirectoryWithExpectedDirectory_WithPostfix_ReturnsRootFolderWithPostfix() + { + // Setup + string postfix = Path.GetRandomFileName(); + const string userSettingsDirectory = "someFolder"; + var settingsHelper = new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = userSettingsDirectory + }; + + // Call + string directory = settingsHelper.GetApplicationLocalUserSettingsDirectory(postfix); + + // Assert + string testDataPath = Path.Combine(userSettingsDirectory, postfix); + Assert.AreEqual(testDataPath, directory); + Assert.IsTrue(Directory.Exists(testDataPath)); + Directory.Delete(testDataPath); + } + + [Test] + public void ApplicationName_WithExpectedSet_ReturnsExpected() + { + // Setup + const string expectedApplicationName = "some name"; + var settingsHelper = new TestSettingsHelper + { + ExpectedApplicationName = expectedApplicationName + }; + + // Call + string applicationName = settingsHelper.ApplicationName; + + // Assert + Assert.AreEqual(expectedApplicationName, applicationName); + } + + [Test] + public void ApplicationVersion_WithExpectedSet_ReturnsExpected() + { + // Setup + const string expectedApplicationVersion = "some version"; + var settingsHelper = new TestSettingsHelper + { + ExpectedApplicationVersion = expectedApplicationVersion + }; + + // Call + string applicationVersion = settingsHelper.ApplicationVersion; + + // Assert + Assert.AreEqual(expectedApplicationVersion, applicationVersion); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.TestUtil/Core.Common.Gui.TestUtil.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -rf3e15928caffd4336c97f5fa3de495a5a05bf6b8 --- Core/Common/test/Core.Common.Gui.TestUtil/Core.Common.Gui.TestUtil.csproj (.../Core.Common.Gui.TestUtil.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Core/Common/test/Core.Common.Gui.TestUtil/Core.Common.Gui.TestUtil.csproj (.../Core.Common.Gui.TestUtil.csproj) (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -87,12 +87,17 @@ + {30E4C2AE-719E-4D70-9FA9-668A9767FBFA} Core.Common.Gui + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + Index: Core/Common/test/Core.Common.Gui.TestUtil/Settings/TestSettingsHelper.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.TestUtil/Settings/TestSettingsHelper.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.TestUtil/Settings/TestSettingsHelper.cs (revision f3e15928caffd4336c97f5fa3de495a5a05bf6b8) @@ -0,0 +1,98 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.IO; +using Core.Common.Gui.Settings; +using Core.Common.TestUtil; + +namespace Core.Common.Gui.TestUtil.Settings +{ + /// + /// A implementation suitable for unit testing purposes. + /// + public class TestSettingsHelper : ISettingsHelper + { + /// + /// Creates a new instance of . + /// + public TestSettingsHelper() + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Common.Gui.Path); + ApplicationName = string.Empty; + ApplicationVersion = string.Empty; + } + + /// + /// Sets the . + /// + public string ExpectedApplicationName + { + set + { + ApplicationName = value; + } + } + + /// + /// Sets the . + /// + public string ExpectedApplicationVersion + { + set + { + ApplicationVersion = value; + } + } + + /// + /// Gets or sets the directory to use in . + /// + public string ExpectedApplicationLocalUserSettingsDirectory { private get; set; } + + public string ApplicationName { get; private set; } + + public string ApplicationVersion { get; private set; } + + public string GetApplicationLocalUserSettingsDirectory(string postfix) + { + var settingsDirectoryPath = string.IsNullOrWhiteSpace(postfix) + ? ExpectedApplicationLocalUserSettingsDirectory + : Path.Combine(ExpectedApplicationLocalUserSettingsDirectory, postfix); + + if (Directory.Exists(settingsDirectoryPath)) + { + return settingsDirectoryPath; + } + + try + { + Directory.CreateDirectory(settingsDirectoryPath); + } + catch (Exception e) + { + var message = $"Unable to create '{settingsDirectoryPath}'"; + throw new IOException(message, e); + } + return settingsDirectoryPath; + } + } +} \ No newline at end of file