Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.IO.Test/DuneLocationsExporterTest.cs =================================================================== diff -u -rd18995d638a6c3f99cb7a8419107bb4148420301 -r28ab332db2d96ad9e766f19677af1c00fc88a644 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.IO.Test/DuneLocationsExporterTest.cs (.../DuneLocationsExporterTest.cs) (revision d18995d638a6c3f99cb7a8419107bb4148420301) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.IO.Test/DuneLocationsExporterTest.cs (.../DuneLocationsExporterTest.cs) (revision 28ab332db2d96ad9e766f19677af1c00fc88a644) @@ -40,7 +40,7 @@ public void Constructor_ExpectedValues() { // Setup - var filePath = TestHelper.GetScratchPadPath(Path.Combine("DuneLocationsExporter", "test.bnd")); + var filePath = TestHelper.GetScratchPadPath(Path.Combine(nameof(DuneLocationsExporterTest), "test.bnd")); // Call var exporter = new DuneLocationsExporter(Enumerable.Empty(), filePath); @@ -52,11 +52,8 @@ [Test] public void Constructor_LocationsNull_ThrowArgumentNullException() { - // Setup - var filePath = TestHelper.GetScratchPadPath(Path.Combine("DuneLocationsExporter", "test.bnd")); - // Call - TestDelegate test = () => new DuneLocationsExporter(null, filePath); + TestDelegate test = () => new DuneLocationsExporter(null, "IAmValid.bnd"); // Assert var exception = Assert.Throws(test); @@ -95,14 +92,13 @@ locationCalculatedOutput }; - string directoryPath = TestHelper.GetScratchPadPath("Export_ValidData_ReturnTrue"); - Directory.CreateDirectory(directoryPath); - string filePath = Path.Combine(directoryPath, "test.bnd"); + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_ValidData_ReturnTrueAndWritesFile)); + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_ValidData_ReturnTrueAndWritesFile))) + { + string filePath = Path.Combine(directoryPath, "test.bnd"); - var exporter = new DuneLocationsExporter(duneLocations, filePath); + var exporter = new DuneLocationsExporter(duneLocations, filePath); - try - { // Call bool isExported = exporter.Export(); @@ -117,10 +113,6 @@ "11\t9771.3\t5.89\t8.53\t14.11\t*\t0.000134\r\n", fileContent); } - finally - { - Directory.Delete(directoryPath, true); - } } [Test] @@ -139,31 +131,24 @@ } }; - string directoryPath = TestHelper.GetScratchPadPath("Export_InvalidDirectoryRights_LogErrorAndReturnFalse"); - Directory.CreateDirectory(directoryPath); - string filePath = Path.Combine(directoryPath, "test.bnd"); + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse)); + using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse))) + { + string filePath = Path.Combine(directoryPath, "test.bnd"); + var exporter = new DuneLocationsExporter(duneLocations, filePath); - var exporter = new DuneLocationsExporter(duneLocations, filePath); + disposeHelper.LockDirectory(FileSystemRights.Write); + bool isExported = true; - try - { - using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write)) - { - // Call - bool isExported = true; - Action call = () => isExported = exporter.Export(); + // Call + Action call = () => isExported = exporter.Export(); - // Assert - string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " - + "Er zijn geen hydraulische randvoorwaarden locaties geƫxporteerd."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); - Assert.IsFalse(isExported); - } + // Assert + string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " + + "Er zijn geen hydraulische randvoorwaarden locaties geƫxporteerd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + Assert.IsFalse(isExported); } - finally - { - Directory.Delete(directoryPath, true); - } } private static DuneLocationOutput CreateDuneLocationOutputForExport(double waterLevel, double wavePeriod, double waveHeight)