// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI 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.Linq; using Deltares.Dam.Data; using Deltares.Dam.Data.DataPlugins.Configuration; using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; using DataAttribute = Deltares.Dam.Data.DataPlugins.Configuration.DataAttribute; namespace Deltares.Dam.Tests { [TestFixture] public class DataPluginDataSourceXmlSerializerTests { private const string cXmlFilename = "datasource.xml"; [SetUp] public void TestFixtureSetup() {} [Test] public void ReadAfterWriteReturnsSameData() { var dataSourceContainerSrc = new DataSourceContainer(); dataSourceContainerSrc.DataSourceList.Add(new DataSource { DataSourceType = DataSourceType.CsvFiles, DataLocation = @".\CSVFiles\" }); dataSourceContainerSrc.Add(new DataAttribute { AttributeName = "testAttribute", DataSource = "testfile.shp" }); dataSourceContainerSrc.MapSoilProfile2D = @".\Geometries"; dataSourceContainerSrc.SensorConfigurationFilename = @".\SensorData.xls"; dataSourceContainerSrc.DataSourceEsriProjection = @"GDSKFJSDALKFKS"; dataSourceContainerSrc.IsImportAsRelativeProfiles = true; dataSourceContainerSrc.SoilProfileCharacteristicPointReference = CharacteristicPointType.DikeToeAtPolder; DataSourceContainer.Serialize(dataSourceContainerSrc, cXmlFilename); DataSourceContainer dataSourceContainerDest = DataSourceContainer.Deserialize(cXmlFilename); Assert.That(dataSourceContainerDest.MapSoilProfile2D, Is.EqualTo(dataSourceContainerSrc.MapSoilProfile2D)); Assert.That(dataSourceContainerDest.SensorConfigurationFilename, Is.EqualTo(dataSourceContainerSrc.SensorConfigurationFilename)); Assert.That(dataSourceContainerDest.DataSourceEsriProjection, Is.EqualTo(dataSourceContainerSrc.DataSourceEsriProjection)); Assert.That(dataSourceContainerDest.IsImportAsRelativeProfiles, Is.EqualTo(dataSourceContainerSrc.IsImportAsRelativeProfiles)); Assert.That(dataSourceContainerDest.SoilProfileCharacteristicPointReference, Is.EqualTo(dataSourceContainerSrc.SoilProfileCharacteristicPointReference)); Assert.That(dataSourceContainerDest.DataSourceList.Count, Is.EqualTo(dataSourceContainerSrc.DataSourceList.Count)); Assert.That(dataSourceContainerDest.DataSourceList[0].DataSourceType, Is.EqualTo(dataSourceContainerSrc.DataSourceList[0].DataSourceType)); Assert.That(dataSourceContainerDest.DataSourceList[0].DataLocation, Is.EqualTo(dataSourceContainerSrc.DataSourceList[0].DataLocation)); Assert.That(dataSourceContainerDest.DataAttributes, Is.Not.Null); Assert.That(dataSourceContainerDest.DataAttributes, Has.Count.EqualTo(1)); Assert.That(dataSourceContainerDest.DataAttributes.ElementAt(0).AttributeName, Is.EqualTo(dataSourceContainerSrc.DataAttributes.ElementAt(0).AttributeName)); } [Test] public void ContainerIsValid_ContainsUnsupportedAttributes_ReturnsFalse() { var container = new DataSourceContainer(); const string attributeName = "testattribute"; container.Add(new DataAttribute { AttributeName = attributeName }); Assert.That(DataSourceContainer.Validate(container, new[] { attributeName }).Count(), Is.EqualTo(0)); } } }