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 Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/CustomCalculationConfigurationWriterDesignGuidelinesTestFixture.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/CustomCalculationConfigurationWriterDesignGuidelinesTestFixture.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/CustomCalculationConfigurationWriterDesignGuidelinesTestFixture.cs (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -0,0 +1,179 @@ +// 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 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 General Public License for more details. +// +// You should have received a copy of the GNU 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 System.Linq; +using System.Security.AccessControl; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Writers; + +namespace Ringtoets.Common.IO.TestUtil +{ + [TestFixture] + public abstract class CustomCalculationConfigurationWriterDesignGuidelinesTestFixture + where TCalculation : class, ICalculation + where TWriter : CalculationConfigurationWriter, new() + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var writer = new TWriter(); + + // Assert + AssertDefaultConstructedInstance(writer); + } + + [Test] + public void Write_ConfigurationNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new TWriter().Write(null, string.Empty); + + // Assert + ArgumentNullException exception = Assert.Throws(test); + AssertNullConfiguration(exception); + } + + [Test] + public void Write_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new TWriter().Write(Enumerable.Empty(), null); + + // Assert + ArgumentNullException exception = Assert.Throws(test); + AssertNullFilePath(exception); + } + + [Test] + [TestCaseSource(typeof(InvalidPathHelper), nameof(InvalidPathHelper.InvalidPaths))] + public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) + { + // Call + TestDelegate call = () => new TWriter().Write(Enumerable.Empty(), filePath); + + // Assert + CriticalFileWriteException exception = Assert.Throws(call); + AssertInvalidFilePath(exception, filePath); + } + + [Test] + public void Write_FilePathTooLong_ThrowCriticalFileWriteException() + { + // Setup + var filePath = new string('a', 249); + + // Call + TestDelegate call = () => new TWriter().Write(Enumerable.Empty(), filePath); + + // Assert + CriticalFileWriteException exception = Assert.Throws(call); + AssertTooLongPath(exception, filePath); + } + + [Test] + public void Write_InvalidDirectoryRights_ThrowCriticalFileWriteException() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException)); + using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException))) + { + string filePath = Path.Combine(directoryPath, "test.xml"); + disposeHelper.LockDirectory(FileSystemRights.Write); + + // Call + TestDelegate call = () => new TWriter().Write(Enumerable.Empty(), filePath); + + // Assert + CriticalFileWriteException exception = Assert.Throws(call); + AssertInvalidDirectoryRights(exception, filePath); + } + } + + [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 TWriter().Write(Enumerable.Empty(), path); + + // Assert + CriticalFileWriteException exception = Assert.Throws(call); + AssertFileInUse(exception, path); + } + } + + protected virtual void AssertDefaultConstructedInstance(TWriter writer) + { + Assert.IsInstanceOf>(writer); + } + + protected virtual void AssertNullConfiguration(ArgumentNullException exception) + { + Assert.IsNotNull(exception); + Assert.AreEqual("configuration", exception.ParamName); + } + + protected virtual void AssertNullFilePath(ArgumentNullException exception) + { + Assert.IsNotNull(exception); + Assert.AreEqual("filePath", exception.ParamName); + } + + protected virtual void AssertInvalidFilePath(CriticalFileWriteException exception, string filePath) + { + Assert.IsNotNull(exception); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + } + + protected virtual void AssertTooLongPath(CriticalFileWriteException exception, string filePath) + { + Assert.IsNotNull(exception); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + protected virtual void AssertInvalidDirectoryRights(CriticalFileWriteException exception, string filePath) + { + Assert.IsNotNull(exception); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + protected virtual void AssertFileInUse(CriticalFileWriteException exception, string filePath) + { + Assert.IsNotNull(exception); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj =================================================================== diff -u -rb731017e828e47ed72aa803dfcc7eeaa7f770933 -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision b731017e828e47ed72aa803dfcc7eeaa7f770933) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -38,10 +38,6 @@ ..\..\..\..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll True - - ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll - True - @@ -50,6 +46,7 @@ Properties\GlobalAssembly.cs + @@ -63,6 +60,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/packages.config =================================================================== diff -u -rb731017e828e47ed72aa803dfcc7eeaa7f770933 -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/packages.config (.../packages.config) (revision b731017e828e47ed72aa803dfcc7eeaa7f770933) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/packages.config (.../packages.config) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -23,5 +23,4 @@ --> - \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs =================================================================== diff -u -r71d49118c3ebc21c6c78375c31ed3c8b2e9753ed -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (.../GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs) (revision 71d49118c3ebc21c6c78375c31ed3c8b2e9753ed) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (.../GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -19,118 +19,26 @@ // 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.Base.Data; -using Core.Common.IO.Exceptions; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.IO.Writers; namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Writers { [TestFixture] public class GrassCoverErosionInwardsCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + GrassCoverErosionInwardsCalculationConfigurationWriter, + GrassCoverErosionInwardsCalculation> { [Test] - public void Write_ConfigurationNull_ThrowArgumentNullException() - { - // Call - TestDelegate test = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().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 GrassCoverErosionInwardsCalculationConfigurationWriter().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 GrassCoverErosionInwardsCalculationConfigurationWriter().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 GrassCoverErosionInwardsCalculationConfigurationWriter().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 - string directoryPath = TestHelper.GetScratchPadPath(nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException)); - using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException))) - { - string filePath = Path.Combine(directoryPath, "test.xml"); - disposeHelper.LockDirectory(FileSystemRights.Write); - - // Call - TestDelegate call = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().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 GrassCoverErosionInwardsCalculationConfigurationWriter().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 WriteConfiguration_SparseCalculation_WritesSparseConfigurationToFile() { // Setup Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs =================================================================== diff -u -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs (.../GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs (.../GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -26,6 +26,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.IO.Writers; using Ringtoets.Revetment.Data; @@ -35,18 +36,11 @@ { [TestFixture] public class GrassCoverErosionOutwardsCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + GrassCoverErosionOutwardsCalculationConfigurationWriter, + GrassCoverErosionOutwardsWaveConditionsCalculation> { [Test] - public void Constructor_Always_CreateWaveConditionsInputWriter() - { - // Call - var writer = new GrassCoverErosionOutwardsCalculationConfigurationWriter(); - - // Assert - Assert.IsInstanceOf>(writer); - } - - [Test] public void Write_GroupWithCalculationAndOtherGroup_WritesOutCalculationAndGroupToFile() { // Setup @@ -101,5 +95,10 @@ File.Delete(filePath); } } + + protected override void AssertDefaultConstructedInstance(GrassCoverErosionOutwardsCalculationConfigurationWriter writer) + { + Assert.IsInstanceOf>(writer); + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingCalculationConfigurationWriterTest.cs =================================================================== diff -u -rf01786afaf51ad02f5be5e2a320461ebfe576bba -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingCalculationConfigurationWriterTest.cs (.../PipingCalculationConfigurationWriterTest.cs) (revision f01786afaf51ad02f5be5e2a320461ebfe576bba) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingCalculationConfigurationWriterTest.cs (.../PipingCalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -19,17 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Security.AccessControl; using Core.Common.Base.Data; -using Core.Common.IO.Exceptions; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.Piping.Data; using Ringtoets.Piping.Integration.TestUtils; using Ringtoets.Piping.IO.Exporters; @@ -39,6 +36,9 @@ { [TestFixture] public class PipingCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + PipingCalculationConfigurationWriter, + PipingCalculation> { private static IEnumerable Calculations { @@ -69,98 +69,6 @@ } [Test] - public void Write_ConfigurationNull_ThrowArgumentNullException() - { - // Call - TestDelegate test = () => new PipingCalculationConfigurationWriter().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 PipingCalculationConfigurationWriter().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 PipingCalculationConfigurationWriter().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 PipingCalculationConfigurationWriter().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 - string directoryPath = TestHelper.GetScratchPadPath(nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException)); - using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException))) - { - string filePath = Path.Combine(directoryPath, "test.xml"); - disposeHelper.LockDirectory(FileSystemRights.Write); - - // Call - TestDelegate call = () => new PipingCalculationConfigurationWriter().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 PipingCalculationConfigurationWriter().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 Write_CalculationGroupsAndCalculation_ValidFile() { // Setup Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj =================================================================== diff -u -r90d46f7d803d51c0a68ee35569cf3c918e5387fd -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision 90d46f7d803d51c0a68ee35569cf3c918e5387fd) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -96,6 +96,10 @@ {4843D6E5-066F-4795-94F5-1D53932DD03C} Ringtoets.Common.Data.TestUtil + + {33508D7C-1602-4C0D-8503-73AAE98C19E5} + Ringtoets.Common.IO.TestUtil + {87C2C553-C0BC-40BF-B1EA-B83BFF357F27} Ringtoets.Revetment.Data Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsCalculationConfigurationWriterTest.cs =================================================================== diff -u -r92df0a0ac0a4e0ccd5d7505d748f55167c2aac81 -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsCalculationConfigurationWriterTest.cs (.../WaveConditionsCalculationConfigurationWriterTest.cs) (revision 92df0a0ac0a4e0ccd5d7505d748f55167c2aac81) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsCalculationConfigurationWriterTest.cs (.../WaveConditionsCalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -30,26 +30,19 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.IO.Writers; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.IO.Writers; namespace Ringtoets.Revetment.IO.Test.Writers { [TestFixture] public class WaveConditionsCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + SimpleWaveConditionsCalculationConfigurationWriter, + SimpleWaveConditionsCalculation> { [Test] - public void Constructor_Always_ReturnsCalculationConfigurationWriter() - { - // Call - var writer = new SimpleWaveConditionsCalculationConfigurationWriter(); - - // Assert - Assert.IsInstanceOf>(writer); - } - - [Test] public void WriteCalculation_SparseCalculation_WritesSparseConfigurationToFile() { // Setup Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Writers/StabilityStoneCoverCalculationConfigurationWriterTest.cs =================================================================== diff -u -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Writers/StabilityStoneCoverCalculationConfigurationWriterTest.cs (.../StabilityStoneCoverCalculationConfigurationWriterTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Writers/StabilityStoneCoverCalculationConfigurationWriterTest.cs (.../StabilityStoneCoverCalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -26,6 +26,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.IO.Writers; using Ringtoets.StabilityStoneCover.Data; @@ -35,18 +36,11 @@ { [TestFixture] public class StabilityStoneCoverCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + StabilityStoneCoverCalculationConfigurationWriter, + StabilityStoneCoverWaveConditionsCalculation> { [Test] - public void Constructor_Always_CreateWaveConditionsInputWriter() - { - // Call - var writer = new StabilityStoneCoverCalculationConfigurationWriter(); - - // Assert - Assert.IsInstanceOf>(writer); - } - - [Test] public void Write_GroupWithCalculationAndOtherGroup_WritesOutCalculationAndGroupToFile() { // Setup @@ -101,5 +95,10 @@ File.Delete(filePath); } } + + protected override void AssertDefaultConstructedInstance(StabilityStoneCoverCalculationConfigurationWriter writer) + { + Assert.IsInstanceOf>(writer); + } } } \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs =================================================================== diff -u -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b -rb2288a6eae1568001c17d9ce7aaa5521a44595f2 --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs (.../WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs (.../WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs) (revision b2288a6eae1568001c17d9ce7aaa5521a44595f2) @@ -26,6 +26,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.IO.Writers; using Ringtoets.WaveImpactAsphaltCover.Data; @@ -35,18 +36,11 @@ { [TestFixture] public class WaveImpactAsphaltCoverCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + WaveImpactAsphaltCoverCalculationConfigurationWriter, + WaveImpactAsphaltCoverWaveConditionsCalculation> { [Test] - public void Constructor_Always_CreateWaveConditionsInputWriter() - { - // Call - var writer = new WaveImpactAsphaltCoverCalculationConfigurationWriter(); - - // Assert - Assert.IsInstanceOf>(writer); - } - - [Test] public void Write_GroupWithCalculationAndOtherGroup_WritesOutCalculationAndGroupToFile() { // Setup @@ -101,5 +95,10 @@ File.Delete(filePath); } } + + protected override void AssertDefaultConstructedInstance(WaveImpactAsphaltCoverCalculationConfigurationWriter writer) + { + Assert.IsInstanceOf>(writer); + } } } \ No newline at end of file