// 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;
using NetTopologySuite.Geometries;
using NUnit.Framework;
namespace Deltares.Maps.Tests.Domain
{
[TestFixture]
public class FeatureTest
{
private Feature feature;
#region Setup
[SetUp]
public void FixtureSetup()
{
}
[TearDown]
public void FixtureTearDown()
{
}
[SetUp]
public void TestSetup()
{
}
[TearDown]
public void TestTearDown()
{
}
#endregion
[Test]
public void FeatureCreation_NormalScenario_CreatesFeatureInstance()
{
const string geometryWkt = "POINT (0.1 0.2)";
feature = Feature.Create(geometryWkt);
Assert.IsNotNull(feature);
Assert.AreEqual(geometryWkt, feature.WktFormat);
feature = Feature.Create(geometryWkt);
Assert.IsNotNull(feature);
Assert.AreEqual(geometryWkt, feature.WktFormat);
Assert.IsInstanceOf(typeof(Point), feature.Geometry);
}
[Test]
// NB This test fails when you change the decimal separator to a point in Dutch regional settings on your computer
public void FeatureCreation_DutchCultureWktStringFormat_Throws()
{
Action test =
() =>
{
string geometryWkt = $"MULTIPOINT ({0.1} {0.2},{0.3} {0.4})";
feature = Feature.Create(geometryWkt);
};
Assert.That(() => CultureHelper.InvokeWithDutchCulture(test),
Throws.InstanceOf().With.Message.Contains("There was an error parsing the WKT geometry string, maybe due to an incorrect culture format conversion"));
}
[Test]
public void FeatureCreation_DutchCulture_FeatureIsCreatedWithoutExceptions()
{
Action test =
() =>
{
const string geometryWkt = "MULTIPOINT (0.0 0.1,0.2 0.3)";
feature = Feature.Create(geometryWkt);
Assert.IsNotNull(feature);
Assert.AreEqual(geometryWkt, feature.WktFormat);
Assert.IsInstanceOf(typeof(MultiPoint), feature.Geometry);
};
CultureHelper.InvokeWithDutchCulture(test);
}
}
}