// Copyright (C) Stichting Deltares 2018. 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 Deltares.DamMacroStability.Calculator; using NUnit.Framework; namespace Deltares.DamMacroStability.CalculatorTests { [TestFixture] public class DGeoStabilityExeRunnerTests { private const string NormalTestFile = @"zuivering Gendt.sti"; private const string NormalTestFile2 = @"zuivering Gendt 2.sti"; private const string TestFolder = @"..\..\Tests\Files"; private const string RunFolder = @"..\..\Tests\Files\RunFolder"; private DGeoStabilityExeRunner runner; [TestFixtureSetUp] public void FixtureSetup() { runner = new DGeoStabilityExeRunner(); } [Test] public void TestCreateDGeoStabilityIniFileForSingleInputFile() { var inputfileName = Path.Combine(RunFolder, NormalTestFile); var inifileName = runner.CreateDGeoStabilityIniFile(inputfileName); Assert.IsTrue(File.Exists(inifileName)); var expectedFile = Path.Combine(TestFolder, "ExpectedIniFileForSingleInputFile.txt"); var expectedLines = File.ReadAllLines(expectedFile); var resultLines = File.ReadAllLines(inifileName); for (var i = 0; i < expectedLines.Length; i++) { Assert.AreEqual(expectedLines[i], resultLines[i]); } } [Test] public void TestCreateDGeoStabilityIniFileForFolder() { var inifileName = runner.CreateDGeoStabilityIniFile(RunFolder); Assert.IsTrue(File.Exists(inifileName)); var expectedFile = Path.Combine(TestFolder, "ExpectedIniFileForFolder.txt"); var expectedLines = File.ReadAllLines(expectedFile); var resultLines = File.ReadAllLines(inifileName); for (var i = 0; i < expectedLines.Length; i++) { Assert.AreEqual(expectedLines[i], resultLines[i]); } } [Test] public void TestCreateDGeoStabilityIniFileWithExtraOptions() { string inifileName; // change exe path where the DGeoStability.ini will be searched // set it back later var currentPath = runner.DGeoStabilityExePath; try { runner.DGeoStabilityExePath = Path.Combine(TestFolder, "DGeoStability.exe"); inifileName = runner.CreateDGeoStabilityIniFile(Path.Combine(RunFolder, NormalTestFile)); } finally { runner.DGeoStabilityExePath = currentPath; } Assert.IsTrue(File.Exists(inifileName)); var expectedFile = Path.Combine(TestFolder, "ExpectedIniFileWithExtraOptions.txt"); var expectedLines = File.ReadAllLines(expectedFile); var resultLines = File.ReadAllLines(inifileName); for (int i = 0; i < expectedLines.Length; i++) { Assert.AreEqual(expectedLines[i], resultLines[i]); } } [Test] public void TestRunDGeoStabilityWithIniFileForSingleInputFile() { var expectedFileName = Path.Combine(RunFolder, NormalTestFile); TestHelper.DeleteOutputFiles(expectedFileName); // 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(), RunFolder)); var inputfileName = Path.Combine(absoluteFolder, NormalTestFile); runner.RunDGeoStabilityProject(inputfileName); TestHelper.AssertOutputFiles(expectedFileName); } [Test] public void TestRunDGeoStabilityIniFileForFolder() { var expectedFileName1 = Path.Combine(RunFolder, NormalTestFile); TestHelper.DeleteOutputFiles(expectedFileName1); var expectedFileName2 = Path.Combine(RunFolder, NormalTestFile2); TestHelper.DeleteOutputFiles(expectedFileName2); // 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(), RunFolder)); runner.RunDGeoStabilityProject(absoluteFolder); TestHelper.AssertOutputFiles(expectedFileName1); TestHelper.AssertOutputFiles(expectedFileName2); } #region Exceptions [Test] [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Projectnaam ' ' is niet geldig")] [SetUICulture("nl-NL")] public void TestLanguageNlThrowsExceptionEmptyProject() { runner.RunDGeoStabilityProject(" "); } [Test] [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Project name ' ' is not valid")] [SetUICulture("en-US")] public void TestLanguageEnThrowsExceptionEmptyProject() { runner.RunDGeoStabilityProject(" "); } [Test] [ExpectedException(typeof(FileNotFoundException))] public void TestThrowsExceptionFileNotFound() { runner.RunDGeoStabilityProject(@"C:\NonExistingFile.sti"); } [Test] public void TestDoesNotThrowExceptionFileExists() { runner.RunDGeoStabilityProject(Path.Combine(RunFolder, NormalTestFile)); } [Test] [ExpectedException(typeof(FileNotFoundException))] public void TestThrowsExceptionFolderNotFound() { runner.RunDGeoStabilityProject(@"C:\NonExistingFolder"); } [Test] public void TestDoesNotThrowExceptionFolderExists() { runner.RunDGeoStabilityProject(TestFolder); } [Test] [ExpectedException(typeof(FileNotFoundException), ExpectedMessage = "Executable voor stabiliteitsberekening niet gevonden op '..\\DGeoStability.exe'")] [SetUICulture("nl-NL")] public void TestThrowsExecutableNotFound() { var currentPath = runner.DGeoStabilityExePath; try { runner.DGeoStabilityExePath = @"..\DGeoStability.exe"; runner.RunDGeoStabilityProject(Path.Combine(RunFolder, NormalTestFile)); } finally { runner.DGeoStabilityExePath = currentPath; } } [Test] public void TestDoesNotThrowExecutableExists() { runner.RunDGeoStabilityProject(Path.Combine(RunFolder, NormalTestFile)); } #endregion } }