Index: DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs =================================================================== diff -u -r3075 -r3084 --- DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 3075) +++ DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 3084) @@ -177,6 +177,77 @@ } [Test] + public void GivenDamProjectWithValidLocationsWithTheSame2DProfiles_WhenCreatingInput_ThenSelectedLocationsAndOneSoilProfileSerialized() + { + // Given + LogManager.Messages.Clear(); + + const string selectedLocationOneName = "SelectedLocationOne"; + const string selectedSegmentOneName = "SelectedSegmentOne"; + const string soilProfileName = "Profile2D 1.sti"; + const string selectedLocationTwoName = "SelectedLocationTwo"; + const string selectedSegmentTwoName = "SelectedSegmentTwo"; + + // Add the locations with the segments + var dike = new Dike + { + MapForSoilGeometries2D = @"TestData\FillXMLInputFromDamUI", + SoilList = CreateSoilList(new[] + { + "Soil 1", + "Soil 2" + }) + }; + dike.Locations.AddRange(new[] + { + CreateSimpleLocationWithSoilProfile2DSegment(selectedLocationOneName, selectedSegmentOneName, soilProfileName), + CreateSimpleLocationWithSoilProfile2DSegment(selectedLocationTwoName, selectedSegmentTwoName, soilProfileName) + }); + + // 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) + { + locationJob.Run = true; + } + + // 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(new[] + { + selectedLocationOneName, + selectedLocationTwoName + }, input.Locations.Select(loc => loc.Name)); + CollectionAssert.AreEquivalent(new[] + { + selectedSegmentOneName, + selectedSegmentTwoName + }, input.Segments.Select(segment => segment.Name)); + CollectionAssert.AreEquivalent(new[] + { + soilProfileName + }, input.SoilProfiles2D.Select(profile => profile.Name)); + } + + [Test] public void GivenDamProjectWithInvalidLocationsWithoutScenariosWith2DProfiles_WhenCreatingInput_ThenOnlyValidLocationsSerializedAndLogsErrorMessage() { // Given Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs =================================================================== diff -u -r3074 -r3084 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 3074) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 3084) @@ -770,20 +770,31 @@ /// The collection of to filter. /// The directory to retrieve the soil profiles from. /// The containing the available soils. - /// The collection of that is contained by the . + /// The collection of that is contained + /// by the . /// A collection of on which calculations can be performed. private static IEnumerable FilterLocationJobsWithSoilProfiles(IEnumerable locationJobs, string soilProfileDirectory, SoilList availableSoils, - List soilProfile) + List containedSoilProfiles) { var validJobs = new List(); + var uniqueSoilProfileNames = new HashSet(); foreach (LocationJob locationJob in locationJobs) { Location location = locationJob.Location; try { - soilProfile.AddRange(GetSoilProfiles(soilProfileDirectory, location.Segment, availableSoils)); + foreach (SoilProfile2D soilProfile in GetSoilProfiles(soilProfileDirectory, location.Segment, availableSoils)) + { + string soilProfileName = soilProfile.Name; + if (!uniqueSoilProfileNames.Contains(soilProfileName)) + { + uniqueSoilProfileNames.Add(soilProfileName); + containedSoilProfiles.Add(soilProfile); + } + } + validJobs.Add(locationJob); } catch (Exception e) when (e is ConversionException || e is SoilProfileImporterException)