// Copyright (C) Stichting Deltares 2020. 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 KellermanSoftware.CompareNetObjects; using NUnit.Framework; namespace Deltares.LayerOnSlopeTool.Io.Tests { public class MStabDamXmlSerializerTests { private const string TestFileFolder = @"TestFiles\"; [Test] public void CanReadWriteDamMStabDocObject() { string filename = Path.Combine(TestFileFolder, "DamMStabDoc.xml"); tnsPrefixDamMStabDoc sourceDamMStabDoc = CreatePopulatedDamMStabDoc(); MStabDamXmlSerializer.SaveDamMStabDocAsXmlFile(filename, sourceDamMStabDoc); tnsPrefixDamMStabDoc destinationDamMStabDoc = MStabDamXmlSerializer.LoadDamMStabDocFromXmlFile(filename); CompareDamMStabDoc(sourceDamMStabDoc, destinationDamMStabDoc); } private tnsPrefixDamMStabDoc CreatePopulatedDamMStabDoc() { tnsPrefixDamMStabDoc DamMStabDoc = new tnsPrefixDamMStabDoc(); DamMStabDoc.tnsPrefixDamMStabInput = new tnsPrefixDamMStabDocTnsPrefixDamMStabInput() { MStabFileName = "Example.sti", SoilDBName = "MSoilbase.mdb" }; var surfaceLine = new tnsbPrefixSurfaceLineTnsbPrefixSurfacePoint[2]; DamMStabDoc.tnsPrefixDamMStabInput.tnsbPrefixSurfaceLine = surfaceLine; surfaceLine[0] = new tnsbPrefixSurfaceLineTnsbPrefixSurfacePoint() { XCoord = 1.0, YCoord = 2.0 }; surfaceLine[1] = new tnsbPrefixSurfaceLineTnsbPrefixSurfacePoint() { XCoord = 3.0, YCoord = 4.0 }; var characteristicPoints = new tnsbPrefixCharacteristicPointsTnsbPrefixCharacteristicPoint[2]; characteristicPoints[0] = new tnsbPrefixCharacteristicPointsTnsbPrefixCharacteristicPoint() { CharacteristicPointType = CharacteristicPointType.SurfaceLevelOutside, XCoord = 10.0, YCoord = 20.0 }; characteristicPoints[1] = new tnsbPrefixCharacteristicPointsTnsbPrefixCharacteristicPoint() { CharacteristicPointType = CharacteristicPointType.SurfaceLevelInside, XCoord = 30.0, YCoord = 40.0 }; DamMStabDoc.tnsPrefixDamMStabInput.tnsbPrefixCharacteristicPoints = characteristicPoints; return DamMStabDoc; } private void CompareDamMStabDoc(tnsPrefixDamMStabDoc expected, tnsPrefixDamMStabDoc actual) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; var result = compare.Compare(expected, actual); Assert.AreEqual(0, result.Differences.Count, "Differences found read/write DamMStabDoc object: " + result.DifferencesString); } } }