// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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 Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; namespace Deltares.DamEngine.Io.Tests; /// /// This class test just if the (generated) Input an Output class can be used for serializing to and from XML /// A check, whether the dat itself is correctly written and read is done in /// - FillDamFromXmlInputTests.CanWriteAndReadDamProjectDataToXml /// - FillXmlOutputFromDamTests.CanWriteAndReadDamProjectDataToXml /// [TestFixture] public class DamXmlSerializationTests { [Test] public void CanReadWriteInputObject() { const string filename = "Input.xml"; Input sourceInput = CreatePopulatedInput(); DamXmlSerialization.SaveInputAsXmlFile(filename, sourceInput); Input destinationInput = DamXmlSerialization.LoadInputFromXmlFile(filename); CompareInput(sourceInput, destinationInput); } [Test] public void CanReadWriteOutputObject() { const string filename = "Output.xml"; Output sourceOutput = CreatePopulatedOutput(); DamXmlSerialization.SaveOutputAsXmlFile(filename, sourceOutput); Output destinationOutput = DamXmlSerialization.LoadOutputFromXmlFile(filename); CompareOutput(sourceOutput, destinationOutput); } private static Input CreatePopulatedInput() { var input = new Input(); input.DamProjectType = InputDamProjectType.Design; return input; } private static void CompareInput(Input expected, Input actual) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; ComparisonResult result = compare.Compare(expected, actual); Assert.That(result.Differences, Is.Empty, "Differences found read/write Input object"); } private static Output CreatePopulatedOutput() { var output = new Output(); output.Results = new OutputResults(); output.Results.CalculationMessages = new Message[3]; output.Results.CalculationMessages[0] = new Message { MessageType = MessageMessageType.Error, Message1 = "test1" }; output.Results.CalculationMessages[1] = new Message { MessageType = MessageMessageType.Warning, Message1 = "test2" }; output.Results.CalculationMessages[2] = new Message { MessageType = MessageMessageType.Info, Message1 = "test3" }; return output; } private static void CompareOutput(Output expected, Output actual) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; ComparisonResult result = compare.Compare(expected, actual); Assert.That(result.Differences, Is.Empty, "Differences found read/write Output object"); } }