Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileReader.cs =================================================================== diff -u -rbf334f50530164badedba45a78f3aab857ae1bf6 -r3f6060a9d5e2b63619d407706139325e8efb05df --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileReader.cs (.../StochasticSoilProfileReader.cs) (revision bf334f50530164badedba45a78f3aab857ae1bf6) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileReader.cs (.../StochasticSoilProfileReader.cs) (revision 3f6060a9d5e2b63619d407706139325e8efb05df) @@ -33,7 +33,8 @@ namespace Ringtoets.Piping.IO.SoilProfile { /// - /// This class reads a DSoil database file and reads from this database. + /// This class reads a DSoil database file and reads + /// from this database. /// public class StochasticSoilProfileReader : SqLiteDatabaseReaderBase { @@ -57,18 +58,24 @@ } /// - /// Gets a value indicating whether or not more stochastic soil profiles can be read using - /// the . + /// Gets a value indicating whether or not more stochastic soil profiles can be read + /// using the . /// public bool HasNext { get; private set; } /// - /// Reads the information for the next stochastic soil profile from the database and creates a - /// instance of the information. + /// Reads the information for the next stochastic soil profile from the database + /// and creates a instance of the information. /// - /// Identifier of the next to look for. - /// The next from the database, or null if no more stochastic soil profiles can be read. - /// Thrown when the database returned incorrect values for required properties. + /// Identifier of the next + /// to look for. + /// The next from the database, or null + /// if no more stochastic soil profiles can be read. + /// Thrown when the database returned + /// incorrect values for required properties. + /// Rows are being read in ascending order based on the database ID of the + /// stochastic soil model. Therefore once a stochastic soil model has been read already, + /// it will not be found with this method. public StochasticSoilProfile ReadStochasticSoilProfile(long stochasticSoilModelId) { if (!HasNext) @@ -90,7 +97,8 @@ { if (exception is FormatException || exception is OverflowException || exception is InvalidCastException) { - var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilProfileDatabaseReader_StochasticSoilProfile_has_invalid_value); + var message = new FileReaderErrorMessageBuilder(Path) + .Build(Resources.StochasticSoilProfileDatabaseReader_StochasticSoilProfile_has_invalid_value); throw new StochasticSoilProfileReadException(message, exception); } throw; @@ -107,10 +115,11 @@ } /// - /// Prepares a new data reader with queries for obtaining the profiles and updates the reader - /// so that it points to the first row of the result set. + /// Prepares a new data reader with queries for obtaining the profiles and updates + /// the reader so that it points to the first row of the result set. /// - /// A query could not be executed on the database schema. + /// A query could not be executed on + /// the database schema. private void InitializeReader() { CreateDataReader(); @@ -135,7 +144,8 @@ catch (SQLiteException exception) { CloseConnection(); - var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilModelDatabaseReader_Failed_to_read_database); + var message = new FileReaderErrorMessageBuilder(Path) + .Build(Resources.StochasticSoilModelDatabaseReader_Failed_to_read_database); throw new CriticalFileReadException(message, exception); } } @@ -201,7 +211,8 @@ return soilProfile2DId; } - var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilProfileDatabaseReader_StochasticSoilProfile_has_invalid_value); + var message = new FileReaderErrorMessageBuilder(Path) + .Build(Resources.StochasticSoilProfileDatabaseReader_StochasticSoilProfile_has_invalid_value); throw new StochasticSoilProfileReadException(message); } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -rbf334f50530164badedba45a78f3aab857ae1bf6 -r3f6060a9d5e2b63619d407706139325e8efb05df --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision bf334f50530164badedba45a78f3aab857ae1bf6) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 3f6060a9d5e2b63619d407706139325e8efb05df) @@ -185,12 +185,18 @@ private bool ValidateStochasticSoilModel(StochasticSoilModel stochasticSoilModel) { - if (stochasticSoilModel.StochasticSoilProfiles.Any(s => s.SoilProfile == null)) + if (!stochasticSoilModel.StochasticSoilProfiles.Any()) { log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_ValidateStochasticSoilModel_No_profiles_found_in_stochastic_soil_model_0, stochasticSoilModel.Name); return false; } + if (stochasticSoilModel.StochasticSoilProfiles.Any(ssp => ssp.SoilProfile == null)) + { + log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_ValidateStochasticSoilModel_SoilModel_0_with_stochastic_soil_profile_without_profile, + stochasticSoilModel.Name); + return false; + } if (!IsSumOfAllProbabilitiesEqualToOne(stochasticSoilModel)) { log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_ValidateStochasticSoilModel_Sum_of_probabilities_of_stochastic_soil_model_0_is_not_correct, @@ -212,7 +218,7 @@ return ((StochasticSoilModelContext) targetItem).AssessmentSection.ReferenceLine != null; } - private void HandleException(string path, Exception e) + private void HandleException(Exception e) { var message = string.Format(RingtoetsPluginResources.PipingSoilProfilesImporter_CriticalErrorMessage_0_File_Skipped, e.Message); @@ -235,17 +241,17 @@ { using (var stochasticSoilModelReader = new StochasticSoilModelReader(path)) { - return GetStochasticSoilModelReadResult(path, stochasticSoilModelReader); + return GetStochasticSoilModelReadResult(stochasticSoilModelReader); } } catch (CriticalFileReadException e) { - HandleException(path, e); + HandleException(e); } return new ReadResult(true); } - private ReadResult GetStochasticSoilModelReadResult(string path, StochasticSoilModelReader stochasticSoilModelReader) + private ReadResult GetStochasticSoilModelReadResult(StochasticSoilModelReader stochasticSoilModelReader) { var totalNumberOfSteps = stochasticSoilModelReader.PipingStochasticSoilModelCount; var currentStep = 1; @@ -290,7 +296,7 @@ } catch (CriticalFileReadException e) { - HandleException(path, e); + HandleException(e); } return new ReadResult(true); } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -rd2a52a4a27bba0bcf0437e905fe3985484c0219c -r3f6060a9d5e2b63619d407706139325e8efb05df --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d2a52a4a27bba0bcf0437e905fe3985484c0219c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3f6060a9d5e2b63619d407706139325e8efb05df) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.18444 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -186,7 +186,7 @@ } /// - /// Looks up a localized string similar to Er zijn geen profielen gevonden in het stochastich ondersgrondmodel '{0}', deze wordt overgeslagen.. + /// Looks up a localized string similar to Er zijn geen profielen gevonden in het stochastisch ondersgrondmodel '{0}', deze wordt overgeslagen.. /// public static string PipingSoilProfilesImporter_ValidateStochasticSoilModel_No_profiles_found_in_stochastic_soil_model_0 { get { @@ -196,6 +196,16 @@ } /// + /// Looks up a localized string similar to Het stochastisch ondergrondmodel '{0}' heeft een stochastisch profiel zonder grondprofiel, deze wordt overgeslagen.. + /// + public static string PipingSoilProfilesImporter_ValidateStochasticSoilModel_SoilModel_0_with_stochastic_soil_profile_without_profile { + get { + return ResourceManager.GetString("PipingSoilProfilesImporter_ValidateStochasticSoilModel_SoilModel_0_with_stochasti" + + "c_soil_profile_without_profile", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De som van de kans van voorkomen in het stochastich ondergrondmodel '{0}' is niet gelijk aan 100%.. /// public static string PipingSoilProfilesImporter_ValidateStochasticSoilModel_Sum_of_probabilities_of_stochastic_soil_model_0_is_not_correct { Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -rd2a52a4a27bba0bcf0437e905fe3985484c0219c -r3f6060a9d5e2b63619d407706139325e8efb05df --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision d2a52a4a27bba0bcf0437e905fe3985484c0219c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 3f6060a9d5e2b63619d407706139325e8efb05df) @@ -222,7 +222,7 @@ Er is geen referentielijn beschikbaar. Geen data ingelezen. - Er zijn geen profielen gevonden in het stochastich ondersgrondmodel '{0}', deze wordt overgeslagen. + Er zijn geen profielen gevonden in het stochastisch ondersgrondmodel '{0}', deze wordt overgeslagen. Inlezen van de stochastische ondergrondmodellen. @@ -251,4 +251,7 @@ Klaar met het inlezen van karakteristieke punten uit bestand '{0}'. + + Het stochastisch ondergrondmodel '{0}' heeft een stochastisch profiel zonder grondprofiel, deze wordt overgeslagen. + \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs =================================================================== diff -u -rd2a52a4a27bba0bcf0437e905fe3985484c0219c -r3f6060a9d5e2b63619d407706139325e8efb05df --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision d2a52a4a27bba0bcf0437e905fe3985484c0219c) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 3f6060a9d5e2b63619d407706139325e8efb05df) @@ -182,8 +182,11 @@ } // Assert - Assert.AreEqual(2, pipingSoilProfilesReader.Count); - Assert.AreEqual(2, result.Count); + const int expectedNumberOfProfiles = 2; + Assert.AreEqual(expectedNumberOfProfiles, pipingSoilProfilesReader.Count); + Assert.AreEqual(expectedNumberOfProfiles, result.Count); + Assert.AreEqual(SoilProfileType.SoilProfile2D, result[0].SoilProfileType); + Assert.AreEqual(SoilProfileType.SoilProfile1D, result[1].SoilProfileType); Assert.AreEqual(result[0].Name, result[1].Name); } } @@ -458,14 +461,14 @@ [SetCulture("nl-NL")] public void GivenACompleteDatabaseAndDutchLocale_WhenReadingTheCompleteDatabase_Returns2ProfilesWithLayersAndGeometries() { - GivenACompleteDatabase_WhenReadingTheCompleteDatabase_Returns2ProfilesWithLayersAndGeometries(); + GivenACompleteDatabase_WhenReadingTheCompleteDatabase_ReturnsProfilesWithLayersAndGeometries(); } [Test] [SetCulture("en-US")] public void GivenACompleteDatabaseAndEnglishLocale_WhenReadingTheCompleteDatabase_Returns2ProfilesWithLayersAndGeometries() { - GivenACompleteDatabase_WhenReadingTheCompleteDatabase_Returns2ProfilesWithLayersAndGeometries(); + GivenACompleteDatabase_WhenReadingTheCompleteDatabase_ReturnsProfilesWithLayersAndGeometries(); } private void GivenDatabaseWith1DProfile_WhenReadingTheCompleteDatabase_ReturnsCompleteSoilProfile() @@ -504,7 +507,7 @@ } } - private void GivenACompleteDatabase_WhenReadingTheCompleteDatabase_Returns2ProfilesWithLayersAndGeometries() + private void GivenACompleteDatabase_WhenReadingTheCompleteDatabase_ReturnsProfilesWithLayersAndGeometries() { // Setup var testFile = "complete.soil"; Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/PipingSoilProfilesReader/reusedSoilProfile1D.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/PipingSoilProfilesReader/reusedSoilProfile2D.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs =================================================================== diff -u -rc4d2af65ad23757fb3bd11f93458839bc1787ded -r3f6060a9d5e2b63619d407706139325e8efb05df --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision c4d2af65ad23757fb3bd11f93458839bc1787ded) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision 3f6060a9d5e2b63619d407706139325e8efb05df) @@ -8,11 +8,12 @@ using Core.Common.Utils.Builders; using NUnit.Framework; using Rhino.Mocks; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Plugin.FileImporter; +using Ringtoets.Piping.Primitives; + using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; using ApplicationResources = Ringtoets.Piping.Plugin.Properties.Resources; @@ -469,7 +470,7 @@ { string.Format(ApplicationResources.PipingSoilProfilesImporter_ReadSoilProfiles_ParseErrorMessage_0_SoilProfile_skipped, internalErrorMessage), - string.Format("Er zijn geen profielen gevonden in het stochastich ondersgrondmodel '{0}', deze wordt overgeslagen.", "Name") + string.Format("Het stochastisch ondergrondmodel '{0}' heeft een stochastisch profiel zonder grondprofiel, deze wordt overgeslagen.", "Name") }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); @@ -578,6 +579,119 @@ mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver } + [Test] + public void Import_TwoSoilModelsReusingSameProfile1D_ImportSoilModelsToCollection() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "reusedSoilProfile1D.soil"); + + var pipingFailureMechanism = new PipingFailureMechanism(); + var assessmentSection = mockRepository.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + mockRepository.ReplayAll(); + + var importer = new PipingSoilProfilesImporter(); + + var context = new StochasticSoilModelContext(pipingFailureMechanism, assessmentSection); + + // Call + var importResult = importer.Import(context, validFilePath); + + // Assert + Assert.IsTrue(importResult); + + Assert.AreEqual(2, pipingFailureMechanism.StochasticSoilModels.Count); + StochasticSoilModel model1 = pipingFailureMechanism.StochasticSoilModels[0]; + StochasticSoilModel model2 = pipingFailureMechanism.StochasticSoilModels[1]; + + Assert.AreEqual(1, model1.StochasticSoilProfiles.Count); + Assert.AreEqual(1, model2.StochasticSoilProfiles.Count); + + StochasticSoilProfile profile1 = model1.StochasticSoilProfiles[0]; + StochasticSoilProfile profile2 = model2.StochasticSoilProfiles[0]; + Assert.AreNotSame(profile1, profile2); + Assert.AreSame(profile1.SoilProfile, profile2.SoilProfile); + + Assert.AreEqual(SoilProfileType.SoilProfile1D, profile1.SoilProfileType, + "Expected database to have 1D profiles."); + Assert.AreEqual(SoilProfileType.SoilProfile1D, profile2.SoilProfileType, + "Expected database to have 1D profiles."); + + mockRepository.VerifyAll(); + } + + [Test] + public void Import_TwoSoilModelsReusingSameProfile2D_ImportSoilModelsToCollection() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "reusedSoilProfile2D.soil"); + + var pipingFailureMechanism = new PipingFailureMechanism(); + var assessmentSection = mockRepository.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + mockRepository.ReplayAll(); + + var importer = new PipingSoilProfilesImporter(); + + var context = new StochasticSoilModelContext(pipingFailureMechanism, assessmentSection); + + // Call + var importResult = importer.Import(context, validFilePath); + + // Assert + Assert.IsTrue(importResult); + + Assert.AreEqual(2, pipingFailureMechanism.StochasticSoilModels.Count); + StochasticSoilModel model1 = pipingFailureMechanism.StochasticSoilModels[0]; + StochasticSoilModel model2 = pipingFailureMechanism.StochasticSoilModels[1]; + + Assert.AreEqual(1, model1.StochasticSoilProfiles.Count); + Assert.AreEqual(1, model2.StochasticSoilProfiles.Count); + + StochasticSoilProfile profile1 = model1.StochasticSoilProfiles[0]; + StochasticSoilProfile profile2 = model2.StochasticSoilProfiles[0]; + Assert.AreNotSame(profile1, profile2); + Assert.AreSame(profile1.SoilProfile, profile2.SoilProfile); + + Assert.AreEqual(SoilProfileType.SoilProfile2D, profile1.SoilProfileType, + "Expected database to have 2D profiles."); + Assert.AreEqual(SoilProfileType.SoilProfile2D, profile2.SoilProfileType, + "Expected database to have 2D profiles."); + + mockRepository.VerifyAll(); + } + + [Test] + public void Import_ModelWithOneInvalidStochasticSoilProfileDueToMissingProfile_SkipModelAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "EmptySoilModel.soil"); + + var observer = mockRepository.StrictMock(); + var assessmentSection = mockRepository.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); + mockRepository.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); + + var importer = new PipingSoilProfilesImporter(); + + var importResult = false; + + // Call + Action call = () => importResult = importer.Import(context, validFilePath); + + // Assert + var expectedLogMessage = @"Er zijn geen profielen gevonden in het stochastisch ondersgrondmodel 'Model', deze wordt overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); + Assert.AreEqual(0, failureMechanism.StochasticSoilModels.Count); + Assert.IsTrue(importResult); + + mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver + } + private void IncrementProgress(string a, int b, int c) { progress++;