// Copyright (C) Stichting Deltares 2020. All rights reserved. // // This file is part of the Layer On Slope Tool. // // The Layer On Slope Tool 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 NUnit.Framework; namespace Deltares.LayerOnSlopeTool.LayerCreator.Tests { [TestFixture] public class LayerCreatorTests { private readonly string importFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFile"); private readonly string importFolderMulti = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesMultiFiles"); private readonly string importFolderIncorrectLocation = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFileMissingDikeMaterial"); private readonly string importFolderStiGeometryLeftOfSurfaceLine = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFileStiGeometryLeftOfSurfaceLine"); private readonly string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\OutputFilesSingleFile"); private readonly string outputFolderMulti = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\OutputFilesMultiFiles"); private readonly string logFileName = ""; [Test] public void TestLayerCreatorForSingleFileWithLocationNoDikeMaterial() { var layerCreator = new LayerCreator(importFolderIncorrectLocation, importFolderIncorrectLocation, outputFolder, logFileName); if (Directory.Exists(outputFolder)) { Directory.Delete(outputFolder,true); } Directory.CreateDirectory(outputFolder); try { layerCreator.Execute(); } catch (Exception e) { Assert.IsTrue(e.Message.Contains("Error(s) found, see log file")); } var resultFile = Path.Combine(outputFolder, "111-DIG-8986-01.2.sti"); Assert.IsFalse(File.Exists(resultFile)); var logFile = Path.Combine(outputFolder, layerCreator.LogFileName); Assert.IsTrue(File.Exists(logFile)); var lines =File.ReadAllLines(logFile); Assert.IsTrue(lines.Length == 1); Assert.IsTrue(lines[0].Contains("Fatal error whilst reading locations")); } [Test] public void TestLayerCreatorForSingleFileWithStiGeometryLeftOfSurfaceLine() { var layerCreator = new LayerCreator(importFolderStiGeometryLeftOfSurfaceLine, importFolderStiGeometryLeftOfSurfaceLine, outputFolder, logFileName); if (Directory.Exists(outputFolder)) { Directory.Delete(outputFolder, true); } Directory.CreateDirectory(outputFolder); try { layerCreator.Execute(); } catch (Exception e) { Assert.IsTrue(e.Message.Contains("Error(s) found, see log file")); } var resultFile = Path.Combine(outputFolder, "111-DIG-8986-01.2.sti"); Assert.IsFalse(File.Exists(resultFile)); var logFile = Path.Combine(outputFolder, layerCreator.LogFileName); Assert.IsTrue(File.Exists(logFile)); var lines = File.ReadAllLines(logFile); Assert.IsTrue(lines.Length == 2); Assert.IsTrue(lines[0].Contains("Handling location")); Assert.IsTrue(lines[1].Contains("Geometry is completely left of Surface Line")); } [Test] public void TestLayerCreatorForSingleFileWithCorrectData() { var layerCreator = new LayerCreator(importFolder, importFolder, outputFolder, logFileName); if (Directory.Exists(outputFolder)) { Directory.Delete(outputFolder, true); } Directory.CreateDirectory(outputFolder); layerCreator.Execute(); var resultFile = Path.Combine(outputFolder, "111-DIG-8986-01.2-dp 46_111-DIG-8986-01.2.sti"); Assert.IsTrue(File.Exists(resultFile)); var logFile = Path.Combine(outputFolder, layerCreator.LogFileName); Assert.IsTrue(File.Exists(logFile)); var lines = File.ReadAllLines(logFile); Assert.IsTrue(lines.Length == 1); Assert.IsTrue(lines[0].Contains("Handling location")); } [Test] public void TestLayerCreatorForMultipleFilesWithCorrectData() { var layerCreator = new LayerCreator(importFolderMulti, importFolderMulti, outputFolderMulti, logFileName); if (Directory.Exists(outputFolderMulti)) { Directory.Delete(outputFolderMulti, true); } Directory.CreateDirectory(outputFolderMulti); layerCreator.Execute(); var resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-01.2-dp 46_111-DIG-8986-01.2.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-05.1-dp 07_111-DIG-8986-05.1.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-05.2-dp 10_111-DIG-8986-05.2.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-06.2-dp 19_111-DIG-8986-06.2.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-07.1-dp 26_111-DIG-8986-07.1.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-07.1-dp 30_111-DIG-8986-07.1a.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-07.2-dp 32_111-DIG-8986-07.2.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-07.3-dp 36_111-DIG-8986-07.3.sti"); Assert.IsTrue(File.Exists(resultFile)); resultFile = Path.Combine(outputFolderMulti, "111-DIG-8986-07.4-dp 43_111-DIG-8986-07.4.sti"); Assert.IsTrue(File.Exists(resultFile)); var logFile = Path.Combine(outputFolderMulti, layerCreator.LogFileName); Assert.IsTrue(File.Exists(logFile)); var lines = File.ReadAllLines(logFile); Assert.IsTrue(lines.Length == 9); Assert.IsTrue(lines[0].Contains("Handling location")); Assert.IsTrue(lines[8].Contains("Handling location")); } } }