// 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;
using System.Collections.Generic;
using System.IO;
using Deltares.DamEngine.Data.Design;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.General.Sensors;
using Deltares.DamEngine.Data.General.TimeSeries;
using Deltares.DamEngine.Data.Geometry;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Io;
using Deltares.DamEngine.Io.XmlInput;
using Deltares.DamEngine.TestHelpers;
using KellermanSoftware.CompareNetObjects;
using NUnit.Framework;
using Segment = Deltares.DamEngine.Data.General.Segment;
using Sensor = Deltares.DamEngine.Data.General.Sensors.Sensor;
using SensorGroup = Deltares.DamEngine.Data.General.Sensors.SensorGroup;
using SensorLocation = Deltares.DamEngine.Data.General.Sensors.SensorLocation;
using Soil = Deltares.DamEngine.Data.Geotechnics.Soil;
using SoilProfile1D = Deltares.DamEngine.Data.Geotechnics.SoilProfile1D;
using SoilProfile2D = Deltares.DamEngine.Data.Geotechnics.SoilProfile2D;
namespace Deltares.DamEngine.Interface.Tests
{
[TestFixture]
public class FillDamFromXmlInputTests
{
[Test]
public void CanWriteAndReadDamProjectDataToXml()
{
const string inputFilename = "InputFile.xml";
DamProjectData expectedDamProjectData = TestDataCreator.CreateExampleDamProjectData();
// Write input file
Input input = FillXmlInputFromDam.CreateInput(expectedDamProjectData);
DamXmlSerialization.SaveInputAsXmlFile(inputFilename, input);
// Init static that is to be loaded with not expected value
DamProjectCalculationSpecification.SelectedAnalysisType = TestDataCreator.NotExpectedAnalysisType;
// Load input file
input = DamXmlSerialization.LoadInputFromXmlFile(inputFilename);
DamProjectData actualDamProjectData = FillDamFromXmlInput.CreateDamProjectData(input);
CompareDamProjectData(actualDamProjectData, expectedDamProjectData);
}
[Test]
public void CanWriteAndReadDamProjectDataToXmlString()
{
DamProjectData expectedDamProjectData = TestDataCreator.CreateExampleDamProjectData();
// Write input string
string xmlString;
Input input = FillXmlInputFromDam.CreateInput(expectedDamProjectData);
xmlString = DamXmlSerialization.SaveInputAsXmlString(input);
// Init static that is to be loaded with not expected value
DamProjectCalculationSpecification.SelectedAnalysisType = TestDataCreator.NotExpectedAnalysisType;
// Load input string
input = DamXmlSerialization.LoadInputFromXmlString(xmlString);
DamProjectData actualDamProjectData = FillDamFromXmlInput.CreateDamProjectData(input);
CompareDamProjectData(actualDamProjectData, expectedDamProjectData);
}
[Test]
public void CanAquiferListBeHandledOk()
{
const string inputFileName = @"TestFiles\AquiferListInputFile.xml";
var input = DamXmlSerialization.LoadInputFromXmlFile(inputFileName);
Assert.AreEqual(28, input.AquiferSoils.Length);
DamProjectData actualDamProjectData = FillDamFromXmlInput.CreateDamProjectData(input);
Assert.AreEqual(11, actualDamProjectData.Dike.SoilList.AquiferDictionary.Count);
Assert.AreEqual(7, actualDamProjectData.CalculationMessages.Count);
}
private void CompareDamProjectData(DamProjectData actual, DamProjectData expected)
{
Assert.AreEqual(TestDataCreator.ExpectedAnalysisType, DamProjectCalculationSpecification.SelectedAnalysisType);
var compare = new CompareLogic { Config = { MaxDifferences = 100 } };
compare.Config.MembersToIgnore = new List
{
"Points",
"MinGeometryPointsX",
"MinGeometryPointsZ",
"MaxGeometryPointsX",
"MaxGeometryPointsZ",
"CurveList",
"Curves",
"Surfaces",
"SurfaceLine",
"Loops",
}; // TODO i.m.o the serializing of the geometry should be improved, so these ignores are not needed anymore
var result = compare.Compare(expected, actual);
Assert.AreEqual(0, result.Differences.Count, "Differences found read/write Input object");
}
}
}