// Copyright (C) Stichting Deltares 2019. 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 System.IO; using NUnit.Framework; using Deltares.MacroStability.Kernel; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo; using Deltares.MacroStability.Standard; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityCommon { [TestFixture] public class MacroStabilityIoTests { private const string WtiFilesMap = @"KernelWrappers\MacroStabilityCommon\TestFiles"; [TestCase("Benchmark 1-01b.wti")] [TestCase("Benchmark 2-04a.wti")] public void GivenWtiFileWhenDeserializingAndSerializingThenTheStringsAreEqual(string fileNameIn) { // Given WTI file string fullFileNameIn = Path.Combine(WtiFilesMap, fileNameIn); // When Deserializing and Serializing string xmlInput = File.ReadAllText(fullFileNameIn); string fileNameOut = fileNameIn + ".out"; string fullFileNameOut = Path.Combine(WtiFilesMap, fileNameOut); KernelModel kernelModel = WtiDeserializer.Deserialize(xmlInput); string xmlOutput = WtiSerializer.Serialize(kernelModel); File.WriteAllText(fullFileNameOut, xmlOutput); // Then the strings are equal Assert.AreEqual(xmlInput, xmlOutput); } [TestCase("ValidateOk.xml")] [TestCase("ValidateError.xml")] public void GivenValidationResultFileWhenDeserializingAndSerializingThenTheStringsAreEqual(string fileNameIn) { // Given validation result file from kernel string fullFileNameIn = Path.Combine(WtiFilesMap, fileNameIn); // When Deserializing and Serializing string xmlInput = File.ReadAllText(fullFileNameIn); string fileNameOut = fileNameIn + ".out"; string fullFileNameOut = Path.Combine(WtiFilesMap, fileNameOut); var validationResults = WtiDeserializer.DeserializeValidation(xmlInput); string xmlOutput = WtiSerializer.SerializeValidation(validationResults); File.WriteAllText(fullFileNameOut, xmlOutput); // Then the strings are equal Assert.AreEqual(xmlInput, xmlOutput); } } }