Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs =================================================================== diff -u -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b -rb731017e828e47ed72aa803dfcc7eeaa7f770933 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs (.../GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs (.../GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs) (revision b731017e828e47ed72aa803dfcc7eeaa7f770933) @@ -19,14 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.IO; -using System.Linq; -using System.Security.AccessControl; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; -using Ringtoets.Common.IO.Exporters; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.IO.Exporters; using Ringtoets.GrassCoverErosionInwards.IO.Writers; @@ -35,31 +32,20 @@ { [TestFixture] public class GrassCoverErosionInwardsCalculationConfigurationExporterTest + : CustomCalculationConfigurationExporterDesignGuidelinesTestFixture< + GrassCoverErosionInwardsCalculationConfigurationExporter, + GrassCoverErosionInwardsCalculationConfigurationWriter, + GrassCoverErosionInwardsCalculation> { [Test] - public void Constructor_ExpectedValues() - { - // Call - var exporter = new GrassCoverErosionInwardsCalculationConfigurationExporter(Enumerable.Empty(), "test.xml"); - - // Assert - Assert.IsInstanceOf< - CalculationConfigurationExporter< - GrassCoverErosionInwardsCalculationConfigurationWriter, - GrassCoverErosionInwardsCalculation>>(exporter); - } - - [Test] public void Export_ValidData_ReturnTrueAndWritesFile() { // Setup - string filePath = TestHelper.GetScratchPadPath($"{nameof(Export_ValidData_ReturnTrueAndWritesFile)}.xml"); - - GrassCoverErosionInwardsCalculation calculation = new GrassCoverErosionInwardsCalculation + var calculation = new GrassCoverErosionInwardsCalculation { Name = "Berekening 1" }; - GrassCoverErosionInwardsCalculation calculation2 = new GrassCoverErosionInwardsCalculation + var calculation2 = new GrassCoverErosionInwardsCalculation { Name = "Berekening 2" }; @@ -81,61 +67,15 @@ } }; - var exporter = new GrassCoverErosionInwardsCalculationConfigurationExporter(new[] - { - calculationGroup - }, filePath); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationExporter), "folderWithSubfolderAndCalculation.xml")); - try + // Call and Assert + WriteAndValidate(new[] { - // Call - bool isExported = exporter.Export(); - - // Assert - Assert.IsTrue(isExported); - Assert.IsTrue(File.Exists(filePath)); - - string actualXml = File.ReadAllText(filePath); - string expectedXmlFilePath = TestHelper.GetTestDataPath( - TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, - Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationExporter), "folderWithSubfolderAndCalculation.xml")); - - string expectedXml = File.ReadAllText(expectedXmlFilePath); - - Assert.AreEqual(expectedXml, actualXml); - } - finally - { - File.Delete(filePath); - } + calculationGroup + }, expectedXmlFilePath); } - - [Test] - public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse() - { - // Setup - 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.xml"); - - var exporter = new GrassCoverErosionInwardsCalculationConfigurationExporter(new[] - { - new GrassCoverErosionInwardsCalculation() - }, filePath); - - disposeHelper.LockDirectory(FileSystemRights.Write); - - // Call - var isExported = true; - Action call = () => isExported = exporter.Export(); - - // Assert - string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " - + "Er is geen configuratie geƫxporteerd."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); - Assert.IsFalse(isExported); - } - } } } \ No newline at end of file