Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.IO.Test/DuneLocationsWriterTest.cs =================================================================== diff -u -ra8aca94d54270b32b12d2e6810e5ef21824130e7 -raa08f3d944eb8f045be344a6c062b1df32cb7cfa --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.IO.Test/DuneLocationsWriterTest.cs (.../DuneLocationsWriterTest.cs) (revision a8aca94d54270b32b12d2e6810e5ef21824130e7) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.IO.Test/DuneLocationsWriterTest.cs (.../DuneLocationsWriterTest.cs) (revision aa08f3d944eb8f045be344a6c062b1df32cb7cfa) @@ -61,7 +61,7 @@ [TestCase("")] [TestCase(" ")] [TestCase("c:\\>")] - public void WriteWaveConditions_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) + public void WriteDuneLocations_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) { // Call TestDelegate call = () => DuneLocationsWriter.WriteDuneLocations(Enumerable.Empty(), filePath); Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/CalculationGroupWriter.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/CalculationGroupWriter.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/CalculationGroupWriter.cs (revision aa08f3d944eb8f045be344a6c062b1df32cb7cfa) @@ -0,0 +1,66 @@ +// 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.Xml; +using Core.Common.IO.Exceptions; +using Ringtoets.Common.Data.Calculation; +using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources; + +namespace Ringtoets.Piping.IO.Exporters +{ + /// + /// Xml file writer for writing objects to *.xml file. + /// + internal static class CalculationGroupWriter + { + /// + /// Writes the calculation group to a xml file. + /// + /// The root calculation group to be written to the file. + /// The path to the file. + /// Thrown when any parameter is null. + /// Thrown when unable to write to . + internal static void WriteCalculationGroups(CalculationGroup rootCalculationGroup, string filePath) + { + if (rootCalculationGroup == null) + { + throw new ArgumentNullException(nameof(rootCalculationGroup)); + } + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + try + { + using (XmlWriter writer = XmlWriter.Create(filePath)) + { + + } + } + catch (SystemException e) + { + throw new CriticalFileWriteException(string.Format(CoreCommonUtilsResources.Error_General_output_error_0, filePath), e); + } + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj =================================================================== diff -u -r316e741c3eefe3aab13dd070b56654a6bc4c24f1 -raa08f3d944eb8f045be344a6c062b1df32cb7cfa --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 316e741c3eefe3aab13dd070b56654a6bc4c24f1) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision aa08f3d944eb8f045be344a6c062b1df32cb7cfa) @@ -52,6 +52,7 @@ + @@ -100,6 +101,11 @@ Core.Common.Utils False + + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} + Ringtoets.Common.Data + False + {52ba7627-cbab-4209-be77-3b5f31378277} Ringtoets.Common.IO @@ -153,6 +159,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/CalculationGroupWriterTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/CalculationGroupWriterTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/CalculationGroupWriterTest.cs (revision aa08f3d944eb8f045be344a6c062b1df32cb7cfa) @@ -0,0 +1,116 @@ +// 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.Security.AccessControl; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Piping.IO.Exporters; + +namespace Ringtoets.Piping.IO.Test.Exporters +{ + [TestFixture] + public class CalculationGroupWriterTest + { + [Test] + public void WriteCalculationGroups_CalculationGroupNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => CalculationGroupWriter.WriteCalculationGroups(null, string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("rootCalculationGroup", exception.ParamName); + } + + [Test] + public void WriteCalculationGroups_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => CalculationGroupWriter.WriteCalculationGroups(new CalculationGroup(), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase("c:\\>")] + public void WriteCalculationGroups_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) + { + // Call + TestDelegate call = () => CalculationGroupWriter.WriteCalculationGroups(new CalculationGroup(), 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 WriteCalculationGroups_FilePathTooLong_ThrowCriticalFileWriteException() + { + // Setup + var filePath = new string('a', 249); + + // Call + TestDelegate call = () => CalculationGroupWriter.WriteCalculationGroups(new CalculationGroup(), 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 WriteCalculationGroups_InvalidDirectoryRights_ThrowCriticalFileWriteException() + { + // Setup + string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, + "WriteCalculationGroups_InvalidDirectoryRights_ThrowCriticalFileWriteException"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.xml"); + + // Call + TestDelegate call = () => CalculationGroupWriter.WriteCalculationGroups(new CalculationGroup(), filePath); + + try + { + using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write)) + { + // 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); + } + } + finally + { + Directory.Delete(directoryPath, true); + } + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -raa08f3d944eb8f045be344a6c062b1df32cb7cfa --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision aa08f3d944eb8f045be344a6c062b1df32cb7cfa) @@ -72,6 +72,7 @@ +