Index: DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs =================================================================== diff -u -r3118 -r3151 --- DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 3118) +++ DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 3151) @@ -91,6 +91,115 @@ } [Test] + public void GivenDamProjectWithValidLocationsWithMixedProfiles_WhenCreatingInput_ThenExpectedProfilesSerialized() + { + // Given + LogManager.Messages.Clear(); + + const string selectedLocationOneName = "SelectedLocationOne"; + const string selectedSegmentOneName = "SelectedSegmentOne"; + const string selectedLocationTwoName = "SelectedLocationTwo"; + const string selectedSegmentTwoName = "SelectedSegmentTwo"; + + var selectedLocations = new HashSet(new[] + { + selectedLocationOneName, + selectedLocationTwoName + }); + + const string firstSoilProfile1DName = "Profile1D"; + const string secondSoilProfile2DName = "Profile1D"; + const string profile2DName = "Profile2D 1"; + + var dike = new Dike + { + MapForSoilGeometries2D = @"TestData\FillXMLInputFromDamUI", + SoilList = CreateSoilList(new[] + { + "Soil 1", + "Soil 2", + "Soil 3" + }) + }; + + // Add the soil profile 1D + var firstSoilProfile1D = new SoilProfile1D + { + Name = firstSoilProfile1DName + }; + var secondSoilProfile1D = new SoilProfile1D + { + Name = secondSoilProfile2DName + }; + dike.SoilProfiles.AddRange(new[] + { + firstSoilProfile1D, + secondSoilProfile1D + }); + + // Add the locations with the segments + dike.Locations.AddRange(new[] + { + CreateSimpleLocationWithSoilProfile1DSegment(selectedLocationOneName, selectedSegmentOneName, firstSoilProfile1D), + CreateSimpleLocationWithSoilProfile1DSegment("DoesNotMatterLocation", "DoesNotMatterSegment", secondSoilProfile1D), + CreateSimpleLocationWithSoilProfile2DSegment(selectedLocationTwoName, selectedSegmentTwoName, profile2DName) + }); + + // Create the project to serialize + var waterBoard = new WaterBoard + { + Dikes = new List + { + dike + } + }; + + var projectData = new DamProjectData(); + FillAnalysisSpecification(projectData); + FillStabilityParameters(projectData); + DamProject.ProjectMap = ""; // Set the folder to be empty so that it runs in the current test directory + projectData.WaterBoard = waterBoard; + foreach (LocationJob locationJob in projectData.LocationJobs) + { + if (selectedLocations.Contains(locationJob.Name)) + { + locationJob.Run = true; + } + } + + // Precondition + // Assert that the "NotCalculated" calculations are not selected to verify that these: + // - Locations and segments do not end up in the input + // - Do not generate an error message in case something goes wrong. + CollectionAssert.AreEquivalent(selectedLocations, projectData.SelectedLocationJobs.Select(job => job.Name)); + + // When + Input input = FillXmlInputFromDamUi.CreateInput(projectData); + + // Then + // Note that the original test setup of DAMProject --> XML --> DAMProject does not + // work in this context, as there is NO field within DAMProject to contain the SoilProfile2D + // The only way to assert that the selected locations, segments and their profiles are present, + // is to verify the XMLInput objects that are generated by the CreateInput() call. + CollectionAssert.AreEquivalent(selectedLocations, input.Locations.Select(loc => loc.Name)); + CollectionAssert.AreEquivalent(new[] + { + selectedSegmentOneName, + selectedSegmentTwoName + }, input.Segments.Select(segment => segment.Name)); + + CollectionAssert.AreEquivalent(new[] + { + firstSoilProfile1DName, + secondSoilProfile2DName + }, input.SoilProfiles1D.Select(profile => profile.Name)); + CollectionAssert.AreEquivalent(new[] + { + profile2DName + }, input.SoilProfiles2D.Select(profile => profile.Name)); + } + + [Test] public void GivenDamProjectWithValidLocationsWith2DProfiles_WhenCreatingInput_ThenSelectedLocationsSerialized() { // Given @@ -462,6 +571,32 @@ return location; } + private Location CreateSimpleLocationWithSoilProfile1DSegment(string locationName, + string segmentName, + SoilProfile1D soilProfile) + { + var surfaceLine = new SurfaceLine2 + { + Name = $"SurfaceLine - {locationName}" + }; + surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry; + AddPointsToSurfaceLines(surfaceLine); + + var random = new Random(21); + var segment = new Segment + { + Name = segmentName + }; + segment.AddSoilProfileProbability(soilProfile, random.NextDouble(), null); + + var location = new Location(locationName) + { + LocalXZSurfaceLine2 = surfaceLine, + Segment = segment + }; + return location; + } + private static Scenario CreateValidScenario(string scenarioName) { var random = new Random(21);