// Copyright (C) Stichting Deltares 2023. 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 System.Collections.Generic;
using System.IO;
using System.Linq;
using Deltares.Dam.Data.IO;
using Deltares.Maps;
using NUnit.Framework;
namespace Deltares.Dam.Tests.IO
{
[TestFixture]
public class ShapeFileExporterTest
{
#region Setup
[SetUp]
public void FixtureSetup()
{
}
[TearDown]
public void FixtureTearDown()
{
}
[SetUp]
public void TestSetup()
{
}
[TearDown]
public void TestTearDown()
{
}
#endregion
[Test]
[Ignore("ShapeFile writing bug needs to be solved to make this test succeed")]
public void Export_UsingValidDataAndPreCondionsAreMet_FilesAreWrittenAnCanBeRead()
{
const string name = "SafetyFactor";
const string path = ".";
foreach(var file in Directory.GetFiles(path, name + ".*"))
{
File.Delete(file);
}
const string attrName = "SAFETYFACT";
var repository = new FeatureRepository();
repository.Add(
Feature.Create(
"POINT(1 1)",
new Dictionary { {attrName, 1.7} }
));
// Actual test
var exporter = new ShapeFileExporter(name, path, repository);
exporter.Export();
var fileLocation = new ShapeFileLocation(path, name);
// Reading data back to verify the export
var retrievedRepository = FeatureRepository.CreateFromShapeFile(fileLocation);
Assert.IsNotNull(retrievedRepository);
var retrievedFeature = retrievedRepository.Features.ElementAt(0);
Assert.AreEqual(1.7, retrievedFeature.Attributes[attrName]);
}
}
}