Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs =================================================================== diff -u -r69eb17523e5ae490637e29718a4a563cbcaacc3c -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision 69eb17523e5ae490637e29718a4a563cbcaacc3c) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -22,8 +22,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Security.AccessControl; using System.Xml; using Core.Common.Base.Data; using Core.Common.IO.Exceptions; @@ -34,107 +32,18 @@ using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.Common.IO.Writers; namespace Ringtoets.Common.IO.Test.Writers { [TestFixture] public class CalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + SimpleCalculationConfigurationWriter, + TestCalculation> { [Test] - public void Write_ConfigurationNull_ThrowArgumentNullException() - { - // Call - TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(null, string.Empty); - - // Assert - var exception = Assert.Throws(test); - Assert.AreEqual("configuration", exception.ParamName); - } - - [Test] - public void Write_FilePathNull_ThrowArgumentNullException() - { - // Call - TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), null); - - // Assert - var exception = Assert.Throws(test); - Assert.AreEqual("filePath", exception.ParamName); - } - - [Test] - [TestCase("")] - [TestCase(" ")] - [TestCase("c:\\>")] - public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) - { - // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), filePath); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); - } - - [Test] - public void Write_FilePathTooLong_ThrowCriticalFileWriteException() - { - // Setup - var filePath = new string('a', 249); - - // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), filePath); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); - } - - [Test] - public void Write_InvalidDirectoryRights_ThrowCriticalFileWriteException() - { - // Setup - const string testName = nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException); - string directoryPath = TestHelper.GetScratchPadPath(testName); - using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), testName)) - { - string filePath = Path.Combine(directoryPath, "test.xml"); - disposeHelper.LockDirectory(FileSystemRights.Write); - - // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), filePath); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); - } - } - - [Test] - public void Write_FileInUse_ThrowCriticalFileWriteException() - { - // Setup - string path = TestHelper.GetScratchPadPath(nameof(Write_FileInUse_ThrowCriticalFileWriteException)); - - using (var fileDisposeHelper = new FileDisposeHelper(path)) - { - fileDisposeHelper.LockFiles(); - - // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), path); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{path}'.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); - } - } - - [Test] public void WriteDistribution_WithoutDistributions_ArgumentNullException() { // Setup @@ -375,26 +284,6 @@ }); } - public class SimpleCalculationConfigurationWriter : CalculationConfigurationWriter - { - public const string CalculationElementTag = "calculation"; - - public void PublicWriteDistributions(IDictionary distributions, XmlWriter writer) - { - WriteDistributions(distributions, writer); - } - - public void PublicWriteBreakWaterProperties(BreakWater breakWater, XmlWriter writer) - { - WriteBreakWaterProperties(breakWater, writer); - } - - protected override void WriteCalculation(TestCalculation calculation, XmlWriter writer) - { - writer.WriteElementString(CalculationElementTag, calculation.Name); - } - } - private static IEnumerable GetCalculationConfigurations() { var calculation1 = new TestCalculation("calculation1"); @@ -442,4 +331,24 @@ .SetName("Calculation and group with nesting"); } } + + public class SimpleCalculationConfigurationWriter : CalculationConfigurationWriter + { + public const string CalculationElementTag = "calculation"; + + public void PublicWriteDistributions(IDictionary distributions, XmlWriter writer) + { + WriteDistributions(distributions, writer); + } + + public void PublicWriteBreakWaterProperties(BreakWater breakWater, XmlWriter writer) + { + WriteBreakWaterProperties(breakWater, writer); + } + + protected override void WriteCalculation(TestCalculation calculation, XmlWriter writer) + { + writer.WriteElementString(CalculationElementTag, calculation.Name); + } + } } \ No newline at end of file