Index: Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -33,7 +33,7 @@ /// Object type that is the target for this importer. public abstract class FileImporterBase : IFileImporter { - private readonly ILog log = LogManager.GetLogger(typeof(FileImporterBase)); + protected readonly ILog Log = LogManager.GetLogger(typeof(FileImporterBase)); /// /// Initializes a new instance of the class. @@ -110,7 +110,7 @@ /// /// Gets the path to the file to import from. /// - protected string FilePath { get; private set; } + protected string FilePath { get; } /// /// Gets the value indicating if a cancel request has been made. When true, no @@ -146,7 +146,7 @@ private void LogImportUncancelableMessage() { - log.Warn(Resources.FileImporterBase_LogUncancelableMessage_Import_cannot_be_canceled_and_continued); + Log.Warn(Resources.FileImporterBase_LogUncancelableMessage_Import_cannot_be_canceled_and_continued); } } } \ No newline at end of file Index: Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs (.../FeatureBasedMapDataImporter.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs (.../FeatureBasedMapDataImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -30,8 +30,6 @@ using Core.Components.Gis.IO.Readers; using DotSpatial.Data; using DotSpatial.Topology; -using log4net; -using ILog = log4net.ILog; namespace Core.Components.Gis.IO.Importers { @@ -41,8 +39,6 @@ /// public class FeatureBasedMapDataImporter : FileImporterBase { - private static readonly ILog log = LogManager.GetLogger(typeof(FeatureBasedMapDataImporter)); - /// /// Creates a new instance of . /// @@ -68,7 +64,7 @@ protected override void LogImportCanceledMessage() { - log.Info(Resources.FeatureBasedMapDataImporter_HandleUserCancelingImport_Import_canceled_no_data_read); + Log.Info(Resources.FeatureBasedMapDataImporter_HandleUserCancelingImport_Import_canceled_no_data_read); } private void AddFeatureBasedMapDataToMapDataCollection(FeatureBasedMapData importedMapData) @@ -146,7 +142,7 @@ { string errorMessage = string.Format(Resources.FeatureBasedMapDataImporter_HandleCriticalFileReadError_Error_0_no_maplayer_imported, new FileReaderErrorMessageBuilder(FilePath).Build(message)); - log.Error(errorMessage); + Log.Error(errorMessage); return new ReadResult(true); } } Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Import/CalculationConfigurationImporter.cs =================================================================== diff -u -r6b18e2c0134c97e01ba13c518fb7a8efa7f42253 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Import/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision 6b18e2c0134c97e01ba13c518fb7a8efa7f42253) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Import/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -25,7 +25,6 @@ using Core.Common.Base.Data; using Core.Common.Base.IO; using Core.Common.IO.Readers; -using log4net; using Ringtoets.Common.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; @@ -45,8 +44,6 @@ where TCalculationConfigurationReader : CalculationConfigurationReader where TReadCalculation : class, IConfigurationItem { - protected readonly ILog Log = LogManager.GetLogger(typeof(CalculationConfigurationImporter)); - /// /// Creates a new instance of . /// Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs (.../FailureMechanismSectionsImporter.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs (.../FailureMechanismSectionsImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -25,7 +25,6 @@ using Core.Common.Base.Geometry; using Core.Common.Base.IO; using Core.Common.IO.Readers; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.IO.Properties; @@ -48,8 +47,6 @@ /// private const double lengthDifferenceTolerance = 1; - private static readonly ILog log = LogManager.GetLogger(typeof(FailureMechanismSectionsImporter)); - private readonly ReferenceLine referenceLine; /// @@ -104,7 +101,7 @@ protected override void LogImportCanceledMessage() { - log.Info(Resources.FailureMechanismSectionsImporter_Import_canceled_no_data_read); + Log.Info(Resources.FailureMechanismSectionsImporter_Import_canceled_no_data_read); } private ReadResult ReadFailureMechanismSections() @@ -175,7 +172,7 @@ { string errorMessage = string.Format(Resources.FailureMechanismSectionsImporter_CriticalErrorMessage_0_No_sections_imported, message); - log.Error(errorMessage); + Log.Error(errorMessage); } private static bool HasStartOrEndPointsTooFarFromReferenceLine(ReferenceLine referenceLine, ICollection mechanismSections) Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs =================================================================== diff -u -r34bec423be51e69135874f811713b5e41de8b379 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision 34bec423be51e69135874f811713b5e41de8b379) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -28,7 +28,6 @@ using Core.Common.Base.IO; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.IO.DikeProfiles; @@ -45,7 +44,6 @@ /// public abstract class ProfilesImporter : FileImporterBase { - protected readonly ILog Log = LogManager.GetLogger(typeof(ProfilesImporter)); protected readonly IImporterMessageProvider MessageProvider; private readonly ReferenceLine referenceLine; Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs =================================================================== diff -u -r81eeb27299fa8e87731b4a362a3671c8f3cfac02 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 81eeb27299fa8e87731b4a362a3671c8f3cfac02) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -30,7 +30,6 @@ using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; using Core.Common.Utils.Builders; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.Properties; @@ -45,7 +44,6 @@ /// Object type that is the target for this importer. public abstract class StructuresImporter : FileImporterBase { - private readonly ILog log = LogManager.GetLogger(typeof(StructuresImporter)); private readonly ReferenceLine referenceLine; /// @@ -88,15 +86,15 @@ } catch (CriticalFileValidationException e) { - log.Error(e.Message); + Log.Error(e.Message); return false; } return true; } protected override void LogImportCanceledMessage() { - log.Info(Resources.StructuresImporter_User_canceled); + Log.Info(Resources.StructuresImporter_User_canceled); } /// @@ -111,7 +109,7 @@ { if (structuresParameterRow.VarianceType == VarianceType.CoefficientOfVariation) { - log.WarnFormat(Resources.StructuresImporter_GetStandardDeviation_Converting_variation_StructureName_0_StructureId_1_ParameterId_2_on_Line_3_, + Log.WarnFormat(Resources.StructuresImporter_GetStandardDeviation_Converting_variation_StructureName_0_StructureId_1_ParameterId_2_on_Line_3_, structureName, structuresParameterRow.LocationId, structuresParameterRow.ParameterId, structuresParameterRow.LineNumber); return (RoundedDouble) structuresParameterRow.VarianceValue * Math.Abs(structuresParameterRow.NumericalValue); } @@ -122,7 +120,7 @@ { if (structuresParameterRow.VarianceType == VarianceType.StandardDeviation) { - log.WarnFormat(Resources.StructuresImporter_GetCoefficientOfVariation_Converting_variation_StructureName_0_StructureId_1_ParameterId_2_on_Line_3_, + Log.WarnFormat(Resources.StructuresImporter_GetCoefficientOfVariation_Converting_variation_StructureName_0_StructureId_1_ParameterId_2_on_Line_3_, structureName, structuresParameterRow.LocationId, structuresParameterRow.ParameterId, structuresParameterRow.LineNumber); return (RoundedDouble) (structuresParameterRow.VarianceValue / Math.Abs(structuresParameterRow.NumericalValue)); } @@ -152,7 +150,7 @@ } else { - log.Info(string.Format(Resources.StructuresImporter_TrySetConstructionProperty_Parameter_0_of_StructureName_1_StructureId_2_missing_or_invalid_default_values_used, + Log.Info(string.Format(Resources.StructuresImporter_TrySetConstructionProperty_Parameter_0_of_StructureName_1_StructureId_2_missing_or_invalid_default_values_used, key, structureName, structureId)); } } @@ -188,7 +186,7 @@ } catch (CriticalFileReadException exception) { - log.Error(exception.Message); + Log.Error(exception.Message); return new ReadResult(true); } @@ -210,7 +208,7 @@ } catch (Exception exception) when (exception is CriticalFileReadException || exception is LineParseException) { - log.Error(exception.Message); + Log.Error(exception.Message); return new ReadResult(true); } } @@ -234,11 +232,11 @@ } catch (CriticalFileReadException exception) { - log.Error(exception.Message); + Log.Error(exception.Message); } catch (ArgumentException exception) { - log.Error(exception.Message); + Log.Error(exception.Message); } return new ReadResult(true); } @@ -266,12 +264,12 @@ Resources.StructuresImporter_GetStructureLocationReadResult_Error_reading_Structure_LineNumber_0_Error_1_, i + 1, exception.Message); - log.Error(message, exception); + Log.Error(message, exception); return new ReadResult(true); } catch (CriticalFileReadException exception) { - log.Error(exception.Message); + Log.Error(exception.Message); return new ReadResult(true); } } Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -25,7 +25,6 @@ using Core.Common.Base; using Core.Common.Base.IO; using Core.Common.IO.Readers; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; @@ -37,8 +36,6 @@ /// public class ReferenceLineImporter : FileImporterBase { - private static readonly ILog log = LogManager.GetLogger(typeof(ReferenceLineImporter)); - private readonly List changedObservables = new List(); private readonly IReferenceLineReplaceHandler replacementHandler; @@ -83,7 +80,7 @@ protected override void LogImportCanceledMessage() { - log.Info(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Import_canceled_no_data_read); + Log.Info(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Import_canceled_no_data_read); } protected override void DoPostImportUpdates() @@ -138,11 +135,11 @@ } } - private static ReadResult HandleCriticalFileReadError(Exception e) + private ReadResult HandleCriticalFileReadError(Exception e) { string errorMessage = string.Format(RingtoetsCommonIOResources.ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_imported, e.Message); - log.Error(errorMessage); + Log.Error(errorMessage); return new ReadResult(true); } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs =================================================================== diff -u -r81eeb27299fa8e87731b4a362a3671c8f3cfac02 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 81eeb27299fa8e87731b4a362a3671c8f3cfac02) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -26,8 +26,10 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.Structures; using Ringtoets.HeightStructures.Data; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.HeightStructures.IO { @@ -37,27 +39,34 @@ /// public class HeightStructuresImporter : StructuresImporter> { + private readonly IImporterMessageProvider messageProvider; private readonly IStructureUpdateStrategy structureUpdateStrategy; /// /// Creates a new instance of . /// /// The height structures to import on. /// The reference line used to check if the - /// objects found in the file are intersecting it. - /// The strategy to update the structures with imported data. + /// objects found in the file are intersecting it. /// The path to the file to import from. + /// The message provider to provide messages during importer actions. + /// The strategy to update the structures with imported data. /// Thrown when any of the input parameters is null. public HeightStructuresImporter(StructureCollection importTarget, ReferenceLine referenceLine, - IStructureUpdateStrategy structureUpdateStrategy, - string filePath) + string filePath, IImporterMessageProvider messageProvider, + IStructureUpdateStrategy structureUpdateStrategy) : base(importTarget, referenceLine, filePath) { + if (messageProvider == null) + { + throw new ArgumentNullException(nameof(messageProvider)); + } if (structureUpdateStrategy == null) { throw new ArgumentNullException(nameof(structureUpdateStrategy)); } + this.messageProvider = messageProvider; this.structureUpdateStrategy = structureUpdateStrategy; } @@ -70,6 +79,12 @@ FilePath); } + protected override void LogImportCanceledMessage() + { + string message = messageProvider.GetCancelledLogMessageText(RingtoetsCommonDataResources.StructureCollection_TypeDescriptor); + Log.Info(message); + } + private IEnumerable CreateHeightStructures(IEnumerable structureLocations, IDictionary> groupedStructureParameterRows) { Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r250f2f821d2540a5c562d5fa9ccaab669dacb24b -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -25,6 +25,7 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; @@ -43,6 +44,7 @@ using Ringtoets.Common.Forms.ImportInfos; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.Service; using Ringtoets.Common.Utils; using Ringtoets.HeightStructures.Data; @@ -89,16 +91,14 @@ { yield return new ImportInfo { - CreateFileImporter = (context, filePath) => new HeightStructuresImporter(context.WrappedData, - context.AssessmentSection.ReferenceLine, - new HeightStructureReplaceDataStrategy(context.FailureMechanism), - filePath), Name = RingtoetsCommonFormsResources.StructuresImporter_DisplayName, Category = RingtoetsCommonFormsResources.Ringtoets_Category, Image = RingtoetsCommonFormsResources.StructuresIcon, - FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, - RingtoetsCommonIOResources.Shape_file_filter_Description), - IsEnabled = context => context.AssessmentSection.ReferenceLine != null + IsEnabled = IsHeightStructuresImporterEnabled, + FileFilterGenerator = HeightStructureFileFilter(), + CreateFileImporter = (context, filePath) => CreateHeightStructuresImporter(context, + filePath, + new ImportMessageProvider()) }; yield return RingtoetsImportInfoFactory.CreateCalculationConfigurationImportInfo( @@ -111,6 +111,22 @@ context.FailureMechanism)); } + public override IEnumerable GetUpdateInfos() + { + yield return new UpdateInfo + { + Name = RingtoetsCommonDataResources.StructureCollection_TypeDescriptor, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsCommonFormsResources.StructuresIcon, + IsEnabled = IsHeightStructuresImporterEnabled, + FileFilterGenerator = HeightStructureFileFilter(), + CreateFileImporter = (context, filePath) => CreateHeightStructuresImporter(context, + filePath, + new UpdateMessageProvider()), + CurrentPath = context => context.WrappedData.SourcePath + }; + } + public override IEnumerable GetExportInfos() { yield return RingtoetsExportInfoFactory.CreateCalculationGroupConfigurationExportInfo( @@ -194,16 +210,7 @@ ? Color.FromKnownColor(KnownColor.ControlText) : Color.FromKnownColor(KnownColor.GrayText), ChildNodeObjects = context => context.WrappedData.Cast().ToArray(), - ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) - .AddImportItem() - .AddSeparator() - .AddDeleteChildrenItem() - .AddSeparator() - .AddCollapseAllItem() - .AddExpandAllItem() - .AddSeparator() - .AddPropertiesItem() - .Build() + ContextMenuStrip = HeightStructuresContextContextMenuStrip }; yield return new TreeNodeInfo @@ -359,6 +366,24 @@ #endregion + #region HeightStructuresContext TreeNodeInfo + + private ContextMenuStrip HeightStructuresContextContextMenuStrip(HeightStructuresContext nodeData, + object parentData, TreeViewControl treeViewControl) + { + return Gui.Get(nodeData, treeViewControl) + .AddImportItem() + .AddUpdateItem() + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + + #endregion + #region HeightStructuresFailureMechanismContext TreeNodeInfo private static object[] FailureMechanismEnabledChildNodeObjects(HeightStructuresFailureMechanismContext context) @@ -736,5 +761,30 @@ #endregion #endregion + + #region Importers + + #region HeightStructuresImporter + + private static IFileImporter CreateHeightStructuresImporter(HeightStructuresContext context, string filePath, IImporterMessageProvider messageProvider) + { + return new HeightStructuresImporter(context.WrappedData, context.AssessmentSection.ReferenceLine, + filePath, messageProvider, new HeightStructureUpdateDataStrategy(context.FailureMechanism)); + } + + private static bool IsHeightStructuresImporterEnabled(HeightStructuresContext context) + { + return context.AssessmentSection.ReferenceLine != null; + } + + private static FileFilterGenerator HeightStructureFileFilter() + { + return new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, + RingtoetsCommonIOResources.Shape_file_filter_Description); + } + + #endregion + + #endregion } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresImporterTest.cs =================================================================== diff -u -r81eeb27299fa8e87731b4a362a3671c8f3cfac02 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresImporterTest.cs (.../HeightStructuresImporterTest.cs) (revision 81eeb27299fa8e87731b4a362a3671c8f3cfac02) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresImporterTest.cs (.../HeightStructuresImporterTest.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -23,13 +23,17 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.FileImporters.MessageProviders; +using Ringtoets.Common.IO.Structures; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Plugin.FileImporters; @@ -38,31 +42,72 @@ [TestFixture] public class HeightStructuresImporterTest { + private readonly string commonIoTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "Structures"); + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.IO); private readonly StructureCollection testImportTarget = new StructureCollection(); private readonly ReferenceLine testReferenceLine = new ReferenceLine(); private readonly string testFilePath = string.Empty; + private MockRepository mocks; + + [SetUp] + public void Setup() + { + mocks = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + [Test] public void Constructor_StructureUpdateStrategyNull_ThrowsArgumentNullException() { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call TestDelegate call = () => new HeightStructuresImporter(testImportTarget, testReferenceLine, - null, testFilePath); + testFilePath, messageProvider, + null); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("structureUpdateStrategy", paramName); + mocks.VerifyAll(); } [Test] + public void Constructor_ImporterMessageProviderNull_ThrowsArgumentNullException() + { + // Setup + mocks.ReplayAll(); + var replaceDataStrategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism()); + + // Call + TestDelegate call = () => new HeightStructuresImporter(testImportTarget, testReferenceLine, + testFilePath, null, replaceDataStrategy); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("messageProvider", paramName); + } + + [Test] public void Constructor_Always_ExpectedValues() { // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + var replaceDataStrategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism()); // Call - var importer = new HeightStructuresImporter(testImportTarget, testReferenceLine, - replaceDataStrategy, testFilePath); + var importer = new HeightStructuresImporter(testImportTarget, testReferenceLine, testFilePath, + messageProvider, replaceDataStrategy); // Assert Assert.IsInstanceOf>>(importer); @@ -72,16 +117,18 @@ public void Import_ValidIncompleteFile_LogAndFalse() { // Setup - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, - Path.Combine("Structures", "CorrectFiles", - "Kunstwerken.shp")); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp"); + ReferenceLine referenceLine = CreateReferenceLine(); var failureMechanism = new HeightStructuresFailureMechanism(); var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism); var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures, - referenceLine, replaceDataStrategy, filePath); + referenceLine, filePath, messageProvider, + replaceDataStrategy); // Call var importResult = false; @@ -103,17 +150,19 @@ public void Import_ValidFileWithConversionsBetweenVarianceTypes_WarnUserAboutConversion() { // Setup - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.IO, - Path.Combine("HeightStructuresVarianceConvert", - "StructureNeedVarianceValueConversion.shp")); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = Path.Combine(testDataPath, "HeightStructuresVarianceConvert", "StructureNeedVarianceValueConversion.shp"); + ReferenceLine referenceLine = CreateReferenceLine(); var failureMechanism = new HeightStructuresFailureMechanism(); var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism); var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures, - referenceLine, replaceDataStrategy, filePath); + referenceLine, filePath, messageProvider, + replaceDataStrategy); // Call var importResult = false; @@ -147,15 +196,17 @@ public void Import_InvalidCsvFile_LogAndFalse() { // Setup - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, - Path.Combine("Structures", "CorrectShpIncompleteCsv", - "Kunstwerken.shp")); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpIncompleteCsv", "Kunstwerken.shp"); + ReferenceLine referenceLine = CreateReferenceLine(); var failureMechanism = new HeightStructuresFailureMechanism(); var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism); var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures, - referenceLine, replaceDataStrategy, filePath); + referenceLine, filePath, messageProvider, + replaceDataStrategy); // Call var importResult = false; @@ -180,16 +231,18 @@ public void Import_MissingParameters_LogWarningAndContinueImportWithDefaultValues() { // Setup - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.IO, - Path.Combine(nameof(HeightStructuresImporter), - "Kunstwerken.shp")); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = Path.Combine(testDataPath, nameof(HeightStructuresImporter), "Kunstwerken.shp"); + ReferenceLine referenceLine = CreateReferenceLine(); var failureMechanism = new HeightStructuresFailureMechanism(); var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism); var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures, - referenceLine, replaceDataStrategy, filePath); + referenceLine, filePath, messageProvider, + replaceDataStrategy); // Call var importResult = false; @@ -227,10 +280,12 @@ public void Import_ParameterIdsWithVaryingCase_TrueAndImportTargetUpdated() { // Setup - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, - Path.Combine("Structures", "CorrectShpRandomCaseHeaderCsv", - "Kunstwerken.shp")); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpRandomCaseHeaderCsv", + "Kunstwerken.shp"); + var referencePoints = new List { new Point2D(154493.618, 568995.991), @@ -244,7 +299,8 @@ var failureMechanism = new HeightStructuresFailureMechanism(); var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism); var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures, - referenceLine, replaceDataStrategy, filePath); + referenceLine, filePath, messageProvider, + replaceDataStrategy); // Call bool importResult = structuresImporter.Import(); @@ -255,6 +311,134 @@ Assert.AreEqual(filePath, failureMechanism.HeightStructures.SourcePath); } + [Test] + public void Import_CancelOfImportWhenReadingShapeFile_CancelsImportAndLogs() + { + // Setup + const string cancelledLogMessage = "Operation Cancelled"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Kunstwerken")).Return(cancelledLogMessage); + + var strategy = mocks.StrictMock>(); + mocks.ReplayAll(); + + string validFilePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp"); + + var referenceLine = new ReferenceLine(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + var importer = new HeightStructuresImporter(failureMechanism.HeightStructures, referenceLine, validFilePath, messageProvider, strategy); + importer.SetProgressChanged(delegate(string description, int step, int steps) + { + if (description.Contains("Inlezen van kunstwerklocaties uit een shapebestand.")) + { + importer.Cancel(); + } + }); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(); + + // Assert + Tuple expectedLogMessage = Tuple.Create(cancelledLogMessage, LogLevelConstant.Info); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage); + Assert.IsFalse(importResult); + } + + [Test] + public void Import_CancelOfImportWhenReadingStructureData_CancelsImportAndLogs() + { + // Setup + const string cancelledLogMessage = "Operation Cancelled"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Kunstwerken")).Return(cancelledLogMessage); + + var strategy = mocks.StrictMock>(); + mocks.ReplayAll(); + + string validFilePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp"); + + ReferenceLine referenceLine = CreateReferenceLine(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + var importer = new HeightStructuresImporter(failureMechanism.HeightStructures, referenceLine, validFilePath, messageProvider, strategy); + importer.SetProgressChanged(delegate(string description, int step, int steps) + { + if (description.Contains("Inlezen van kunstwerkgegevens uit een kommagescheiden bestand.")) + { + importer.Cancel(); + } + }); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(); + + // Assert + Tuple expectedLogMessage = Tuple.Create(cancelledLogMessage, LogLevelConstant.Info); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage); + Assert.IsFalse(importResult); + } + + [Test] + public void Import_CancelOfImportWhenAddingDataToModel_ImportCompletedSuccessfullyNonetheless() + { + // Setup + var messageProvider = mocks.StrictMock(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + + ReferenceLine referenceLine = CreateReferenceLine(); + + string validFilePath = Path.Combine(testDataPath, "HeightStructuresImporter", "Kunstwerken.shp"); + + var strategy = new TestStructureUpdateStrategy(); + + var importer = new HeightStructuresImporter(failureMechanism.HeightStructures, referenceLine, + validFilePath, messageProvider, strategy); + importer.SetProgressChanged((description, step, steps) => + { + if (description.Contains("Geïmporteerde data toevoegen aan het toetsspoor.")) + { + importer.Cancel(); + } + }); + + var importResult = false; + + // Call + Action call = () => importResult = importer.Import(); + + // Assert + Tuple expectedLogMessage = Tuple.Create( + "Huidige actie was niet meer te annuleren en is daarom voortgezet.", LogLevelConstant.Warn); + TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage); + Assert.IsTrue(importResult); + Assert.IsTrue(strategy.Updated); + } + + private class TestStructureUpdateStrategy : IStructureUpdateStrategy + { + public bool Updated { get; private set; } + public string FilePath { get; private set; } + public HeightStructure[] ReadHeightStructures { get; private set; } + public IEnumerable UpdatedInstances { get; } = Enumerable.Empty(); + + public IEnumerable UpdateStructuresWithImportedData( + StructureCollection targetDataCollection, + IEnumerable readStructures, string sourceFilePath) + { + Updated = true; + FilePath = sourceFilePath; + ReadHeightStructures = readStructures.ToArray(); + return UpdatedInstances; + } + } + private static ReferenceLine CreateReferenceLine() { var referencePoints = new List @@ -271,7 +455,8 @@ return referenceLine; } - private static string CreateExpectedErrorMessage(string filePath, string structureName, string structureId, + private static string CreateExpectedErrorMessage(string filePath, string structureName, + string structureId, IEnumerable messages) { return string.Format("Fout bij het lezen van bestand '{0}' (Kunstwerk '{1}' ({2})): klik op details voor meer informatie." + Environment.NewLine Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj =================================================================== diff -u -r250f2f821d2540a5c562d5fa9ccaab669dacb24b -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj (.../Ringtoets.HeightStructures.IO.Test.csproj) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj (.../Ringtoets.HeightStructures.IO.Test.csproj) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -42,6 +42,10 @@ ..\..\..\..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll True + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + True + Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/packages.config =================================================================== diff -u -r4bf59bb3506b840b284efe0c0f4431b7876e0e5b -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/packages.config (.../packages.config) (revision 4bf59bb3506b840b284efe0c0f4431b7876e0e5b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/packages.config (.../packages.config) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -1,4 +1,5 @@ - + \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs =================================================================== diff -u -r250f2f821d2540a5c562d5fa9ccaab669dacb24b -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs (.../HeightStructuresScenariosViewIntegrationTest.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs (.../HeightStructuresScenariosViewIntegrationTest.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -26,11 +26,13 @@ using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.Views; using Ringtoets.HeightStructures.IO; @@ -90,6 +92,10 @@ public void ScenariosView_GenerateCalculations_ChangesCorrectlyObservedAndSynced() { // Setup + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + using (var form = new Form()) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -98,8 +104,7 @@ DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, assessmentSection.ReferenceLine, - new HeightStructureReplaceDataStrategy(failureMechanism), - filePath) + filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)) .Import(); CalculationGroup calculationsGroup = assessmentSection.HeightStructures.CalculationsGroup; @@ -133,12 +138,17 @@ Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); Assert.AreEqual("Eerste kunstwerk 6-3", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); } + mocks.VerifyAll(); } [Test] public void ScenariosView_RenameCalculations_ChangesCorrectlyObservedAndSynced() { // Setup + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + using (var form = new Form()) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -147,8 +157,7 @@ DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, assessmentSection.ReferenceLine, - new HeightStructureReplaceDataStrategy(failureMechanism), - filePath) + filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)) .Import(); CalculationGroup calculationsGroup = assessmentSection.HeightStructures.CalculationsGroup; @@ -188,12 +197,18 @@ Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCell).Items[0].ToString()); Assert.AreEqual("Eerste kunstwerk 6-3_changed", ((DataGridViewComboBoxCell) dataGridViewCell).Items[1].ToString()); } + + mocks.VerifyAll(); } [Test] public void ScenariosView_ChangeStructureOfCalculation_ChangesCorrectlyObservedAndSynced() { // Setup + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + using (var form = new Form()) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -202,8 +217,7 @@ DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures, assessmentSection.ReferenceLine, - new HeightStructureReplaceDataStrategy(failureMechanism), - filePath) + filePath, messageProvider, new HeightStructureReplaceDataStrategy(failureMechanism)) .Import(); var view = new HeightStructuresScenariosView @@ -245,6 +259,8 @@ Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridViewCellWithRemovedCalculation).Items.Count); Assert.AreEqual("", ((DataGridViewComboBoxCell) dataGridViewCellWithRemovedCalculation).Items[0].ToString()); } + + mocks.VerifyAll(); } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj =================================================================== diff -u -rf21dfc68719af2540c7c07392fdd3d045907098d -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision f21dfc68719af2540c7c07392fdd3d045907098d) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -75,6 +75,7 @@ + Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresContextTreeNodeInfoTest.cs =================================================================== diff -u -rc10213be206d81cd8618603d9e526f18f070211b -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresContextTreeNodeInfoTest.cs (.../HeightStructuresContextTreeNodeInfoTest.cs) (revision c10213be206d81cd8618603d9e526f18f070211b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresContextTreeNodeInfoTest.cs (.../HeightStructuresContextTreeNodeInfoTest.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -209,9 +209,8 @@ using (mocks.Ordered()) { menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddUpdateItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddDeleteChildrenItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/UpdateInfos/HeightStructuresContextUpdateInfoTest.cs (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -0,0 +1,187 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Linq; +using Core.Common.Base.IO; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.IO; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.HeightStructures.Plugin.Test.UpdateInfos +{ + [TestFixture] + public class HeightStructuresContextUpdateInfoTest + { + private UpdateInfo updateInfo; + private HeightStructuresPlugin plugin; + + [SetUp] + public void SetUp() + { + plugin = new HeightStructuresPlugin(); + updateInfo = plugin.GetUpdateInfos().First(i => i.DataType == typeof(HeightStructuresContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Name_Always_ReturnExpectedName() + { + // Call + string name = updateInfo.Name; + + // Assert + Assert.AreEqual("Kunstwerken", name); + } + + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Call + string category = updateInfo.Category; + + // Assert + Assert.AreEqual("Algemeen", category); + } + + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Call + Image image = updateInfo.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); + } + + [Test] + public void IsEnabled_ReferenceLineNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var structures = new StructureCollection(); + + var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + bool isEnabled = updateInfo.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_ReferenceLineSet_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + assessmentSection.ReferenceLine = new ReferenceLine(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var structures = new StructureCollection(); + + var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + bool isEnabled = updateInfo.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnExpectedFileFilter() + { + // Call + string fileFilter = updateInfo.FileFilterGenerator.Filter; + + // Assert + Assert.AreEqual(@"Shapebestand (*.shp)|*.shp", fileFilter); + } + + [Test] + public void CurrentPath_StructureCollectionHasPathSet_ReturnsExpectedPath() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + const string expectedFilePath = "some/path"; + var structures = new StructureCollection(); + structures.AddRange(Enumerable.Empty(), expectedFilePath); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + string currentPath = updateInfo.CurrentPath(context); + + // Assert + Assert.AreEqual(expectedFilePath, currentPath); + mocks.VerifyAll(); + } + + [Test] + public void CreateFileImporter_ValidInput_ReturnFileImporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + assessmentSection.ReferenceLine = new ReferenceLine(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var structures = new StructureCollection(); + + var importTarget = new HeightStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + IFileImporter importer = updateInfo.CreateFileImporter(importTarget, ""); + + // Assert + Assert.IsInstanceOf(importer); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs =================================================================== diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs (.../StochasticSoilModelImporter.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs (.../StochasticSoilModelImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -26,7 +26,6 @@ using Core.Common.Base; using Core.Common.Base.IO; using Core.Common.IO.Readers; -using log4net; using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Exceptions; @@ -43,7 +42,6 @@ /// public class StochasticSoilModelImporter : FileImporterBase { - private readonly ILog log = LogManager.GetLogger(typeof(StochasticSoilModelImporter)); private readonly IImporterMessageProvider messageProvider; private readonly IStochasticSoilModelUpdateModelStrategy modelUpdateStrategy; private IEnumerable updatedInstances; @@ -119,7 +117,7 @@ protected override void LogImportCanceledMessage() { string message = messageProvider.GetCancelledLogMessageText(RingtoetsPipingDataResources.StochasticSoilModelCollection_TypeDescriptor); - log.Info(message); + Log.Info(message); } /// @@ -133,19 +131,19 @@ { if (!stochasticSoilModel.StochasticSoilProfiles.Any()) { - log.WarnFormat(Resources.StochasticSoilModelImporter_ValidateStochasticSoilModel_No_profiles_found_in_stochastic_soil_model_0, + Log.WarnFormat(Resources.StochasticSoilModelImporter_ValidateStochasticSoilModel_No_profiles_found_in_stochastic_soil_model_0, stochasticSoilModel.Name); return false; } if (stochasticSoilModel.StochasticSoilProfiles.Any(ssp => ssp.SoilProfile == null)) { - log.WarnFormat(Resources.StochasticSoilModelImporter_ValidateStochasticSoilModel_SoilModel_0_with_stochastic_soil_profile_without_profile, + Log.WarnFormat(Resources.StochasticSoilModelImporter_ValidateStochasticSoilModel_SoilModel_0_with_stochastic_soil_profile_without_profile, stochasticSoilModel.Name); return false; } if (!IsSumOfAllProbabilitiesEqualToOne(stochasticSoilModel)) { - log.WarnFormat(Resources.StochasticSoilModelImporter_ValidateStochasticSoilModel_Sum_of_probabilities_of_stochastic_soil_model_0_is_not_correct, + Log.WarnFormat(Resources.StochasticSoilModelImporter_ValidateStochasticSoilModel_Sum_of_probabilities_of_stochastic_soil_model_0_is_not_correct, stochasticSoilModel.Name); } return true; @@ -206,7 +204,7 @@ if (currentProfile.SoilProfileId == previousProfile.SoilProfileId && currentProfile.SoilProfileType == previousProfile.SoilProfileType) { - log.Warn(string.Format(Resources.StochasticSoilModelImporter_MergeStochasticSoilProfiles_Multiple_SoilProfile_0_used_in_StochasticSoilModel_1_Probabilities_added, + Log.Warn(string.Format(Resources.StochasticSoilModelImporter_MergeStochasticSoilProfiles_Multiple_SoilProfile_0_used_in_StochasticSoilModel_1_Probabilities_added, previousProfile.SoilProfile.Name, stochasticSoilModel.Name)); @@ -222,7 +220,7 @@ NotifyProgress(Resources.StochasticSoilModelImporter_CheckIfAllProfilesAreUsed_Start_checking_soil_profiles, 1, 1); foreach (PipingSoilProfile soilProfile in soilProfiles.Where(soilProfile => !PipingSoilProfileIsUsed(soilProfile, stochasticSoilModels))) { - log.WarnFormat(Resources.StochasticSoilModelImporter_CheckIfAllProfilesAreUsed_SoilProfile_0_is_not_used_in_any_stochastic_soil_model, soilProfile.Name); + Log.WarnFormat(Resources.StochasticSoilModelImporter_CheckIfAllProfilesAreUsed_SoilProfile_0_is_not_used_in_any_stochastic_soil_model, soilProfile.Name); } } @@ -238,7 +236,7 @@ { string message = string.Format(Resources.StochasticSoilModelImporter_CriticalErrorMessage_0_File_Skipped, e.Message); - log.Error(message); + Log.Error(message); } #region read stochastic soil models @@ -280,7 +278,7 @@ catch (StochasticSoilProfileReadException e) { string message = string.Format(Resources.StochasticSoilModelImporter_GetStochasticSoilModelReadResult_Error_0_stochastic_soil_model_skipped, e.Message); - log.Error(message); + Log.Error(message); } } return new ReadResult(false) @@ -331,13 +329,13 @@ { string message = string.Format(Resources.StochasticSoilModelImporter_ReadSoilProfiles_ParseErrorMessage_0_SoilProfile_skipped, e.Message); - log.Error(message); + Log.Error(message); } catch (CriticalFileReadException e) { string message = string.Format(Resources.StochasticSoilModelImporter_CriticalErrorMessage_0_File_Skipped, FilePath, e.Message); - log.Error(message); + Log.Error(message); return new ReadResult(true); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -r8e74b5d6680386fce48486c8253b62331f7d7055 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 8e74b5d6680386fce48486c8253b62331f7d7055) @@ -28,7 +28,6 @@ using Core.Common.Base.IO; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Piping.Data; @@ -59,7 +58,6 @@ private const string csvFileExtension = ".csv"; private readonly IImporterMessageProvider messageProvider; private readonly ISurfaceLineUpdateDataStrategy surfaceLineUpdateStrategy; - private readonly ILog log = LogManager.GetLogger(typeof(PipingSurfaceLinesCsvImporter)); private readonly ReferenceLine referenceLine; private IEnumerable updatedInstances; @@ -72,16 +70,11 @@ /// The path to the file to import from. /// The message provider to provide messages during importer actions. /// The strategy to update the surface lines with imported data. - /// Thrown when - /// or is null. + /// Thrown when any of the input parameters is null. public PipingSurfaceLinesCsvImporter(RingtoetsPipingSurfaceLineCollection importTarget, ReferenceLine referenceLine, string filePath, IImporterMessageProvider messageProvider, ISurfaceLineUpdateDataStrategy surfaceLineUpdateStrategy) : base(filePath, importTarget) { - if (importTarget == null) - { - throw new ArgumentNullException(nameof(importTarget)); - } if (referenceLine == null) { throw new ArgumentNullException(nameof(referenceLine)); @@ -129,7 +122,7 @@ protected override void LogImportCanceledMessage() { string message = messageProvider.GetCancelledLogMessageText(RingtoetsPipingDataResources.PipingSurfaceLineCollection_TypeDescriptor); - log.Info(message); + Log.Info(message); } protected override void DoPostImportUpdates() @@ -142,7 +135,7 @@ private ReadResult HandleCriticalReadError(Exception e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); return new ReadResult(true); } @@ -184,15 +177,15 @@ } else if (readCharacteristicPointsLocations.Count > 0) { - log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_No_characteristic_points_for_SurfaceLine_0_, + Log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_No_characteristic_points_for_SurfaceLine_0_, readSurfaceLine.Name); } yield return readSurfaceLine; } foreach (string name in readCharacteristicPointsLocationNames) { - log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Characteristic_points_found_for_unknown_SurfaceLine_0_, + Log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Characteristic_points_found_for_unknown_SurfaceLine_0_, name); } } @@ -209,7 +202,7 @@ if (localDikeToeAtPolder.X <= localDikeToeAtRiver.X) { - log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, characteristicPoints.Name); + Log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, characteristicPoints.Name); return false; } @@ -222,13 +215,13 @@ if (result.TypeOfIntersection == ReferenceLineIntersectionsResult.NoIntersections) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline_0_does_not_correspond_to_current_referenceline_1_, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline_0_does_not_correspond_to_current_referenceline_1_, readSurfaceLine.Name, Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_This_could_be_caused_coordinates_being_local_coordinate_system); } else if (result.TypeOfIntersection == ReferenceLineIntersectionsResult.MultipleIntersectionsOrOverlap) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline_0_does_not_correspond_to_current_referenceline, readSurfaceLine.Name); + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline_0_does_not_correspond_to_current_referenceline, readSurfaceLine.Name); } return result; @@ -268,9 +261,7 @@ } } } - return intersectionPoint != null ? - ReferenceLineIntersectionResult.CreateIntersectionResult(intersectionPoint) : - ReferenceLineIntersectionResult.CreateNoSingleIntersectionResult(); + return intersectionPoint != null ? ReferenceLineIntersectionResult.CreateIntersectionResult(intersectionPoint) : ReferenceLineIntersectionResult.CreateNoSingleIntersectionResult(); } private static void SetCharacteristicPointsOnSurfaceLine(RingtoetsPipingSurfaceLine readSurfaceLine, CharacteristicPoints characteristicPointsLocation) @@ -322,12 +313,12 @@ return new ReadResult(true); } - log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadSurfaceLines_Start_reading_surface_lines_from_File_0_, + Log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadSurfaceLines_Start_reading_surface_lines_from_File_0_, FilePath); ReadResult readPipingSurfaceLines = ReadPipingSurfaceLines(reader); - log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadSurfaceLines_Finished_reading_surface_lines_from_File_0_, + Log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadSurfaceLines_Finished_reading_surface_lines_from_File_0_, FilePath); return readPipingSurfaceLines; @@ -387,7 +378,7 @@ } catch (LineParseException e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_ParseErrorMessage_0_SurfaceLine_skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_ParseErrorMessage_0_SurfaceLine_skipped, e.Message); } } @@ -396,7 +387,7 @@ { if (readSurfaceLineIdentifiers.Any(i => i.Name == ringtoetsPipingSurfaceLine.Name)) { - log.WarnFormat( + Log.WarnFormat( Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Duplicate_definitions_for_same_location_0_, ringtoetsPipingSurfaceLine.Name); @@ -413,7 +404,7 @@ } catch (CriticalFileReadException e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); return -1; } @@ -427,7 +418,7 @@ } catch (ArgumentException e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); return null; } @@ -453,7 +444,7 @@ if (consecutiveDuplicatePointIndices.Any()) { - log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_SurfaceLine_0_has_multiple_duplicate_geometry_points_and_is_ignored, + Log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_SurfaceLine_0_has_multiple_duplicate_geometry_points_and_is_ignored, ringtoetsPipingSurfaceLine.Name); ringtoetsPipingSurfaceLine.SetGeometry(readPoints.Where((p, index) => !consecutiveDuplicatePointIndices.Contains(index))); } @@ -479,12 +470,12 @@ return new ReadResult(true); } - log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_File_0_, + Log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_File_0_, characteristicPointsFilePath); ReadResult readCharacteristicPoints = ReadCharacteristicPoints(characteristicPointsFilePath, reader); - log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Finished_reading_characteristic_points_from_File_0_, + Log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Finished_reading_characteristic_points_from_File_0_, characteristicPointsFilePath); return readCharacteristicPoints; @@ -545,7 +536,7 @@ } catch (LineParseException e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_ParseErrorMessage_0_CharacteristicPoints_skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_ParseErrorMessage_0_CharacteristicPoints_skipped, e.Message); } } @@ -554,7 +545,7 @@ { if (list.Any(i => i.Name == location.Name)) { - log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Duplicate_definitions_for_same_characteristic_point_location_0_, + Log.WarnFormat(Resources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Duplicate_definitions_for_same_characteristic_point_location_0_, location.Name); return false; } @@ -569,7 +560,7 @@ } catch (CriticalFileReadException e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); return -1; } @@ -583,7 +574,7 @@ } catch (ArgumentException e) { - log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + Log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); return null; } @@ -594,7 +585,7 @@ string path = FilePath.Insert(FilePath.Length - csvFileExtension.Length, characteristicPointsFileSubExtension); if (!File.Exists(path)) { - log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, path); + Log.InfoFormat(Resources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, path); return null; } return path;