Index: Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs =================================================================== diff -u -rbb0308b863b1f9b65a349c4291e1d44944ebf805 -rf4bdeb639e4a7a0bdb6442f6238285cc9cee4d6c --- Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs (.../TestHelperTest.cs) (revision bb0308b863b1f9b65a349c4291e1d44944ebf805) +++ Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs (.../TestHelperTest.cs) (revision f4bdeb639e4a7a0bdb6442f6238285cc9cee4d6c) @@ -80,6 +80,88 @@ } [Test] + public void GetScratchPadPath_WithoutPath_ReturnRootFolder() + { + // Call + string actualPath = TestHelper.GetScratchPadPath(); + + // Assert + var expectedPath = Path.Combine(TestHelper.SolutionRoot, "Scratchpad"); + Assert.AreEqual(expectedPath, actualPath); + Assert.IsTrue(Directory.Exists(actualPath), + $"The directory '{expectedPath}' should exist, such that unit tests have a clean environment to temporarily write files and directories to."); + } + + + [Test] + public void GetScratchPadPath_WithoutPathAndFolderDoesntExist_ThrowIOException() + { + // Setup + string actualPath = TestHelper.GetScratchPadPath(); + + Directory.Delete(actualPath, true); + + try + { + // Call + TestDelegate call = () => TestHelper.GetScratchPadPath(); + + // Assert + string message = Assert.Throws(call).Message; + const string expectedMessage = "The 'Scratchpad' folder has been deleted from the trunk, while tests require the existence of this folder for writing to disk temporarily."; + Assert.AreEqual(expectedMessage, message); + } + finally + { + Directory.CreateDirectory(actualPath); + } + } + + [Test] + public void GetScratchPadPath_WithSubPath_ReturnPathInScratchPad() + { + // Setup + string subPath = Path.Combine("test", "1.234"); + + // Call + string actualPath = TestHelper.GetScratchPadPath(subPath); + + // Assert + var expectedPath = Path.Combine(TestHelper.SolutionRoot, "Scratchpad", subPath); + Assert.AreEqual(expectedPath, actualPath); + Assert.IsFalse(File.Exists(actualPath), + $"The file '{expectedPath}' should not exist, as the folder should always be empty at the start of any unit test."); + Assert.IsFalse(Directory.Exists(actualPath), + $"The directory '{expectedPath}' should not exist, as the folder should always be empty at the start of any unit test."); + } + + [Test] + public void GetScratchPadPath_WithSubPathAndScratchPadFolderDoesntExist_ThrowIOException() + { + // Setup + string actualPath = TestHelper.GetScratchPadPath(); + + Directory.Delete(actualPath, true); + + try + { + string subPath = Path.Combine("test", "1.234"); + + // Call + TestDelegate call = () => TestHelper.GetScratchPadPath(subPath); + + // Assert + string message = Assert.Throws(call).Message; + const string expectedMessage = "The 'Scratchpad' folder has been deleted from the trunk, while tests require the existence of this folder for writing to disk temporarily."; + Assert.AreEqual(expectedMessage, message); + } + finally + { + Directory.CreateDirectory(actualPath); + } + } + + [Test] public void GetTestDataPath_Always_VerifiedTestPaths() { string path = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Storage); Index: Core/Common/test/Core.Common.TestUtil/TestHelper.cs =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -rf4bdeb639e4a7a0bdb6442f6238285cc9cee4d6c --- Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision f4bdeb639e4a7a0bdb6442f6238285cc9cee4d6c) @@ -48,6 +48,36 @@ } /// + /// Returns the location on disk that can be used safely for writing to disk temporarily. + /// + /// The folder path. + /// Caller is responsible for cleaning up files put in the folder. + /// Thrown when the folder doesn't exist. + /// + public static string GetScratchPadPath() + { + string scratchPadPath = Path.Combine(Path.GetDirectoryName(SolutionRoot), "Scratchpad"); + if (!Directory.Exists(scratchPadPath)) + { + throw new IOException("The 'Scratchpad' folder has been deleted from the trunk, while tests require the existence of this folder for writing to disk temporarily."); + } + return scratchPadPath; + } + + /// + /// Returns the location on disk that can be used safely for writing to disk temporarily. + /// + /// The filepath or folderpath inside the 'scratchpad' folder. + /// The folder path. + /// Caller is responsible for cleaning up files put in the folder. + /// Thrown when the folder doesn't exist. + /// + public static string GetScratchPadPath(string path) + { + return Path.Combine(GetScratchPadPath(), path); + } + + /// /// Returns a full path to a test data directory given the . /// /// The path to construct a full test data path for.