Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs =================================================================== diff -u -rb57fef181580e4b78a36f2077d66389fc09803d9 -rdf47231d9fd5a49e09f120f0e054e1b9d66cbcec --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs (.../AssessmentSectionMerger.cs) (revision b57fef181580e4b78a36f2077d66389fc09803d9) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs (.../AssessmentSectionMerger.cs) (revision df47231d9fd5a49e09f120f0e054e1b9d66cbcec) @@ -27,6 +27,7 @@ using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.Merge; using Ringtoets.Integration.Plugin.Properties; +using Ringtoets.Integration.Service.Comparers; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; using RingtoetsStorageResources = Ringtoets.Storage.Core.Properties.Resources; @@ -41,17 +42,18 @@ private readonly IInquiryHelper inquiryHandler; private readonly Action getAssessmentSectionsAction; - private readonly AssessmentSectionsOwner assessmentSectionsOwner; + private readonly IAssessmentSectionMergeComparer comparer; /// /// Creates a new instance of , /// /// Object responsible for inquiring the required data. /// The action for getting the assessment sections /// to merge. - /// Thrown when - /// is null. - public AssessmentSectionMerger(IInquiryHelper inquiryHandler, Action getAssessmentSectionsAction) + /// The comparer to compare the assessment sections with. + /// Thrown when any parameter is null. + public AssessmentSectionMerger(IInquiryHelper inquiryHandler, Action getAssessmentSectionsAction, + IAssessmentSectionMergeComparer comparer) { if (inquiryHandler == null) { @@ -63,51 +65,63 @@ throw new ArgumentNullException(nameof(getAssessmentSectionsAction)); } + if (comparer == null) + { + throw new ArgumentNullException(nameof(comparer)); + } + this.inquiryHandler = inquiryHandler; this.getAssessmentSectionsAction = getAssessmentSectionsAction; - - assessmentSectionsOwner = new AssessmentSectionsOwner(); + this.comparer = comparer; } - public void StartMerge() + /// + /// Performs the merge of . + /// + /// The assessment section to perform the merge on. + /// Thrown when + /// is null. + public void StartMerge(AssessmentSection assessmentSection) { - SelectProject(); - } + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } - private void SelectProject() - { - string filePath = inquiryHandler.GetSourceFileLocation(RingtoetsStorageResources.Ringtoets_project_file_filter); + string filePath = SelectProject(); + if (filePath == null) { CancelMergeAndLog(); return; } - if (!GetAssessmentSections(filePath)) - { - return; - } - } + IEnumerable assessmentSections = GetAssessmentSections(filePath); - private bool GetAssessmentSections(string filePath) - { - getAssessmentSectionsAction(filePath, assessmentSectionsOwner); - IEnumerable assessmentSections = assessmentSectionsOwner.AssessmentSections; - if (assessmentSections == null) { - return false; + return; } if (!assessmentSections.Any()) { LogError(Resources.AssessmentSectionMerger_No_matching_AssessmentSections); - return false; + return; } + } - return true; + private string SelectProject() + { + return inquiryHandler.GetSourceFileLocation(RingtoetsStorageResources.Ringtoets_project_file_filter); } + private IEnumerable GetAssessmentSections(string filePath) + { + var assessmentSectionsOwner = new AssessmentSectionsOwner(); + getAssessmentSectionsAction(filePath, assessmentSectionsOwner); + return assessmentSectionsOwner.AssessmentSections; + } + private static void CancelMergeAndLog() { log.Info(CoreCommonGuiResources.GuiImportHandler_ImportItemsUsingDialog_Importing_cancelled); Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r7e3cd776c36ff203c4e7c096a45777f06671929c -rdf47231d9fd5a49e09f120f0e054e1b9d66cbcec --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 7e3cd776c36ff203c4e7c096a45777f06671929c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision df47231d9fd5a49e09f120f0e054e1b9d66cbcec) @@ -92,6 +92,7 @@ using Ringtoets.Integration.Plugin.Handlers; using Ringtoets.Integration.Plugin.Properties; using Ringtoets.Integration.Service; +using Ringtoets.Integration.Service.Comparers; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; using Ringtoets.Piping.Data; @@ -275,12 +276,13 @@ assessmentSectionFromFileCommandHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow, Gui, Gui.DocumentViewController); hydraulicBoundaryLocationCalculationGuiService = new HydraulicBoundaryLocationCalculationGuiService(Gui.MainWindow); - assessmentSectionMerger = new AssessmentSectionMerger(new DialogBasedInquiryHelper(Gui.MainWindow), + assessmentSectionMerger = new AssessmentSectionMerger(new DialogBasedInquiryHelper(Gui.MainWindow), (filePath, assessmentSectionOwner) => { var provider = new AssessmentSectionProviderStub(Gui.MainWindow); assessmentSectionOwner.AssessmentSections = provider.GetAssessmentSections(filePath); - }); + }, + new AssessmentSectionMergeComparer()); ribbonCommandHandler = new RingtoetsRibbon { @@ -1470,7 +1472,7 @@ GuiResources.Import, GuiResources.Import_ToolTip, GuiResources.ImportIcon, - (sender, args) => assessmentSectionMerger.StartMerge()); + (sender, args) => assessmentSectionMerger.StartMerge((AssessmentSection) nodeData)); return Gui.Get(nodeData, treeViewControl) .AddOpenItem() Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs =================================================================== diff -u -rb57fef181580e4b78a36f2077d66389fc09803d9 -rdf47231d9fd5a49e09f120f0e054e1b9d66cbcec --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs (.../AssessmentSectionMergerTest.cs) (revision b57fef181580e4b78a36f2077d66389fc09803d9) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs (.../AssessmentSectionMergerTest.cs) (revision df47231d9fd5a49e09f120f0e054e1b9d66cbcec) @@ -25,7 +25,9 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Integration.Data; +using Ringtoets.Integration.Service.Comparers; namespace Ringtoets.Integration.Plugin.Test { @@ -35,12 +37,18 @@ [Test] public void Constructor_InquiryHandlerNull_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var comparer = mocks.StrictMock(); + mocks.ReplayAll(); + // Call - TestDelegate call = () => new AssessmentSectionMerger(null, (path, owner) => {}); + TestDelegate call = () => new AssessmentSectionMerger(null, (path, owner) => {}, comparer); // Assert var exception = Assert.Throws(call); Assert.AreEqual("inquiryHandler", exception.ParamName); + mocks.VerifyAll(); } [Test] @@ -49,10 +57,11 @@ // Setup var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); + var comparer = mocks.StrictMock(); mocks.ReplayAll(); // Call - TestDelegate call = () => new AssessmentSectionMerger(inquiryHelper, null); + TestDelegate call = () => new AssessmentSectionMerger(inquiryHelper, null, comparer); // Assert var exception = Assert.Throws(call); @@ -61,18 +70,56 @@ } [Test] + public void Constructor_ComparerNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}, null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("comparer", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void StartMerge_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + var comparer = mocks.StrictMock(); + mocks.ReplayAll(); + + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}, comparer); + + // Call + TestDelegate call = () => merger.StartMerge(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] public void StartMerge_FilePathNull_AbortAndShowCancelMessage() { // Setup var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(null); + var comparer = mocks.StrictMock(); mocks.ReplayAll(); - var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}); + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}, comparer); // Call - Action call = () => merger.StartMerge(); + Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); // Assert TestHelper.AssertLogMessageWithLevelIsGenerated(call, new Tuple("Importeren van gegevens is geannuleerd.", LogLevelConstant.Info), 1); @@ -86,12 +133,13 @@ var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); + var comparer = mocks.StrictMock(); mocks.ReplayAll(); - var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}); + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}, comparer); // Call - Action call = () => merger.StartMerge(); + Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); // Assert TestHelper.AssertLogMessagesCount(call, 0); @@ -105,12 +153,14 @@ var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); + var comparer = mocks.StrictMock(); mocks.ReplayAll(); - var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => { owner.AssessmentSections = Enumerable.Empty(); }); + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => { owner.AssessmentSections = Enumerable.Empty(); }, + comparer); // Call - Action call = () => merger.StartMerge(); + Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); // Assert TestHelper.AssertLogMessageWithLevelIsGenerated(call, new Tuple("Er zijn geen trajecten gevonden die samengevoegd kunnen worden.", LogLevelConstant.Error), 1);