Index: src/Deltares.DSoilModel.Forms.Tests/DSoilModelSegmentGeometryEditorTests.cs =================================================================== diff -u --- src/Deltares.DSoilModel.Forms.Tests/DSoilModelSegmentGeometryEditorTests.cs (revision 0) +++ src/Deltares.DSoilModel.Forms.Tests/DSoilModelSegmentGeometryEditorTests.cs (revision 388) @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Deltares.DSoilModel.Data; +using Deltares.Geometry; +using Deltares.Geotechnics; +using Deltares.Standard; +using Deltares.Standard.EventPublisher; +using Deltares.Standard.Forms; +using Deltares.Standard.Forms.DExpress; +using NUnit.Framework; + +namespace Deltares.DSoilModel.Forms.Tests +{ + [TestFixture] + public class DSoilModelSegmentGeometryEditorTests + { + private DSoilModelSegmentGeometryEditor dsmGeometryEditor; + private readonly GeometryEditor extraGeometryEditor = new GeometryEditor(); + private MainForm mainForm; + private SpatialEditor spatialEditor; + + [SetUp] + public void SetUp() + { + About.IgnoreAssemblyErrors = true; + mainForm = new MainForm(); + var project = new DSoilModelProject(); + dsmGeometryEditor = new DSoilModelSegmentGeometryEditor(extraGeometryEditor) + { + Project = project + }; + extraGeometryEditor.Title = "Extra Geometry"; + extraGeometryEditor.SpatialEditor.ReadUserValues(); + mainForm.AddControl(extraGeometryEditor); + spatialEditor = dsmGeometryEditor.SpatialEditor; + } + + [TearDown] + public void TearDown() + { + dsmGeometryEditor.Dispose(); + dsmGeometryEditor = null; + } + + private SoilProfile2D CreateSoilProfile2D() + { + var profile = new SoilProfile2D(); + + profile.CenterCrestLocation = 0; + profile.Geometry.Points.Add(new GeometryPoint(1, 1, 1)); + profile.PreconsolidationStresses.Add(new PreConsolidationStress()); + profile.Surfaces.Add(new SoilLayer2D()); + + return profile; + } + + private DSoilModelProject CreateProject() + { + var project = new DSoilModelProject(); + var sp2 = CreateSoilProfile2D(); + project.SoilProfiles2D.Add(sp2); + var segment = new SoilSegment(); + var ssp = new StochasticSoilProfile(); + ssp.Probability = 1; + ssp.Profile = sp2; + segment.StochasticSoilModel.StochasticSoilProfiles.Add(ssp); + project.SoilSegments.Add(segment); + return project; + } + + [TestCase(null)] + [TestCase("")] + [TestCase("Name")] + public void IsVisibleTest_AlwaysTrue(string propertyName) + { + Assert.IsTrue(dsmGeometryEditor.IsVisible(propertyName)); // always true + } + + [TestCase(null, true)] + [TestCase("", true)] + [TestCase("Name", true)] + [TestCase("SplitSegment", false)] + [TestCase("SplitSegmentLocation", false)] + public void IsVisibleTest_NoData(string propertyName, bool expected) + { + Assert.AreEqual(expected, dsmGeometryEditor.IsEnabled(propertyName)); // always true + } + + [TestCase(null, true)] + [TestCase("", true)] + [TestCase("Name", true)] + [TestCase("SplitSegment", true)] + [TestCase("SplitSegmentLocation", false)] + public void IsVisibleTest_WithRequiredData(string propertyName, bool expected) + { + dsmGeometryEditor.Project = CreateProject(); + var splitLocation = new SoilSegmentSplitLocation + { + SoilSegment = dsmGeometryEditor.Project.SoilSegments[0], + SoilProfile2D = dsmGeometryEditor.Project.SoilProfiles2D[0], + XCoordinate = 0.5 + }; + spatialEditor.EmptySelection = new EmptyShape(dsmGeometryEditor.Project.SoilProfiles2D[0]); + DataEventPublisher.SelectionChanged(splitLocation); + Assert.AreEqual(expected, dsmGeometryEditor.IsEnabled(propertyName)); + } + + [TestCase("SplitSegment", false)] + [TestCase("SplitSegmentLocation", true)] + public void IsVisibleTest_WithRequiredDataForSplitSegmentLocation(string propertyName, bool expected) + { + dsmGeometryEditor.Project = CreateProject(); + var splitLocation = new SoilSegmentSplitLocation + { + SoilSegment = dsmGeometryEditor.Project.SoilSegments[0], + SoilProfile2D = dsmGeometryEditor.Project.SoilProfiles2D[0], + XCoordinate = 0.5 + }; + spatialEditor.EmptySelection = new EmptyShape(dsmGeometryEditor.Project.SoilProfiles2D[0]); + DataEventPublisher.SelectionChanged(splitLocation); + var seg = new SoilSegment(); + dsmGeometryEditor.Project.SoilSegments.Add(seg); + DataEventPublisher.SelectionChanged(seg); + Assert.AreEqual(expected, dsmGeometryEditor.IsEnabled(propertyName)); + } + } +} Index: src/Deltares.DSoilModel.Forms.Tests/Deltares.DSoilModel.Forms.Tests.csproj =================================================================== diff -u -r386 -r388 --- src/Deltares.DSoilModel.Forms.Tests/Deltares.DSoilModel.Forms.Tests.csproj (.../Deltares.DSoilModel.Forms.Tests.csproj) (revision 386) +++ src/Deltares.DSoilModel.Forms.Tests/Deltares.DSoilModel.Forms.Tests.csproj (.../Deltares.DSoilModel.Forms.Tests.csproj) (revision 388) @@ -107,6 +107,7 @@ + Index: src/Deltares.DSoilModel.Forms/DSoilModelSegmentGeometryEditor.cs =================================================================== diff -u -r6 -r388 --- src/Deltares.DSoilModel.Forms/DSoilModelSegmentGeometryEditor.cs (.../DSoilModelSegmentGeometryEditor.cs) (revision 6) +++ src/Deltares.DSoilModel.Forms/DSoilModelSegmentGeometryEditor.cs (.../DSoilModelSegmentGeometryEditor.cs) (revision 388) @@ -71,6 +71,20 @@ } /// + /// Gets the spatial editor. + /// + /// + /// The spatial editor. + /// + public SpatialEditor SpatialEditor + { + get + { + return spatialEditor; + } + } + + /// /// Gets or sets the project. /// public DSoilModelProject Project @@ -149,6 +163,7 @@ /// /// Property for binding of Split segment toolbar button. + /// So even when it seems not used, it is used! /// /// /// true if [split segment location]; otherwise, false.