Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -rb0021f2db39d2455a22c14bd3708ff2fc2a9e817 -r97c94a903e0fd98edd8cd4120340f91f06d3955c --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision b0021f2db39d2455a22c14bd3708ff2fc2a9e817) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -102,6 +102,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -0,0 +1,147 @@ +// 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.Collections.Generic; +using System.Xml; +using Core.Common.IO.Exceptions; +using Core.Common.Utils.Properties; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.IO.Schema; + +namespace Ringtoets.Common.IO.Writers +{ + /// + /// Base implementation of a writer for calculations to XML format. + /// + /// The type of calculations which are written to file. + public abstract class CalculationConfigurationWriter where T : class, ICalculation + { + /// + /// Writes a single in XML format to file. + /// + /// The calculation to write. + /// The writer to use for writing. + protected abstract void WriteCalculation(T calculation, XmlWriter writer); + + /// + /// Writes the in XML format to file. + /// + /// The distributions, as tuples of name and distribution, to write. + /// The writer to use for writing. + protected static void WriteDistributions(IEnumerable> distributions, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement); + + foreach (Tuple distribution in distributions) + { + WriteDistribution(distribution.Item2, distribution.Item1, writer); + } + + writer.WriteEndElement(); + } + + /// + /// Writes a piping configuration to an XML file. + /// + /// The root calculation group containing the piping configuration to write. + /// The path to the target XML file. + /// Thrown when any parameter is null. + /// Thrown when unable to write to . + /// The itself will not be part of the written XML, only its children. + public void Write(CalculationGroup rootCalculationGroup, string filePath) + { + if (rootCalculationGroup == null) + { + throw new ArgumentNullException(nameof(rootCalculationGroup)); + } + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + try + { + var settings = new XmlWriterSettings + { + Indent = true + }; + + using (XmlWriter writer = XmlWriter.Create(filePath, settings)) + { + writer.WriteStartDocument(); + writer.WriteStartElement(ConfigurationSchemaIdentifiers.ConfigurationElement); + + WriteConfiguration(rootCalculationGroup, writer); + + writer.WriteEndElement(); + writer.WriteEndDocument(); + } + } + catch (SystemException e) + { + throw new CriticalFileWriteException(string.Format(Resources.Error_General_output_error_0, filePath), e); + } + } + + private void WriteConfiguration(CalculationGroup calculationGroup, XmlWriter writer) + { + foreach (ICalculationBase child in calculationGroup.Children) + { + var innerGroup = child as CalculationGroup; + if (innerGroup != null) + { + WriteCalculationGroup(innerGroup, writer); + } + + var calculation = child as T; + if (calculation != null) + { + WriteCalculation(calculation, writer); + } + } + } + + private static void WriteDistribution(IDistribution distribution, string elementName, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastElement); + + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, elementName); + writer.WriteElementString(ConfigurationSchemaIdentifiers.MeanElement, + XmlConvert.ToString(distribution.Mean)); + writer.WriteElementString(ConfigurationSchemaIdentifiers.StandardDeviationElement, + XmlConvert.ToString(distribution.StandardDeviation)); + + writer.WriteEndElement(); + } + + private void WriteCalculationGroup(CalculationGroup calculationGroup, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.FolderElement); + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculationGroup.Name); + + WriteConfiguration(calculationGroup, writer); + + writer.WriteEndElement(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/DistributionPropertiesTestHelperTest.cs =================================================================== diff -u -r9acc86d915e28f2107cbd27cf9154733de28f12f -r97c94a903e0fd98edd8cd4120340f91f06d3955c --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/DistributionPropertiesTestHelperTest.cs (.../DistributionPropertiesTestHelperTest.cs) (revision 9acc86d915e28f2107cbd27cf9154733de28f12f) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/DistributionPropertiesTestHelperTest.cs (.../DistributionPropertiesTestHelperTest.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -114,7 +114,7 @@ #endregion [Test] - [TestCaseSource(typeof(DistributionPropertiesTestHelperTest), nameof(distributionTestCases))] + [TestCaseSource(nameof(distributionTestCases))] public void AssertPropertiesInState_DifferentDistributions_ExpectedAssertionsCalled( DistributionPropertiesBase distribution, bool expectedMeanReadOnly, @@ -136,7 +136,7 @@ } [Test] - [TestCaseSource(typeof(DistributionPropertiesTestHelperTest), nameof(variationCoefficientDistributionTestCases))] + [TestCaseSource(nameof(variationCoefficientDistributionTestCases))] public void AssertPropertiesInState_DifferentVariationCoefficientDistributions_ExpectedAssertionsCalled( VariationCoefficientDistributionPropertiesBase distribution, bool expectedMeanReadOnly, Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r24f0b189764d40cc8ee7e9efd62ee6c6ea8c7b5f -r97c94a903e0fd98edd8cd4120340f91f06d3955c --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 24f0b189764d40cc8ee7e9efd62ee6c6ea8c7b5f) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -95,6 +95,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -0,0 +1,280 @@ +// 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.Collections.Generic; +using System.IO; +using System.Security.AccessControl; +using System.Xml; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.IO.Writers; + +namespace Ringtoets.Common.IO.Test.Writers +{ + [TestFixture] + public class CalculationConfigurationWriterTest + { + [Test] + public void Write_CalculationGroupNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(null, string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("rootCalculationGroup", exception.ParamName); + } + + [Test] + public void Write_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(new CalculationGroup(), 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(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 Write_FilePathTooLong_ThrowCriticalFileWriteException() + { + // Setup + var filePath = new string('a', 249); + + // Call + TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(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 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 SimpleCalculationConfigurationWriter().Write(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 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(new CalculationGroup(), 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_Always_WritesEachDistributionAsElement() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test_distributions_write.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.Common.IO, + Path.Combine("CalculationConfigurationWriter", "distributions.xml")); + + var distributions = new List> + { + new Tuple("normal", new NormalDistribution + { + Mean = (RoundedDouble) 0.2, + StandardDeviation = (RoundedDouble) 0.1 + }), + new Tuple("lognormal", new LogNormalDistribution + { + Mean = (RoundedDouble) 0.4, + StandardDeviation = (RoundedDouble) 0.3 + }) + }; + + try + { + using (XmlWriter writer = XmlWriter.Create(filePath, new XmlWriterSettings + { + Indent = true + })) + { + // Call + new SimpleCalculationConfigurationWriter().PublicWriteDistributions(distributions, writer); + } + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + [Test] + [TestCaseSource(nameof(CalculationConfigurations))] + public void Write_DifferentCalculationAndCalculationGroupConfigurations_ValidFile(CalculationGroup rootGroup, string expectedFileContentsFileName) + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.Common.IO, + Path.Combine(nameof(CalculationConfigurationWriter), expectedFileContentsFileName)); + + try + { + // Call + new SimpleCalculationConfigurationWriter().Write(rootGroup, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + public class SimpleCalculation : Observable, ICalculation + { + public SimpleCalculation(string name) + { + Name = name; + } + + public string Name { get; set; } + public bool HasOutput { get; } + public Comment Comments { get; } + public void ClearOutput() {} + } + + public class SimpleCalculationConfigurationWriter : CalculationConfigurationWriter + { + public const string CalculationElementTag = "calculation"; + + protected override void WriteCalculation(SimpleCalculation calculation, XmlWriter writer) + { + writer.WriteElementString(CalculationElementTag, calculation.Name); + } + + public void PublicWriteDistributions(IEnumerable> distributions, XmlWriter writer) + { + WriteDistributions(distributions, writer); + } + } + + private static IEnumerable CalculationConfigurations() + { + var calculation1 = new SimpleCalculation("calculation1"); + var calculation2 = new SimpleCalculation("calculation2"); + + var calculationGroup1 = new CalculationGroup("group1", false); + var calculationGroup2 = new CalculationGroup("group2", false) + { + Children = + { + calculation2, + calculationGroup1 + } + }; + + yield return new TestCaseData( + CreateRootGroupWithChildren(calculationGroup1), + "singleGroup.xml") + .SetName("Single group"); + yield return new TestCaseData( + CreateRootGroupWithChildren(calculation1), + "singleCalculation.xml") + .SetName("Single calculation"); + yield return new TestCaseData( + CreateRootGroupWithChildren(calculationGroup1, calculation1), + "calculationGroupAndCalculation.xml") + .SetName("Calculation group and calculation"); + yield return new TestCaseData( + CreateRootGroupWithChildren(calculation1, calculationGroup2), + "calculationAndGroupWithNesting.xml") + .SetName("Calculation and group with nesting"); + } + + private static CalculationGroup CreateRootGroupWithChildren(params ICalculationBase[] children) + { + var group = new CalculationGroup("root", false); + foreach (ICalculationBase child in children) + { + group.Children.Add(child); + } + return group; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/PipingConfigurationExporter.cs =================================================================== diff -u -rb7f9c9f43aac18c45ea1932f4559a29eda7fbe34 -r97c94a903e0fd98edd8cd4120340f91f06d3955c --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/PipingConfigurationExporter.cs (.../PipingConfigurationExporter.cs) (revision b7f9c9f43aac18c45ea1932f4559a29eda7fbe34) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/PipingConfigurationExporter.cs (.../PipingConfigurationExporter.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -63,7 +63,7 @@ { try { - PipingConfigurationWriter.Write(calculationGroup, filePath); + new PipingConfigurationWriter().Write(calculationGroup, filePath); } catch (CriticalFileWriteException e) { Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/PipingConfigurationWriter.cs =================================================================== diff -u -r3aa7e76b08eadd9497740489ed3daad5f2e13b0e -r97c94a903e0fd98edd8cd4120340f91f06d3955c --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/PipingConfigurationWriter.cs (.../PipingConfigurationWriter.cs) (revision 3aa7e76b08eadd9497740489ed3daad5f2e13b0e) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Exporters/PipingConfigurationWriter.cs (.../PipingConfigurationWriter.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -20,95 +20,23 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Xml; -using Core.Common.IO.Exceptions; -using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.IO.Schema; +using Ringtoets.Common.IO.Writers; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Schema; -using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources; namespace Ringtoets.Piping.IO.Exporters { /// /// Writer for writing a piping configuration to XML. /// - internal static class PipingConfigurationWriter + internal class PipingConfigurationWriter : CalculationConfigurationWriter { - /// - /// Writes a piping configuration to an XML file. - /// - /// The root calculation group containing the piping configuration to write. - /// The path to the target XML file. - /// Thrown when any parameter is null. - /// Thrown when unable to write to . - /// The itself will not be part of the written XML, only its children. - internal static void Write(CalculationGroup rootCalculationGroup, string filePath) + protected override void WriteCalculation(PipingCalculation calculation, XmlWriter writer) { - if (rootCalculationGroup == null) - { - throw new ArgumentNullException(nameof(rootCalculationGroup)); - } - if (filePath == null) - { - throw new ArgumentNullException(nameof(filePath)); - } - - try - { - var settings = new XmlWriterSettings - { - Indent = true - }; - - using (XmlWriter writer = XmlWriter.Create(filePath, settings)) - { - writer.WriteStartDocument(); - writer.WriteStartElement(ConfigurationSchemaIdentifiers.ConfigurationElement); - - WriteConfiguration(rootCalculationGroup, writer); - - writer.WriteEndElement(); - writer.WriteEndDocument(); - } - } - catch (SystemException e) - { - throw new CriticalFileWriteException(string.Format(CoreCommonUtilsResources.Error_General_output_error_0, filePath), e); - } - } - - private static void WriteConfiguration(CalculationGroup calculationGroup, XmlWriter writer) - { - foreach (ICalculationBase child in calculationGroup.Children) - { - var innerGroup = child as CalculationGroup; - if (innerGroup != null) - { - WriteCalculationGroup(innerGroup, writer); - } - - var calculation = child as PipingCalculation; - if (calculation != null) - { - WriteCalculation(calculation, writer); - } - } - } - - private static void WriteCalculationGroup(CalculationGroup calculationGroup, XmlWriter writer) - { - writer.WriteStartElement(ConfigurationSchemaIdentifiers.FolderElement); - writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculationGroup.Name); - - WriteConfiguration(calculationGroup, writer); - - writer.WriteEndElement(); - } - - private static void WriteCalculation(PipingCalculation calculation, XmlWriter writer) - { writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculation.Name); @@ -147,34 +75,20 @@ } } - WriteDistributions(calculationInputParameters, writer); + WriteDistributions(CreateInputDistributions(calculationInputParameters), writer); writer.WriteEndElement(); } - private static void WriteDistributions(PipingInput calculationInputParameters, XmlWriter writer) + private static IEnumerable> CreateInputDistributions(PipingInput calculationInputParameters) { - writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement); + yield return Tuple.Create( + PipingConfigurationSchemaIdentifiers.PhreaticLevelExitStochastName, + calculationInputParameters.PhreaticLevelExit); - WriteDistribution(calculationInputParameters.PhreaticLevelExit, - PipingConfigurationSchemaIdentifiers.PhreaticLevelExitStochastName, writer); - WriteDistribution(calculationInputParameters.DampingFactorExit, - PipingConfigurationSchemaIdentifiers.DampingFactorExitStochastName, writer); - - writer.WriteEndElement(); + yield return Tuple.Create( + PipingConfigurationSchemaIdentifiers.DampingFactorExitStochastName, + calculationInputParameters.DampingFactorExit); } - - private static void WriteDistribution(IDistribution distribution, string elementName, XmlWriter writer) - { - writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastElement); - writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, elementName); - - writer.WriteElementString(ConfigurationSchemaIdentifiers.MeanElement, - XmlConvert.ToString(distribution.Mean)); - writer.WriteElementString(ConfigurationSchemaIdentifiers.StandardDeviationElement, - XmlConvert.ToString(distribution.StandardDeviation)); - - writer.WriteEndElement(); - } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingConfigurationWriterTest.cs =================================================================== diff -u -r28ab332db2d96ad9e766f19677af1c00fc88a644 -r97c94a903e0fd98edd8cd4120340f91f06d3955c --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingConfigurationWriterTest.cs (.../PipingConfigurationWriterTest.cs) (revision 28ab332db2d96ad9e766f19677af1c00fc88a644) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingConfigurationWriterTest.cs (.../PipingConfigurationWriterTest.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) @@ -71,7 +71,7 @@ public void Write_CalculationGroupNull_ThrowArgumentNullException() { // Call - TestDelegate test = () => PipingConfigurationWriter.Write(null, string.Empty); + TestDelegate test = () => new PipingConfigurationWriter().Write(null, string.Empty); // Assert var exception = Assert.Throws(test); @@ -82,7 +82,7 @@ public void Write_FilePathNull_ThrowArgumentNullException() { // Call - TestDelegate test = () => PipingConfigurationWriter.Write(new CalculationGroup(), null); + TestDelegate test = () => new PipingConfigurationWriter().Write(new CalculationGroup(), null); // Assert var exception = Assert.Throws(test); @@ -96,7 +96,7 @@ public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) { // Call - TestDelegate call = () => PipingConfigurationWriter.Write(new CalculationGroup(), filePath); + TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), filePath); // Assert var exception = Assert.Throws(call); @@ -111,7 +111,7 @@ var filePath = new string('a', 249); // Call - TestDelegate call = () => PipingConfigurationWriter.Write(new CalculationGroup(), filePath); + TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), filePath); // Assert var exception = Assert.Throws(call); @@ -130,7 +130,7 @@ disposeHelper.LockDirectory(FileSystemRights.Write); // Call - TestDelegate call = () => PipingConfigurationWriter.Write(new CalculationGroup(), filePath); + TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), filePath); // Assert var exception = Assert.Throws(call); @@ -150,7 +150,7 @@ fileDisposeHelper.LockFiles(); // Call - TestDelegate call = () => PipingConfigurationWriter.Write(new CalculationGroup(), path); + TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), path); // Assert var exception = Assert.Throws(call); @@ -212,7 +212,7 @@ try { // Call - PipingConfigurationWriter.Write(rootGroup, filePath); + new PipingConfigurationWriter().Write(rootGroup, filePath); // Assert Assert.IsTrue(File.Exists(filePath)); @@ -249,7 +249,7 @@ try { // Call - PipingConfigurationWriter.Write(rootCalculationGroup, filePath); + new PipingConfigurationWriter().Write(rootCalculationGroup, filePath); // Assert Assert.IsTrue(File.Exists(filePath));