// Copyright (C) Stichting Deltares 2018. 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 System.Text; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.IntegrationTests.IntegrationTests { /// /// These tests were based on DamLiveIntegrationTest.Run_UsingTestFiles_HasExpectedResultsInOutputFile() /// [TestFixture] class OperationalPulauTekongTests { private const double tolerance = 0.0005; private const double novalue = -999.0; private const string stabilityOutsideFactor = "StabilityOutsideFactor"; [Test] [TestCase(@"PulauTekong.InputFile.xml", 2.486106, 2.114159)] [TestCase(@"PulauTekong.InputFile-NoValues.xml", novalue, novalue)] public void Run_UsingTestFiles_HasExpectedResultsInOutputFile(string inputTestcaseFilename, double valueEntry1, double valueEntry2) { const string calcDir = "TestOperationalPulauTekong"; const string workingDir = @"TestFiles\"; const string baseTestDirectory = @".\Operational\PulauTekong\"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); // Switch to TestFiles directory to check if DamLive can also run from another directory Directory.SetCurrentDirectory(workingDir); // Based on "Deltares.DamLive.Tests.PulauTekongTest" string inputFileName = baseTestDirectory + inputTestcaseFilename; const string outputFileName = baseTestDirectory + @"PulauTekong.OutputFile.xml"; string inputString = File.ReadAllText(inputFileName); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "MapForSoilgeometries2D", baseTestDirectory + @"PulauTekong.geometries2D.0\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", baseTestDirectory + @"PulauTekong0.soilmaterials.mdb"); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); File.WriteAllText(outputFileName, outputString, Encoding.Unicode); Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(null, output); Assert.AreEqual(stabilityOutsideFactor, output.Results.OperationalOutputTimeSeries[0].ParameterId); Assert.AreEqual(valueEntry1, output.Results.OperationalOutputTimeSeries[0].Entries.TimeSerieEntry[0].Value, tolerance); Assert.AreEqual(stabilityOutsideFactor, output.Results.OperationalOutputTimeSeries[1].ParameterId); Assert.AreEqual(valueEntry2, output.Results.OperationalOutputTimeSeries[1].Entries.TimeSerieEntry[0].Value, tolerance); } } }