// Copyright (C) Stichting Deltares 2023. 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.Globalization; using System.IO; using System.Threading; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.IntegrationTests.IntegrationTests; [TestFixture] public class DebuggingTest { private const string mapTestFiles = @"TestFiles\"; /// Debugs the with XML input file. /// Usage: /// 1) Generate the input XML file in the DAM UI /// 2) Copy the file to src\Deltares.DamEngine.IntegrationTests\TestFiles\InputForDebugging.xml /// 3) Run the test in Debugging mode /// [Test]//, Ignore("This test is only used for debugging XML files generated by Dam UI")] [TestCase(12)] [TestCase(16)] public void DebugWithXmlInputFile(int maxCores) { const string inputFilename = "InputForDebugging.xml"; // or put your own name here; string fullInputFilename = Path.Combine(mapTestFiles, inputFilename); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string inputString = File.ReadAllText(fullInputFilename); var engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); engineInterface.DamProjectData.MaxCalculationCores = maxCores; string result = engineInterface.Validate(); Assert.IsTrue(result == null, "Validation must succeed but does not, see output xml in debugger"); string outputString = engineInterface.Run(); string outputName = "Output" + maxCores + ".xml"; File.WriteAllText(outputName, outputString); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString); int errorCount = GeneralHelper.DetermineNumberOfCalculationErrors(engineInterface.DamProjectData.CalculationMessages); Assert.AreEqual(0, errorCount, "There should be nor errors during the calculation."); if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design) { Assert.AreNotEqual(null, output.Results.CalculationResults); } else { Assert.AreNotEqual(null, output.Results.OperationalOutputTimeSeries); } } }