// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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.ComponentModel;
using System.Linq;
using Core.Common.Base.Geometry;
using Core.Common.Gui.Converters;
using Core.Common.Gui.PropertyBag;
using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.Forms.PropertyClasses;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.Forms.Test.PropertyClasses
{
public class MacroStabilityInwardsSoilLayer2DPropertiesTest
{
[Test]
public void Constructor_MacroStabilityInwardsSoilLayer2DNull_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => new MacroStabilityInwardsSoilLayer2DProperties(null);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("soilLayer", exception.ParamName);
}
[Test]
public void Constructor_ValidMacroStabilityInwardsSoilLayer2D_ExpectedValues()
{
// Setup
MacroStabilityInwardsSoilLayer2D soilLayer = CreateMacroStabilityInwardsSoilLayer2D();
// Call
var properties = new MacroStabilityInwardsSoilLayer2DProperties(soilLayer);
// Assert
Assert.IsInstanceOf>(properties);
TestHelper.AssertTypeConverter(nameof(MacroStabilityInwardsSoilLayer2DProperties.OuterRing));
TestHelper.AssertTypeConverter(nameof(MacroStabilityInwardsSoilLayer2DProperties.NestedLayers));
Assert.AreSame(soilLayer, properties.Data);
}
[Test]
public void GetProperties_WithData_ReturnExpectedValues()
{
// Setup
var nestedLayer = new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
{
new Point2D(12.987, 12.821),
new Point2D(4.23, 1.02)
}), new Ring[0]);
var layer = new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
{
new Point2D(20.210230, 26.00001),
new Point2D(3.830, 1.040506)
}),
new Ring[0])
{
Data = new MacroStabilityInwardsSoilLayerData
{
MaterialName = "Test Name",
IsAquifer = true
},
NestedLayers = new[]
{
nestedLayer
}
};
// Call
var properties = new MacroStabilityInwardsSoilLayer2DProperties(layer);
// Assert
Assert.AreEqual(layer.Data.MaterialName, properties.Name);
Assert.AreEqual(layer.Data.IsAquifer, properties.IsAquifer);
CollectionAssert.AreEqual(layer.OuterRing.Points, properties.OuterRing);
Assert.AreEqual(1, properties.NestedLayers.Length);
Assert.AreSame(layer.NestedLayers.Single(), properties.NestedLayers[0].Data);
}
[Test]
public void ToString_Always_ReturnsMaterialName()
{
// Setup
MacroStabilityInwardsSoilLayer2D layer = CreateMacroStabilityInwardsSoilLayer2D();
layer.Data.MaterialName = "Layer A 2D";
var properties = new MacroStabilityInwardsSoilLayer2DProperties(layer);
// Call
string name = properties.ToString();
// Assert
Assert.AreEqual(layer.Data.MaterialName, name);
}
[Test]
public void Constructor_ValidData_PropertieshaveExpectedAttributeValues()
{
// Setup
MacroStabilityInwardsSoilLayer2D layer = CreateMacroStabilityInwardsSoilLayer2D();
// Call
var properties = new MacroStabilityInwardsSoilLayer2DProperties(layer);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(4, dynamicProperties.Count);
const string generalCategoryName = "Algemeen";
PropertyDescriptor nameProperty = dynamicProperties[0];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
generalCategoryName,
"Naam",
"De naam van de grondlaag.",
true);
PropertyDescriptor outerRingProperty = dynamicProperties[1];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(outerRingProperty,
generalCategoryName,
"Buitenring",
"De geometrie van de buitenring van deze grondlaag.",
true);
PropertyDescriptor nestedLayersProperty = dynamicProperties[2];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nestedLayersProperty,
generalCategoryName,
"Geneste lagen",
"De geneste lagen binnen deze grondlaag.",
true);
PropertyDescriptor isAquiferProperty = dynamicProperties[3];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isAquiferProperty,
generalCategoryName,
"Is aquifer",
"Geeft aan of deze grondlaag een watervoerende laag betreft.",
true);
}
private static MacroStabilityInwardsSoilLayer2D CreateMacroStabilityInwardsSoilLayer2D()
{
return new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
{
new Point2D(20.210230, 26.00001),
new Point2D(3.830, 1.040506)
}),
new Ring[0])
{
Data = new MacroStabilityInwardsSoilLayerData()
};
}
}
}