// 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 Deltares.LayerOnSlopeTool.Data; 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 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 const double Diff = 0.001; [Test] public void TestLayerCreatorForSingleFileWithLocationNoDikeMaterial() { var layerCreator = new LayerCreator(importFolderIncorrectLocation, importFolderIncorrectLocation, outputFolder); 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); 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); if (Directory.Exists(outputFolder)) { Directory.Delete(outputFolder, true); } Directory.CreateDirectory(outputFolder); layerCreator.Execute(); var resultFile = Path.Combine(outputFolder, "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")); } } }