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; namespace Deltares.DSoilModel.Forms.Tests { [TestFixture] public class DSoilModelGeometryEditorTests { private DSoilModelGeometryEditor dsmGeometryEditor; private MainForm mainForm; private SpatialEditor spatialEditor; [SetUp] public void SetUp() { About.IgnoreAssemblyErrors = true; mainForm = new MainForm(); var project = new DSoilModelProject(); dsmGeometryEditor = new DSoilModelGeometryEditor(mainForm) { Project = project }; spatialEditor = dsmGeometryEditor.SpatialEditor; } [TearDown] public void TearDown() { dsmGeometryEditor = null; } private DSoilModelProject CreateProjectForSoilProfile2D(SoilProfile2D profile) { var p = new DSoilModelProject(); p.BoringLookup2Ds.Add(new BoringLookup2D {SoilProfile2D = profile}); 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; } private DSoilModelProject CreateProjectForSoilProfile1D(SoilProfile1D profile) { var p = new DSoilModelProject(); p.BoringLookup1Ds.Add(new BoringLookup1D { SoilProfile1D = profile }); p.CptLookup1Ds.Add(new ConePenetrationTestLookup1D { SoilProfile1D = profile }); return p; } 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 SoilProfile1D CreateSoilProfile1D() { var profile = new SoilProfile1D(); profile.Layers.Add(new SoilLayer1D()); profile.Layers.Add(new SoilLayer1D()); return profile; } [Test] public void ClearGeometryForSoilProfile1DTest() { var soilProfile1D = CreateSoilProfile1D(); dsmGeometryEditor.Project = CreateProjectForSoilProfile1D(soilProfile1D); dsmGeometryEditor.ClearGeometryForSoilProfile1D(soilProfile1D); Assert.IsEmpty(dsmGeometryEditor.Project.BoringLookup1Ds); Assert.IsEmpty(dsmGeometryEditor.Project.CptLookup1Ds); Assert.IsEmpty(soilProfile1D.Layers); } [Test] public void ClearGeometryForSoilProfile2DTest() { var soilProfile2D = CreateSoilProfile2D(); dsmGeometryEditor.Project = CreateProjectForSoilProfile2D(soilProfile2D); dsmGeometryEditor.ClearGeometryForSoilProfile2D(soilProfile2D); 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); Assert.IsEmpty(soilProfile2D.PreconsolidationStresses); Assert.IsEmpty(soilProfile2D.Surfaces); } [TestCase(null)] [TestCase("")] [TestCase("Name")] public void IsEnabledTest_AlwaysTrue(string propertyName) { 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("Ondergrondsegment " + 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.AddCenterCrestLocationTo2DProfile(); Assert.AreEqual((soilProfile.Geometry.Right - soilProfile.Geometry.Left) * 0.5, dsmGeometryEditor.Project.SoilProfiles2D[0].CenterCrestLocation); } } }