using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; using Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStability; using Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStability.Assemblers; using Deltares.DamEngine.Data.Design; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Logging; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.DamMacroStability { [TestFixture] public class MStabXmlDocTests { [Test] public void TestCreateMStabXmlDoc() { List errorMessages; var stabilityProjectFilename = "testproject"; const string soilGeometry2DName = @"KernelWrappers\DamMacroStability\TestData\1D1.sti"; const string soilDbName = @"KernelWrappers\DamMacroStability\TestData\soilmaterials.mdb"; var requiredSafetyFactor = 1.2; var line = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(); var location = new Location(); var scenario = CreateScenarioForLocation(location, line); scenario.Location.SoildatabaseName = soilDbName; var surfaceLine = scenario.Location.SurfaceLine; var trafficLoad = 10.0; var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.StiFileName = soilGeometry2DName; subSoilScenario.SoilProfileType = SoilProfileType.ProfileTypeStiFile; subSoilScenario.SegmentFailureMechanismType = FailureMechanismSystemType.StabilityInside; // ToDo mStabDesignEmbankment for now set to null XDocument mstabXml = MStabXmlDoc.CreateMStabXmlDoc(stabilityProjectFilename, scenario, subSoilScenario, scenario.RiverLevel, null, surfaceLine, trafficLoad, requiredSafetyFactor, out errorMessages); mstabXml.Save(stabilityProjectFilename + ".xml"); XElement inputElement = (from element in mstabXml.Root.Descendants() where element.Name.LocalName == DamMStabAssembler.XmlElementNameInput select element).Single(); var attribute = inputElement.Attribute(DamMStabAssembler.XmlAttributeMStabFileName); Assert.IsNotNull(attribute); Assert.AreEqual(stabilityProjectFilename, attribute.Value); } public static DesignScenario CreateScenarioForLocation(Location location, SurfaceLine2 surfaceLine) { DesignScenario scenario = new DesignScenario(); scenario.Location = location; scenario.Location.DamType = DamType.Regional; scenario.Location.Name = "LocationName"; scenario.Location.DikeEmbankmentMaterial = "OB1"; scenario.Location.ShoulderEmbankmentMaterial = "OB2"; scenario.Location.SoilList = CreateSoilList(); scenario.LocationScenarioID = "ScenarioID"; scenario.Location.SurfaceLine = surfaceLine; return scenario; } private static SoilList CreateSoilList() { var soilList = new SoilList(); var s1 = new Soil("DKN5") { AbovePhreaticLevel = 17.5, BelowPhreaticLevel = 17.50 }; soilList.Soils.Add(s1); var s2 = new Soil("DKN4") { AbovePhreaticLevel = 17.16, BelowPhreaticLevel = 17.16 }; soilList.Soils.Add(s2); var s3 = new Soil("OA") { AbovePhreaticLevel = 18.00, BelowPhreaticLevel = 20.00 }; soilList.Soils.Add(s3); var s4 = new Soil("DKN3"); soilList.Soils.Add(s4); var s5 = new Soil("LM"); soilList.Soils.Add(s5); var s6 = new Soil("OB1"); soilList.Soils.Add(s6); var s7 = new Soil("OB2"); soilList.Soils.Add(s7); return soilList; } } }