Index: src/Deltares.DSoilModel.Forms.Tests/DSoilModelGeometryEditorTests.cs =================================================================== diff -u -r349 -r384 --- src/Deltares.DSoilModel.Forms.Tests/DSoilModelGeometryEditorTests.cs (.../DSoilModelGeometryEditorTests.cs) (revision 349) +++ src/Deltares.DSoilModel.Forms.Tests/DSoilModelGeometryEditorTests.cs (.../DSoilModelGeometryEditorTests.cs) (revision 384) @@ -1,9 +1,11 @@ -using Deltares.DSoilModel.Data; +using System; +using Deltares.DSoilModel.Data; using Deltares.Geometry; using Deltares.Geotechnics; using Deltares.Geotechnics.ConePenetrationTest; using Deltares.Geotechnics.IO; using Deltares.Standard; +using Deltares.Standard.Forms; using Deltares.Standard.Forms.DExpress; using NUnit.Framework; @@ -12,19 +14,27 @@ [TestFixture] public class DSoilModelGeometryEditorTests { - private DSoilModelGeometryEditor geometryEditor; - - [TestFixtureSetUp] + private DSoilModelGeometryEditor dsmGeometryEditor; + private MainForm mainForm; + private SpatialEditor spatialEditor; + + [SetUp] public void SetUp() { About.IgnoreAssemblyErrors = true; - geometryEditor = new DSoilModelGeometryEditor(new MainForm()); + mainForm = new MainForm(); + var project = new DSoilModelProject(); + dsmGeometryEditor = new DSoilModelGeometryEditor(mainForm) + { + Project = project + }; + spatialEditor = dsmGeometryEditor.SpatialEditor; } - [TestFixtureTearDown] + [TearDown] public void TearDown() { - geometryEditor = null; + dsmGeometryEditor = null; } private DSoilModelProject CreateProjectForSoilProfile2D(SoilProfile2D profile) @@ -35,7 +45,7 @@ p.CptLookup2Ds.Add(new ConePenetrationTestLookup2D {SoilProfile2D = profile}); p.SpecificMechanismPointLocations.Add(new SpecificMechanismPointLocation {SoilProfile2D = profile}); p.Soilprofile1DLookup2Ds.Add(new SoilProfile1DLookup2D {SoilProfile2D = profile}); - + p.SoilProfiles2D.Add(profile); return p; } @@ -53,7 +63,7 @@ { var profile = new SoilProfile2D(); - profile.CenterCrestLocation = 55; + profile.CenterCrestLocation = 0; profile.Geometry.Points.Add(new GeometryPoint(1, 1, 1)); profile.PreconsolidationStresses.Add(new PreConsolidationStress()); profile.Surfaces.Add(new SoilLayer2D()); @@ -75,12 +85,12 @@ public void ClearGeometryForSoilProfile1DTest() { var soilProfile1D = CreateSoilProfile1D(); - geometryEditor.Project = CreateProjectForSoilProfile1D(soilProfile1D); + dsmGeometryEditor.Project = CreateProjectForSoilProfile1D(soilProfile1D); - geometryEditor.ClearGeometryForSoilProfile1D(soilProfile1D); + dsmGeometryEditor.ClearGeometryForSoilProfile1D(soilProfile1D); - Assert.IsEmpty(geometryEditor.Project.BoringLookup1Ds); - Assert.IsEmpty(geometryEditor.Project.CptLookup1Ds); + Assert.IsEmpty(dsmGeometryEditor.Project.BoringLookup1Ds); + Assert.IsEmpty(dsmGeometryEditor.Project.CptLookup1Ds); Assert.IsEmpty(soilProfile1D.Layers); } @@ -89,14 +99,14 @@ public void ClearGeometryForSoilProfile2DTest() { var soilProfile2D = CreateSoilProfile2D(); - geometryEditor.Project = CreateProjectForSoilProfile2D(soilProfile2D); + dsmGeometryEditor.Project = CreateProjectForSoilProfile2D(soilProfile2D); - geometryEditor.ClearGeometryForSoilProfile2D(soilProfile2D); + dsmGeometryEditor.ClearGeometryForSoilProfile2D(soilProfile2D); - Assert.IsEmpty(geometryEditor.Project.BoringLookup2Ds); - Assert.IsEmpty(geometryEditor.Project.CptLookup2Ds); - Assert.IsEmpty(geometryEditor.Project.SpecificMechanismPointLocations); - Assert.IsEmpty(geometryEditor.Project.Soilprofile1DLookup2Ds); + Assert.IsEmpty(dsmGeometryEditor.Project.BoringLookup2Ds); + Assert.IsEmpty(dsmGeometryEditor.Project.CptLookup2Ds); + Assert.IsEmpty(dsmGeometryEditor.Project.SpecificMechanismPointLocations); + Assert.IsEmpty(dsmGeometryEditor.Project.Soilprofile1DLookup2Ds); Assert.IsNaN(soilProfile2D.CenterCrestLocation); Assert.IsEmpty(soilProfile2D.Geometry.Points); @@ -109,7 +119,138 @@ [TestCase("Name")] public void IsEnabledTest_AlwaysTrue(string propertyName) { - Assert.IsTrue(geometryEditor.IsEnabled(propertyName)); // always true - } + Assert.IsTrue(dsmGeometryEditor.IsEnabled(propertyName)); // always true + } + + [TestCase(null, true)] + [TestCase("", true)] + [TestCase("Name", true)] + [TestCase("CreatePointInLine", false)] + [TestCase("CreatePolyline", false)] + [TestCase("DeleteLooseLines", false)] + [TestCase("InsertCpt", false)] + [TestCase("InsertBoring", false)] + [TestCase("InsertSoilProfile1D", false)] + [TestCase("InsertSpecificMechanismPointLocation", false)] + [TestCase("AddCenterCrestLocationTo2DProfile", false)] + [TestCase("AddSurfaceLineToCreateNew2DProfile", false)] + [TestCase("AddSurfaceLineToCreate2DProfile", false)] + [TestCase("Add1DProfileToCreate2DProfile", false)] + [TestCase("ExecuteClearSoilProfile1DCommand", false)] + [TestCase("ExecuteClearSoilProfile2DCommand", false)] + public void IsVisibleTestWithNoData(string propertyName, bool expected) + { + Assert.AreEqual(expected, dsmGeometryEditor.IsVisible(propertyName)); + } + + [Test] + public void TestCreatePolyLine() + { + dsmGeometryEditor.CreatePolyline = true; + var res = dsmGeometryEditor.CreatePolyline; + // expected = false as no curves are actually added. + Assert.AreEqual(false, res); + } + + [Test] + public void TestCreatePointInLine() + { + dsmGeometryEditor.CreatePolyline = true; + var res = dsmGeometryEditor.CreatePointInLine; + // expected = false as no point is actually added. + Assert.AreEqual(false, res); + } + + [Test] + public void TestAllowEdit() + { + dsmGeometryEditor.AllowEdit = true; + var res = dsmGeometryEditor.AllowEdit; + Assert.AreEqual(true, res); + dsmGeometryEditor.AllowEdit = false; + res = dsmGeometryEditor.AllowEdit; + Assert.AreEqual(false, res); + } + + [Test] + public void TestShowSoilSegmentReturnsEarlyOnMissingData() + { + const string emptyCaption = "Empty"; + mainForm.GeometryDockPanel.Text = emptyCaption; + dsmGeometryEditor.ShowSoilSegment(null, null); + // caption must remain as is + Assert.AreEqual(emptyCaption, mainForm.GeometryDockPanel.Text); + + var segment = new SoilSegment(); + const string emptySegment = "Empty segment"; + segment.Name = emptySegment; + dsmGeometryEditor.ShowSoilSegment(segment, null); + // caption must be Segment + name only + Assert.AreEqual("Segment " + emptySegment, mainForm.GeometryDockPanel.Text); + } + + [Test] + public void TestShowSoilSegmentReturnsProperly() + { + const string emptyCaption = "Empty"; + mainForm.GeometryDockPanel.Text = emptyCaption; + var segment = new SoilSegment(); + const string emptySegment = "Empty segment"; + segment.Name = emptySegment; + + //Test for 1D profile + var stochProf = new StochasticSoilProfile(); + const string name1D = "Empty 1D"; + var prof1D = new SoilProfile1D + { + Name = name1D + }; + stochProf.Profile = prof1D; + dsmGeometryEditor.ShowSoilSegment(segment, stochProf); + // caption must name1D + string caption = mainForm.GeometryDockPanel.Text; + Assert.IsTrue(caption.Contains(name1D)); + + // Test for 2D profile + const string name2D = "Empty 2D"; + var prof2D = new SoilProfile2D {Name = name2D}; + stochProf.Profile = prof2D; + dsmGeometryEditor.ShowSoilSegment(segment, stochProf); + // caption must contain name2D + caption = mainForm.GeometryDockPanel.Text; + Assert.IsTrue(caption.Contains(name2D)); + } + + [Test] + public void TestInsertSpecificMechanismPointLocation() + { + // First without data + dsmGeometryEditor.InsertSpecificMechanismPointLocation(); + Assert.AreEqual(0, dsmGeometryEditor.Project.SpecificMechanismPointLocations.Count); + + var soilProfile = CreateSoilProfile2D(); + dsmGeometryEditor.Project = CreateProjectForSoilProfile2D(soilProfile); + dsmGeometryEditor.Project.SpecificMechanismPointLocations.Clear(); + spatialEditor.EmptySelection = new EmptyShape(soilProfile); + // expected = 1 new location + dsmGeometryEditor.InsertSpecificMechanismPointLocation(); + Assert.AreEqual(1, dsmGeometryEditor.Project.SpecificMechanismPointLocations.Count); + } + + [Test] + public void TestAddCenterCrestLocationTo2DProfile() + { + // First without data + dsmGeometryEditor.AddCenterCrestLocationTo2DProfile(); + var soilProfile = CreateSoilProfile2D(); + dsmGeometryEditor.Project = CreateProjectForSoilProfile2D(soilProfile); + Assert.AreEqual(0, dsmGeometryEditor.Project.SoilProfiles2D[0].CenterCrestLocation); + + spatialEditor.EmptySelection = new EmptyShape(soilProfile); + // expected Centercrest at center + dsmGeometryEditor.InsertSpecificMechanismPointLocation(); + Assert.AreEqual((soilProfile.Geometry.Right - soilProfile.Geometry.Left) * 0.5, + dsmGeometryEditor.Project.SoilProfiles2D[0].CenterCrestLocation); + } } }