// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of the Dam Macrostability Kernel. // // The Dam Macrostability Kernel 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.IO; using System.Linq; using Deltares.DamMacroStability.Calculator; using NUnit.Framework; namespace Deltares.DamMacroStability.CalculatorTests { [TestFixture] public class StabilityCalculatorTests { private const string TestCalcFolder = @"..\..\Tests\Files\Calc"; private const string TestFile1D = @"Test1D.sti"; private const string TestFile2D = @"Test2D.sti"; [Test] public void TestCalculateStabilitySafetyFactorGeometry1D() { // Relative paths in ini file do not work yet in DGeoStability 16.2. This is fixed in 18.1. var absoluteFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), TestCalcFolder)); var inputFileName = Path.Combine(absoluteFolder, TestFile1D); TestHelper.DeleteOutputFiles(inputFileName); var stabilityCalculator = new StabilityCalculator(); stabilityCalculator.ProjectName = inputFileName; stabilityCalculator.Calculate(); var results = stabilityCalculator.GetResults(); Assert.AreEqual(1, results.Count); Assert.AreEqual(1.486, results[0].Zone1.SafetyFactor, 0.001); TestHelper.AssertOutputFiles(inputFileName); } [Test] public void TestCalculateStabilitySafetyFactorGeometry2D() { // Relative paths in ini file do not work yet in DGeoStability 16.2. This is fixed in 18.1. var absoluteFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), TestCalcFolder)); var inputFileName = Path.Combine(absoluteFolder, TestFile2D); TestHelper.DeleteOutputFiles(inputFileName); var stabilityCalculator = new StabilityCalculator(); stabilityCalculator.ProjectName = inputFileName; stabilityCalculator.Calculate(); var results = stabilityCalculator.GetResults(); Assert.AreEqual(1, results.Count); Assert.AreEqual(1.557, results[0].Zone1.SafetyFactor, 0.001); TestHelper.AssertOutputFiles(inputFileName); } [Test] public void TestCalculateStabilitySafetyFactorForFolder() { // Relative paths in ini file do not work yet in DGeoStability 16.2. This is fixed in 18.1. var absoluteFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), TestCalcFolder)); var fileName1 = Path.Combine(absoluteFolder, TestFile1D); TestHelper.DeleteOutputFiles(fileName1); var fileName2 = Path.Combine(absoluteFolder, TestFile2D); TestHelper.DeleteOutputFiles(fileName2); var stabilityCalculator = new StabilityCalculator(); stabilityCalculator.ProjectName = absoluteFolder; stabilityCalculator.Calculate(); var results = stabilityCalculator.GetResults(); Assert.AreEqual(2, results.Count); Assert.AreEqual(1.486, results.First(r => r.CalculationName == "Test1D").Zone1.SafetyFactor, 0.001); Assert.AreEqual(1.557, results.First(r => r.CalculationName == "Test2D").Zone1.SafetyFactor, 0.001); TestHelper.AssertOutputFiles(fileName1); TestHelper.AssertOutputFiles(fileName2); } [Test] [SetUICulture("nl-NL")] public void TestRunWithDifferentExePath() { // Relative paths in ini file do not work yet in DGeoStability 16.2. This is fixed in 18.1. var absoluteFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), TestCalcFolder)); var inputFileName = Path.Combine(absoluteFolder, TestFile1D); var stabilityCalculator = new StabilityCalculator(); stabilityCalculator.ProjectName = inputFileName; stabilityCalculator.DGeoStabilityExePath = @".\DGeoStabilityNew.exe"; try { stabilityCalculator.Calculate(); } catch (Exception e) { Assert.IsTrue(e.Message.Contains(string.Format( "Er is een fout opgetreden tijdens de berekening van de stabiliteitsfactor voor '{0}'", inputFileName))); Assert.IsTrue(e.InnerException.Message.Contains("Executable voor stabiliteitsberekening niet gevonden op '.\\DGeoStabilityNew.exe'")); } } [Test] [SetUICulture("nl-NL")] public void TestThrowIfSomethingGoesWrongDuringCalculation() { const string inputFileName = "NonExistingProject.sti"; try { var stabilityCalculator = new StabilityCalculator(); stabilityCalculator.ProjectName = inputFileName; stabilityCalculator.Calculate(); } catch (Exception e) { Assert.IsTrue(e.Message.Contains(string.Format( "Er is een fout opgetreden tijdens de berekening van de stabiliteitsfactor voor '{0}'", inputFileName))); Assert.IsTrue(e.InnerException.Message.Contains("Project 'NonExistingProject.sti' niet gevonden")); } } } }