// Copyright (C) Stichting Deltares 2024. 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 System.Globalization;
using System.Threading;
using NetTopologySuite.Geometries;
using NUnit.Framework;
namespace Deltares.Maps.Tests.Domain;
[TestFixture]
public class FeatureTest
{
private Feature feature;
[Test]
public void FeatureCreation_NormalScenario_CreatesFeatureInstance()
{
const string geometryWkt = "POINT (0.1 0.2)";
feature = Feature.Create(geometryWkt);
Assert.That(feature, Is.Not.Null);
Assert.That(feature.WktFormat, Is.EqualTo(geometryWkt));
feature = Feature.Create(geometryWkt);
Assert.That(feature, Is.Not.Null);
Assert.That(feature.WktFormat, Is.EqualTo(geometryWkt));
Assert.That(feature.Geometry, Is.InstanceOf());
}
[Test]
public void FeatureCreation_DutchCultureWktStringFormat_Throws()
{
var cultureInfo = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
string oldDecimalSeparator = cultureInfo.NumberFormat.NumberDecimalSeparator;
try
{
cultureInfo.NumberFormat.NumberDecimalSeparator = ",";
Thread.CurrentThread.CurrentCulture = cultureInfo;
Assert.That(() =>
{
var geometryWkt = $"MULTIPOINT ({0.1} {0.2},{0.3} {0.4})";
feature = Feature.Create(geometryWkt);
},
Throws.InstanceOf().With.Message.Contains("Operation is not valid due to the current state of the object."));
}
finally
{
cultureInfo.NumberFormat.NumberDecimalSeparator = oldDecimalSeparator;
Thread.CurrentThread.CurrentCulture = cultureInfo;
}
}
[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.That(feature, Is.Not.Null);
Assert.That(feature.WktFormat, Is.EqualTo(geometryWkt));
Assert.That(feature.Geometry, Is.InstanceOf());
};
CultureHelper.InvokeWithDutchCulture(test);
}
#region Setup
[SetUp]
public void FixtureSetup() {}
[TearDown]
public void FixtureTearDown() {}
[SetUp]
public void TestSetup() {}
[TearDown]
public void TestTearDown() {}
#endregion
}