// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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 Deltares.Dam.Data.CsvImporters; using Deltares.Geotechnics; using Deltares.Geotechnics.GeotechnicalGeometry; using System.Collections.Generic; using System.IO; using NUnit.Framework; using Deltares.Dam.Data; using Deltares.Geotechnics.SurfaceLines; using Deltares.Geotechnics.TestUtils; namespace Deltares.Dam.Tests { [TestFixture] public class CsvExportSurfaceLineTest { string importFolder; string fileNameSurfaceLines; [TestFixtureSetUp] public void FixtureSetup() { importFolder = Directory.GetCurrentDirectory() + "\\TmpImportFiles"; fileNameSurfaceLines = importFolder + "\\ExportSurfaceLine.csv"; if (!Directory.Exists(importFolder)) Directory.CreateDirectory(importFolder); } [Test] public void CanWriteTutorial1SurfaceLine() { // Write surfaceline using (SurfaceLine2 orgSurfaceLine = FactoryForSurfaceLineTests.CreateSurfaceLineTutorial1()) { string orgSurfaceLineString = orgSurfaceLine.ToString(); var csvExportSurfaceLineIdentifiers = new CsvExportSurfaceLineIdentifiers { LocationId = "Tutorial1", SoilProfileId = "SoilProfile", Scenario = "Scenario", CalculationMechanism = "Mechanism", CalculationModel = "Model" }; var csvExportSurfaceLine = new CsvExportSurfaceLine(csvExportSurfaceLineIdentifiers, orgSurfaceLine); var creator = new CsvExporter(fileNameSurfaceLines, new List { csvExportSurfaceLine }) { WriteHeaderInFirstLine = true }; creator.WriteFile(); // Read surfacelines var csvImporterSurfaceLines = new CsvImporterSurfaceLines(fileNameSurfaceLines); foreach (var surfaceLineRecord in csvImporterSurfaceLines.ImportedItems) { using (var surfaceLine = new SurfaceLine2 { Name = "SL1", Geometry = new LocalizedGeometryPointString(), CharacteristicPoints = { GeometryMustContainPoint = true } }) { for (int i = 0; i < surfaceLineRecord.Xcoors.Count; i++) { // empty points will not be added if (surfaceLineRecord.Xcoors[i] != -1 || surfaceLineRecord.Ycoors[i] != -1 || surfaceLineRecord.Zcoors[i] != -1) surfaceLine.EnsurePointOfType(surfaceLineRecord.Xcoors[i], surfaceLineRecord.Ycoors[i], surfaceLineRecord.Zcoors[i], null); } surfaceLine.Name = surfaceLineRecord.SurfaceLineId; Assert.AreEqual(orgSurfaceLineString, surfaceLine.ToString()); } } } } } }