Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDikeAssessmentSectionCommand.cs =================================================================== diff -u -r1e49eb86c81e8446aeb6031cfd7a209bb0c11bac -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDikeAssessmentSectionCommand.cs (.../AddNewDemoDikeAssessmentSectionCommand.cs) (revision 1e49eb86c81e8446aeb6031cfd7a209bb0c11bac) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDikeAssessmentSectionCommand.cs (.../AddNewDemoDikeAssessmentSectionCommand.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -114,7 +114,8 @@ using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "DR6.soil")) { var surfaceLinesImporter = new PipingSoilProfilesImporter(); - surfaceLinesImporter.Import(pipingFailureMechanism.SoilProfiles, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil")); + var context = new StochasticSoilModelContext(pipingFailureMechanism, demoAssessmentSection); + surfaceLinesImporter.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil")); } var calculation = pipingFailureMechanism.CalculationsGroup.GetPipingCalculations().First(); Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanism.cs =================================================================== diff -u -r0c05978e0502e47090bffa6f5716c91dae3e7150 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanism.cs (.../PipingFailureMechanism.cs) (revision 0c05978e0502e47090bffa6f5716c91dae3e7150) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanism.cs (.../PipingFailureMechanism.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -20,7 +20,7 @@ // All rights reserved. using System.Collections.Generic; - +using System.Linq; using Core.Common.Base; using Ringtoets.Common.Data; using Ringtoets.Common.Placeholder; @@ -44,13 +44,13 @@ SemiProbabilisticInput = new SemiProbabilisticPipingInput(); GeneralInput = new GeneralPipingInput(); SurfaceLines = new ObservableList(); - SoilProfiles = new ObservableList(); + StochasticSoilModels = new ObservableList(); var pipingCalculationGroup = new PipingCalculationGroup(PipingDataResources.PipingFailureMechanism_Calculations_DisplayName, false); pipingCalculationGroup.Children.Add(new PipingCalculation(GeneralInput, SemiProbabilisticInput)); CalculationsGroup = pipingCalculationGroup; AssessmentResult = new OutputPlaceholder(RingtoetsCommonDataResources.FailureMechanism_AssessmentResult_DisplayName); } - + public override IEnumerable CalculationItems { get @@ -79,9 +79,20 @@ /// /// Gets the available profiles within the scope of the piping failure mechanism. /// - public ObservableList SoilProfiles { get; private set; } + public ICollection SoilProfiles + { + get + { + return StochasticSoilModels.SelectMany(ssm => ssm.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile)).ToList(); + } + } /// + /// Gets the available stochastic soil models within the scope of the piping failure mechanism. + /// + public ObservableList StochasticSoilModels { get; private set; } + + /// /// Gets all available piping calculations. /// public PipingCalculationGroup CalculationsGroup { get; private set; } Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs =================================================================== diff -u -r3bf7e84ac84de7dd0be38be7e9f2372878e733f6 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 3bf7e84ac84de7dd0be38be7e9f2372878e733f6) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -19,6 +19,8 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using Ringtoets.Piping.Primitives; + namespace Ringtoets.Piping.Data { /// @@ -53,5 +55,10 @@ /// Gets the probability of the stochastic soil profile. /// public double Probability { get; private set; } + + /// + /// Gets the . + /// + public PipingSoilProfile SoilProfile { get; set; } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/StochasticSoilModelContext.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/StochasticSoilModelContext.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/StochasticSoilModelContext.cs (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -0,0 +1,109 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base; +using Ringtoets.Common.Data; +using Ringtoets.Piping.Data; + +namespace Ringtoets.Piping.Forms.PresentationObjects +{ + /// + /// The presentation object for . + /// + public class StochasticSoilModelContext : IObservable + { + /// + /// Creates a new instance of . + /// + /// The failure mechanism to wrap. + /// The assessment section. + /// Thrown when or is null. + public StochasticSoilModelContext(PipingFailureMechanism failureMechanism, AssessmentSectionBase assessmentSection) + { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } + + FailureMechanism = failureMechanism; + AssessmentSection = assessmentSection; + } + + public PipingFailureMechanism FailureMechanism { get; private set; } + public AssessmentSectionBase AssessmentSection { get; private set; } + + #region IObservable + + public void Attach(IObserver observer) + { + FailureMechanism.Attach(observer); + } + + public void Detach(IObserver observer) + { + FailureMechanism.Detach(observer); + } + + public void NotifyObservers() + { + FailureMechanism.NotifyObservers(); + } + + #endregion + + #region Equatible + + private bool Equals(StochasticSoilModelContext other) + { + return Equals(FailureMechanism, other.FailureMechanism); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((StochasticSoilModelContext) obj); + } + + public override int GetHashCode() + { + return FailureMechanism.GetHashCode(); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -r1e49eb86c81e8446aeb6031cfd7a209bb0c11bac -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 1e49eb86c81e8446aeb6031cfd7a209bb0c11bac) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -61,6 +61,7 @@ + True Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs =================================================================== diff -u -r0c05978e0502e47090bffa6f5716c91dae3e7150 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision 0c05978e0502e47090bffa6f5716c91dae3e7150) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -39,13 +39,13 @@ /// public partial class PipingCalculationsView : UserControl, IView { + private readonly RecursiveObserver pipingCalculationGroupObserver; + private readonly Observer pipingSoilProfilesObserver; private AssessmentSectionBase assessmentSection; private PipingFailureMechanism pipingFailureMechanism; private PipingCalculationGroup pipingCalculationGroup; private DataGridViewComboBoxColumn soilProfileColumn; private DataGridViewComboBoxColumn hydraulicBoundaryLocationColumn; - private readonly RecursiveObserver pipingCalculationGroupObserver; - private readonly Observer pipingSoilProfilesObserver; /// /// Creates a new instance of the class. @@ -72,7 +72,7 @@ { pipingFailureMechanism = value; - pipingSoilProfilesObserver.Observable = pipingFailureMechanism != null ? pipingFailureMechanism.SoilProfiles : null; + pipingSoilProfilesObserver.Observable = pipingFailureMechanism != null ? pipingFailureMechanism.StochasticSoilModels : null; UpdateSoilProfileColumn(); } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -r619f3fd6896edb6d7f6ac160fcfc66054883dce4 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 619f3fd6896edb6d7f6ac160fcfc66054883dce4) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -23,11 +23,13 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; +using System.Linq; using Core.Common.Base.IO; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; using log4net; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.SoilProfile; using Ringtoets.Piping.Primitives; @@ -40,7 +42,7 @@ /// /// Imports .soil files (SqlLite database files) created with the DSoilModel application. /// - public class PipingSoilProfilesImporter : FileImporterBase> + public class PipingSoilProfilesImporter : FileImporterBase { private readonly ILog log = LogManager.GetLogger(typeof(PipingSoilProfilesImporter)); @@ -81,11 +83,10 @@ public override bool Import(object targetItem, string filePath) { - if (!IsReferenceLineAvailable(targetItem)) + var surfaceLinesContext = (StochasticSoilModelContext) targetItem; + if (!IsReferenceLineAvailable(surfaceLinesContext)) { - var message = String.Format(RingtoetsPluginResources.PipingSoilProfilesImporter_ReadSoilProfiles_ParseErrorMessage_0_SoilProfile_skipped, - RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Import_Required_referenceline_missing); - log.Error(message); + log.Error(RingtoetsPluginResources.PipingSoilProfilesImporter_Import_Required_referenceline_missing); return false; } @@ -101,16 +102,99 @@ return false; } - AddImportedDataToModel(targetItem, importSoilProfileResult); + var importStochasticSoilModelResult = ReadStochasticSoilModels(filePath); + if (importStochasticSoilModelResult.CriticalErrorOccurred) + { + return false; + } + + if (ImportIsCancelled) + { + HandleUserCancellingImport(); + return false; + } + + AddSoilProfilesToStochasticSoilModels(importSoilProfileResult.ImportedItems, importStochasticSoilModelResult.ImportedItems); + + CheckIfAllProfilesAreUsed(importSoilProfileResult.ImportedItems, importStochasticSoilModelResult.ImportedItems); + + AddImportedDataToModel(surfaceLinesContext, importStochasticSoilModelResult.ImportedItems); return true; } - private static bool IsReferenceLineAvailable(object targetItem) + private void AddSoilProfilesToStochasticSoilModels(ICollection soilProfiles, ICollection stochasticSoilModels) { - //return ((RingtoetsPipingSurfaceLinesContext) targetItem).AssessmentSection.ReferenceLine != null; + foreach (var stochasticSoilModel in stochasticSoilModels) + { + foreach (var stochasticSoilProfile in stochasticSoilModel.StochasticSoilProfiles) + { + var soilProfile = soilProfiles.FirstOrDefault(s => s.PipingSoilProfileId == stochasticSoilProfile.SoilProfileId); + if (soilProfile != null) + { + stochasticSoilProfile.SoilProfile = soilProfile; + } + } + } + } + + private void CheckIfAllProfilesAreUsed(ICollection soilProfiles, ICollection stochasticSoilModels) + { + foreach (var soilProfile in soilProfiles.Where(soilProfile => !PipingSoilProfileIsUsed(soilProfile, stochasticSoilModels))) + { + log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_CheckIfAllProfilesAreUsed_SoilProfile_0_is_not_used_in_any_stochastic_soil_model, soilProfile.Name); + } + } + + private static bool PipingSoilProfileIsUsed(PipingSoilProfile soilProfile, ICollection stochasticSoilModels) + { + return stochasticSoilModels.Any(stochasticSoilModel => stochasticSoilModel.StochasticSoilProfiles.Any(stochasticSoilProfile => stochasticSoilProfile.SoilProfile == soilProfile)); + } + + private void AddImportedDataToModel(StochasticSoilModelContext target, ICollection readStochasticSoilModels) + { + var targetCollection = target.FailureMechanism.StochasticSoilModels; + var stochasticSoilModelCount = readStochasticSoilModels.Count; + var currentIndex = 1; + foreach (var readStochasticSoilModel in readStochasticSoilModels) + { + NotifyProgress(RingtoetsPluginResources.PipingSoilProfilesImporter_Adding_imported_data_to_model, currentIndex++, stochasticSoilModelCount); + if (!ValidateStochasticSoilModel(readStochasticSoilModel)) + { + continue; + } + var stochasticSoilModel = targetCollection.FirstOrDefault(ssm => ssm.Id == readStochasticSoilModel.Id); + if (stochasticSoilModel != null) + { + log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_AddImportedDataToModel_Stochastisch_soil_model_0_already_exists, stochasticSoilModel.Name); + } + targetCollection.Add(readStochasticSoilModel); + } + } + + private bool ValidateStochasticSoilModel(StochasticSoilModel stochasticSoilModel) + { + if (stochasticSoilModel.StochasticSoilProfiles.Count(s => s.SoilProfile == null) > 0) + { + log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_ValidateStochasticSoilModel_No_profiles_found_in_stochastic_soil_model_0, stochasticSoilModel.Name); + return false; + } + if (stochasticSoilModel.Geometry.Count == 0) + { + log.WarnFormat("Er zijn geen coordinaten gevonden in het stochastich ondersgrondmodel '{0}', deze wordt overgeslagen.", stochasticSoilModel.Name); + return false; + } + if (!stochasticSoilModel.StochasticSoilProfiles.Where(s => s.SoilProfile != null).Sum(s => s.Probability).Equals(1.0)) + { + log.WarnFormat("De som van de kans van voorkomen in stochastich ondersgrondmodel '{0}' is niet gelijk aan 1.", stochasticSoilModel.Name); + } return true; } + private static bool IsReferenceLineAvailable(StochasticSoilModelContext targetItem) + { + return targetItem.AssessmentSection.ReferenceLine != null; + } + private void HandleException(string path, Exception e) { var message = string.Format(RingtoetsPluginResources.PipingSoilProfilesImporter_CriticalErrorMessage_0_File_Skipped, @@ -203,18 +287,6 @@ return new ReadResult(true); } - private void AddImportedDataToModel(object target, ReadResult imported) - { - var targetCollection = (ICollection) target; - - int totalProfileCount = imported.ImportedItems.Count; - NotifyProgress(RingtoetsPluginResources.PipingSoilProfilesImporter_Adding_imported_data_to_model, totalProfileCount, totalProfileCount); - foreach (var item in imported.ImportedItems) - { - targetCollection.Add(item); - } - } - private ReadResult GetProfileReadResult(string path, PipingSoilProfileReader soilProfileReader) { var totalNumberOfSteps = soilProfileReader.Count; Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r619f3fd6896edb6d7f6ac160fcfc66054883dce4 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 619f3fd6896edb6d7f6ac160fcfc66054883dce4) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -70,6 +70,16 @@ } /// + /// Looks up a localized string similar to Het stochastisch ondergrondmodel '{0}' bestaat al in het faalmechanisme.. + /// + public static string PipingSoilProfilesImporter_AddImportedDataToModel_Stochastisch_soil_model_0_already_exists { + get { + return ResourceManager.GetString("PipingSoilProfilesImporter_AddImportedDataToModel_Stochastisch_soil_model_0_alrea" + + "dy_exists", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Geïmporteerde data toevoegen aan faalmechanisme. /// public static string PipingSoilProfilesImporter_Adding_imported_data_to_model { @@ -79,6 +89,16 @@ } /// + /// Looks up a localized string similar to Het uitgelezen profiel '{0}' niet wordt niet gebruikt in een van de stochastische ondergrondmodellen.. + /// + public static string PipingSoilProfilesImporter_CheckIfAllProfilesAreUsed_SoilProfile_0_is_not_used_in_any_stochastic_soil_model { + get { + return ResourceManager.GetString("PipingSoilProfilesImporter_CheckIfAllProfilesAreUsed_SoilProfile_0_is_not_used_in" + + "_any_stochastic_soil_model", resourceCulture); + } + } + + /// /// Looks up a localized string similar to {0} ///Het bestand wordt overgeslagen.. /// @@ -98,6 +118,15 @@ } /// + /// Looks up a localized string similar to Er is geen referentielijn beschikbaar. Geen data ingelezen.. + /// + public static string PipingSoilProfilesImporter_Import_Required_referenceline_missing { + get { + return ResourceManager.GetString("PipingSoilProfilesImporter_Import_Required_referenceline_missing", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Inlezen van de D-Soil Model database. /// public static string PipingSoilProfilesImporter_Reading_database { @@ -127,6 +156,16 @@ } /// + /// Looks up a localized string similar to Er zijn geen profielen gevonden in het stochastich ondersgrondmodel '{0}', deze wordt overgeslagen.. + /// + public static string PipingSoilProfilesImporter_ValidateStochasticSoilModel_No_profiles_found_in_stochastic_soil_model_0 { + get { + return ResourceManager.GetString("PipingSoilProfilesImporter_ValidateStochasticSoilModel_No_profiles_found_in_stoch" + + "astic_soil_model_0", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Karakteristieke punten gevonden zonder bijbehorende profielmeting voor locatie '{0}'.. /// public static string PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Characteristic_points_found_for_unknown_SurfaceLine_0_ { Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -r619f3fd6896edb6d7f6ac160fcfc66054883dce4 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 619f3fd6896edb6d7f6ac160fcfc66054883dce4) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -212,4 +212,16 @@ Inlezen van het profielmetingenbestand. + + Het stochastisch ondergrondmodel '{0}' bestaat al in het faalmechanisme. + + + Het uitgelezen profiel '{0}' niet wordt niet gebruikt in een van de stochastische ondergrondmodellen. + + + Er is geen referentielijn beschikbaar. Geen data ingelezen. + + + Er zijn geen profielen gevonden in het stochastich ondersgrondmodel '{0}', deze wordt overgeslagen. + \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/StochasticSoilModelContextTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/StochasticSoilModelContextTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/StochasticSoilModelContextTest.cs (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -0,0 +1,256 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; + +namespace Ringtoets.Piping.Forms.Test.PresentationObjects +{ + [TestFixture] + public class StochasticSoilModelContextTest + { + [Test] + public void ParameteredConstructor_DefaultValues() + { + // Setup + var mocks = new MockRepository(); + var failureMechanism = new PipingFailureMechanism(); + var assessmentSection = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf(context); + Assert.AreSame(failureMechanism, context.FailureMechanism); + Assert.AreSame(assessmentSection, context.AssessmentSection); + mocks.VerifyAll(); + } + + [Test] + public void ParameteredConstructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new StochasticSoilModelContext(null, assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void ParameteredConstructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + // Call + TestDelegate test = () => new StochasticSoilModelContext(failureMechanism, null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void NotifyObservers_ObserverAttached_NotifyObserver() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + context.Attach(observer); + + // Call + context.NotifyObservers(); + + // Assert + mocks.VerifyAll(); // Expect attach and notify observers on failure mechanism + } + + [Test] + public void NotifyObservers_ObserverDetached_NoCallsOnObserver() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + var presentationObject = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + // Call + presentationObject.Detach(observer); + + // Assert + mocks.VerifyAll(); // Expect detach from failure mechanism + } + + [Test] + public void Equals_ToItself_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(context); + + // Assert + Assert.IsTrue(isEqual); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + // Call + bool isEqual = context.Equals(null); + + // Assert + Assert.IsFalse(isEqual); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToEqualOtherInstance_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + var otherContext = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(otherContext); + bool isEqual2 = otherContext.Equals(context); + + // Assert + Assert.IsTrue(isEqual); + Assert.IsTrue(isEqual2); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToInequalOtherInstance_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + var otherFailureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + var otherContext = new StochasticSoilModelContext(otherFailureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(otherContext); + bool isEqual2 = otherContext.Equals(context); + + // Assert + Assert.IsFalse(isEqual); + Assert.IsFalse(isEqual2); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToInequalOtherObject_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + var otherContext = new Object(); + + // Call + bool isEqual = context.Equals(otherContext); + + // Assert + Assert.IsFalse(isEqual); + mocks.VerifyAll(); + } + + [Test] + public void GetHashCode_TwoContextInstancesEqualToEachOther_ReturnIdenticalHashes() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + + var otherContext = new StochasticSoilModelContext(failureMechanism, assessmentSection); + // Precondition + Assert.True(context.Equals(otherContext)); + + // Call + int contextHashCode = context.GetHashCode(); + int otherContextHashCode = otherContext.GetHashCode(); + + // Assert + Assert.AreEqual(contextHashCode, otherContextHashCode); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -r1e49eb86c81e8446aeb6031cfd7a209bb0c11bac -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 1e49eb86c81e8446aeb6031cfd7a209bb0c11bac) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -61,6 +61,7 @@ + @@ -182,6 +183,9 @@ + + Copying.licenseheader + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingFailureMechanismTreeNodeInfoTest.cs =================================================================== diff -u -r65ea41e01d41d77df1e30bf8e850a44de46e870f -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingFailureMechanismTreeNodeInfoTest.cs (.../PipingFailureMechanismTreeNodeInfoTest.cs) (revision 65ea41e01d41d77df1e30bf8e850a44de46e870f) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingFailureMechanismTreeNodeInfoTest.cs (.../PipingFailureMechanismTreeNodeInfoTest.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -118,7 +118,7 @@ Assert.AreEqual("Invoer", inputsFolder.Name); Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); - var failureMechanismSectionsContext = (FailureMechanismSectionsContext)inputsFolder.Contents[0]; + var failureMechanismSectionsContext = (FailureMechanismSectionsContext) inputsFolder.Contents[0]; CollectionAssert.AreEqual(pipingFailureMechanism.Sections, failureMechanismSectionsContext.WrappedData); Assert.AreSame(pipingFailureMechanism, failureMechanismSectionsContext.ParentFailureMechanism); Assert.AreSame(assessmentSection, failureMechanismSectionsContext.ParentAssessmentSection); @@ -136,7 +136,7 @@ Assert.AreEqual("Berekeningen", calculationsFolder.WrappedData.Name); CollectionAssert.AreEqual(pipingFailureMechanism.CalculationsGroup.Children, calculationsFolder.WrappedData.Children); Assert.AreSame(pipingFailureMechanism.SurfaceLines, calculationsFolder.AvailablePipingSurfaceLines); - Assert.AreSame(pipingFailureMechanism.SoilProfiles, calculationsFolder.AvailablePipingSoilProfiles); + Assert.AreEqual(pipingFailureMechanism.SoilProfiles, calculationsFolder.AvailablePipingSoilProfiles); Assert.AreSame(pipingFailureMechanism, calculationsFolder.PipingFailureMechanism); var outputsFolder = (CategoryTreeFolder) children[2]; @@ -328,14 +328,17 @@ }; var dataMock = mocks.StrictMock(); - dataMock.Stub(dm => dm.CalculationItems).Return(new ICalculationItem[] { pipingCalculation }); + dataMock.Stub(dm => dm.CalculationItems).Return(new ICalculationItem[] + { + pipingCalculation + }); var assessmentSection = mocks.Stub(); var failureMechanismContext = new PipingFailureMechanismContext(dataMock, assessmentSection); var gui = mocks.StrictMock(); gui.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); - + mocks.ReplayAll(); plugin.Gui = gui; @@ -469,7 +472,7 @@ Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); IPipingCalculationItem addedItem = failureMechanism.CalculationsGroup.Children.ElementAt(1); Assert.AreEqual("Nieuwe berekening (1)", addedItem.Name, - "Because there is already an item with the same default name, '(1)' should be appended."); + "Because there is already an item with the same default name, '(1)' should be appended."); Assert.IsInstanceOf(addedItem); mocks.VerifyAll(); @@ -514,7 +517,7 @@ Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); IPipingCalculationItem addedItem = failureMechanism.CalculationsGroup.Children.ElementAt(1); Assert.AreEqual("Nieuwe map (1)", addedItem.Name, - "Because there is already an item with the same default name, '(1)' should be appended."); + "Because there is already an item with the same default name, '(1)' should be appended."); Assert.IsInstanceOf(addedItem); mocks.VerifyAll(); Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/PipingSoilProfilesReader/invalidAtX2dProperty.soil =================================================================== diff -u -r41d06d91a2ef710ad07b3f474f190400751e09b8 -re4c1ee9fe5170ccf7794006d572461d3f88e7740 Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs =================================================================== diff -u -r10779bb6a6db2d00f4627b2bc190e7e35e1fee3e -re4c1ee9fe5170ccf7794006d572461d3f88e7740 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision 10779bb6a6db2d00f4627b2bc190e7e35e1fee3e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision e4c1ee9fe5170ccf7794006d572461d3f88e7740) @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using Core.Common.Base; @@ -8,9 +7,10 @@ using Core.Common.Utils.Builders; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Data; 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; @@ -41,7 +41,7 @@ var importer = new PipingSoilProfilesImporter(); // Assert - Assert.IsInstanceOf>>(importer); + Assert.IsInstanceOf>(importer); Assert.AreEqual(PipingFormsResources.PipingSoilProfilesCollection_DisplayName, importer.Name); Assert.AreEqual(RingtoetsFormsResources.Ringtoets_Category, importer.Category); Assert.AreEqual(16, importer.Image.Width); @@ -58,23 +58,26 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); - var observableList = new ObservableList(); - observableList.Attach(observer); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); var importResult = true; // Call - Action call = () => importResult = importer.Import(observableList, validFilePath); + Action call = () => importResult = importer.Import(context, validFilePath); // Assert TestHelper.AssertLogMessages(call, messages => @@ -84,7 +87,7 @@ StringAssert.EndsWith(message, messageArray[0]); }); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); Assert.AreEqual(1, progress); mocks.VerifyAll(); // 'observer' should not be notified @@ -99,23 +102,26 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); - var observableList = new ObservableList(); - observableList.Attach(observer); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); var importResult = true; // Call - Action call = () => importResult = importer.Import(observableList, invalidFilePath); + Action call = () => importResult = importer.Import(context, invalidFilePath); // Assert TestHelper.AssertLogMessages(call, messages => @@ -125,67 +131,155 @@ StringAssert.EndsWith(message, messageArray[0]); }); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); Assert.AreEqual(1, progress); mocks.VerifyAll(); // 'observer' should not be notified } [Test] + public void Import_NoReferenceLine_CancelImportWithErrorMessage() + { + // Setup + var file = "file"; + string invalidFilePath = Path.Combine(testDataPath, file); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var expectedMessage = "Er is geen referentielijn beschikbaar. Geen data ingelezen."; + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); + + var importer = new PipingSoilProfilesImporter + { + ProgressChanged = IncrementProgress + }; + + // Precondition + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(context, invalidFilePath); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsFalse(importResult); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); + Assert.AreEqual(0, progress); + + mocks.VerifyAll(); // 'observer' should not be notified + } + + [Test] public void Import_ImportingToValidTargetWithValidFile_ImportSoilProfilesToCollection() { // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); - var piping = new PipingFailureMechanism(); + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + var pipingFailureMechanism = new PipingFailureMechanism(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + mocks.ReplayAll(); var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; - var importTarget = piping.SoilProfiles; + var context = new StochasticSoilModelContext(pipingFailureMechanism, assessmentSection); + context.Attach(observer); // Call - var importResult = importer.Import(importTarget, validFilePath); + var importResult = importer.Import(context, validFilePath); // Assert Assert.IsTrue(importResult); - Assert.AreEqual(28, progress); + Assert.AreEqual(34, progress); + + mocks.VerifyAll(); } [Test] + public void Import_ImportingToValidTargetWithValidFileTwice_AddsSoilProfilesToCollectionLogWarning() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.soil"); + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + var pipingFailureMechanism = new PipingFailureMechanism(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + mocks.ReplayAll(); + + var importer = new PipingSoilProfilesImporter + { + ProgressChanged = IncrementProgress + }; + + var context = new StochasticSoilModelContext(pipingFailureMechanism, assessmentSection); + context.Attach(observer); + var importResult = false; + + // Precondition + importer.Import(context, validFilePath); + var names = context.FailureMechanism.StochasticSoilModels.Select(ssm => ssm.Name); + var expectedLogMessages = names.Select(name => string.Format("Het stochastisch ondergrondmodel '{0}' bestaat al in het faalmechanisme.", name)).ToList(); + expectedLogMessages.Add(String.Format("Het uitgelezen profiel '{0}' niet wordt niet gebruikt in een van de stochastische ondergrondmodellen.", "Segment_36005_1D2")); + expectedLogMessages.Add(String.Format("Het uitgelezen profiel '{0}' niet wordt niet gebruikt in een van de stochastische ondergrondmodellen.", "Segment_36005_1D3")); + + // Call + Action call = () => importResult = importer.Import(context, validFilePath); + TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, expectedLogMessages.Count); + + // Assert + Assert.IsTrue(importResult); + Assert.AreEqual(34*2, progress); + + mocks.VerifyAll(); + } + + [Test] public void Import_CancelOfImportToValidTargetWithValidFile_CancelImportAndLog() { // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); var mocks = new MockRepository(); var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); - var observableList = new ObservableList(); - observableList.Attach(observer); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); Assert.IsTrue(File.Exists(validFilePath)); importer.Cancel(); var importResult = true; // Call - Action call = () => importResult = importer.Import(observableList, validFilePath); + Action call = () => importResult = importer.Import(context, validFilePath); // Assert TestHelper.AssertLogMessageIsGenerated(call, ApplicationResources.PipingSoilProfilesImporter_Import_Import_cancelled, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels); Assert.AreEqual(1, progress); mocks.VerifyAll(); // 'observer' should not be notified @@ -200,31 +294,35 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); - var observableList = new ObservableList(); - observableList.Attach(observer); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(observableList); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); Assert.IsTrue(File.Exists(validFilePath)); // Setup (second part) importer.Cancel(); - var importResult = importer.Import(observableList, validFilePath); + var importResult = importer.Import(context, validFilePath); Assert.IsFalse(importResult); // Call - importResult = importer.Import(observableList, validFilePath); + importResult = importer.Import(context, validFilePath); // Assert Assert.IsTrue(importResult); - Assert.AreEqual(29, progress); + Assert.AreEqual(35, progress); } [Test] @@ -235,28 +333,31 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); + var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; - var observableSoilProfileList = new ObservableList(); - observableSoilProfileList.Attach(observer); - var importResult = true; // Call - Action call = () => importResult = importer.Import(observableSoilProfileList, corruptPath); + Action call = () => importResult = importer.Import(context, corruptPath); // Assert var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath).Build(RingtoetsIOResources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); var expectedLogMessage = string.Format(ApplicationResources.PipingSoilProfilesImporter_CriticalErrorMessage_0_File_Skipped, internalErrorMessage); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(observableSoilProfileList, + CollectionAssert.IsEmpty(context.FailureMechanism.StochasticSoilModels, "No items should be added to collection when import is aborted."); Assert.AreEqual(1, progress); @@ -271,33 +372,41 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); + var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; - var observableSoilProfileList = new ObservableList(); - observableSoilProfileList.Attach(observer); - var importResult = false; - // Call - Action call = () => importResult = importer.Import(observableSoilProfileList, corruptPath); - - // Assert var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) .WithSubject("ondergrondschematisering 'Profile'") .Build(string.Format(RingtoetsIOResources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, "IntersectionX")); - var expectedLogMessage = string.Format(ApplicationResources.PipingSoilProfilesImporter_ReadSoilProfiles_ParseErrorMessage_0_SoilProfile_skipped, - internalErrorMessage); - TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); + var expectedLogMessages = new[] + { + 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") + }; + // Call + Action call = () => importResult = importer.Import(context, corruptPath); + + // Assert + TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); + Assert.IsTrue(importResult); - Assert.AreEqual(1, observableSoilProfileList.Count); - Assert.AreEqual(4, progress); + Assert.AreEqual(0, context.FailureMechanism.StochasticSoilModels.Count); + Assert.AreEqual(6, progress); mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } @@ -310,21 +419,24 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); + var context = new StochasticSoilModelContext(failureMechanism, assessmentSection); + context.Attach(observer); + var importer = new PipingSoilProfilesImporter { ProgressChanged = IncrementProgress }; - var observableSoilProfileList = new ObservableList(); - observableSoilProfileList.Attach(observer); - // Call - var importResult = importer.Import(observableSoilProfileList, corruptPath); + var importResult = importer.Import(context, corruptPath); Assert.IsTrue(importResult); - Assert.AreEqual(0, observableSoilProfileList.Count); + Assert.AreEqual(0, context.FailureMechanism.StochasticSoilModels.Count); mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver }