Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs =================================================================== diff -u -r03733ab29bedcd18c213b3d62b87080514a9a67b -rb57fef181580e4b78a36f2077d66389fc09803d9 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs (.../AssessmentSectionMerger.cs) (revision 03733ab29bedcd18c213b3d62b87080514a9a67b) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs (.../AssessmentSectionMerger.cs) (revision b57fef181580e4b78a36f2077d66389fc09803d9) @@ -25,8 +25,8 @@ using Core.Common.Gui; using log4net; using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.Merge; using Ringtoets.Integration.Plugin.Properties; -using Ringtoets.Integration.Service.Merge; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; using RingtoetsStorageResources = Ringtoets.Storage.Core.Properties.Resources; @@ -40,25 +40,33 @@ private static readonly ILog log = LogManager.GetLogger(typeof(AssessmentSectionMerger)); private readonly IInquiryHelper inquiryHandler; - private readonly IAssessmentSectionProvider assessmentSectionProvider; + private readonly Action getAssessmentSectionsAction; + private readonly AssessmentSectionsOwner assessmentSectionsOwner; /// /// Creates a new instance of , /// /// Object responsible for inquiring the required data. - /// The provider for getting the assessment sections + /// The action for getting the assessment sections /// to merge. /// Thrown when /// is null. - public AssessmentSectionMerger(IInquiryHelper inquiryHandler, IAssessmentSectionProvider assessmentSectionProvider) + public AssessmentSectionMerger(IInquiryHelper inquiryHandler, Action getAssessmentSectionsAction) { if (inquiryHandler == null) { throw new ArgumentNullException(nameof(inquiryHandler)); } + if (getAssessmentSectionsAction == null) + { + throw new ArgumentNullException(nameof(getAssessmentSectionsAction)); + } + this.inquiryHandler = inquiryHandler; - this.assessmentSectionProvider = assessmentSectionProvider; + this.getAssessmentSectionsAction = getAssessmentSectionsAction; + + assessmentSectionsOwner = new AssessmentSectionsOwner(); } public void StartMerge() @@ -75,18 +83,29 @@ return; } - IEnumerable assessmentSections = assessmentSectionProvider.GetAssessmentSections(filePath); + if (!GetAssessmentSections(filePath)) + { + return; + } + } + private bool GetAssessmentSections(string filePath) + { + getAssessmentSectionsAction(filePath, assessmentSectionsOwner); + IEnumerable assessmentSections = assessmentSectionsOwner.AssessmentSections; + if (assessmentSections == null) { - return; + return false; } if (!assessmentSections.Any()) { LogError(Resources.AssessmentSectionMerger_No_matching_AssessmentSections); - return; + return false; } + + return true; } private static void CancelMergeAndLog() Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -rd9d47cee30e2987819dfb5b8c0c935ee4a72e52a -rb57fef181580e4b78a36f2077d66389fc09803d9 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision d9d47cee30e2987819dfb5b8c0c935ee4a72e52a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision b57fef181580e4b78a36f2077d66389fc09803d9) @@ -275,7 +275,12 @@ assessmentSectionFromFileCommandHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow, Gui, Gui.DocumentViewController); hydraulicBoundaryLocationCalculationGuiService = new HydraulicBoundaryLocationCalculationGuiService(Gui.MainWindow); - assessmentSectionMerger = new AssessmentSectionMerger(new InquiryMergeHelper(), new AssessmentSectionProviderStub(Gui.MainWindow)); + assessmentSectionMerger = new AssessmentSectionMerger(new InquiryMergeHelper(), + (filePath, assessmentSectionOwner) => + { + var provider = new AssessmentSectionProviderStub(Gui.MainWindow); + assessmentSectionOwner.AssessmentSections = provider.GetAssessmentSections(filePath); + }); ribbonCommandHandler = new RingtoetsRibbon { Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs =================================================================== diff -u -r03733ab29bedcd18c213b3d62b87080514a9a67b -rb57fef181580e4b78a36f2077d66389fc09803d9 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs (.../AssessmentSectionMergerTest.cs) (revision 03733ab29bedcd18c213b3d62b87080514a9a67b) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs (.../AssessmentSectionMergerTest.cs) (revision b57fef181580e4b78a36f2077d66389fc09803d9) @@ -26,7 +26,6 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Integration.Data; -using Ringtoets.Integration.Service.Merge; namespace Ringtoets.Integration.Plugin.Test { @@ -36,17 +35,28 @@ [Test] public void Constructor_InquiryHandlerNull_ThrowsArgumentNullException() { + // Call + TestDelegate call = () => new AssessmentSectionMerger(null, (path, owner) => {}); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("inquiryHandler", exception.ParamName); + } + + [Test] + public void Constructor_GetAssessmentSectionsActionNull_ThrowsArgumentNullException() + { // Setup var mocks = new MockRepository(); - var assessmentSectionProvider = mocks.StrictMock(); + var inquiryHelper = mocks.StrictMock(); mocks.ReplayAll(); // Call - TestDelegate call = () => new AssessmentSectionMerger(null, assessmentSectionProvider); + TestDelegate call = () => new AssessmentSectionMerger(inquiryHelper, null); // Assert var exception = Assert.Throws(call); - Assert.AreEqual("inquiryHandler", exception.ParamName); + Assert.AreEqual("getAssessmentSectionsAction", exception.ParamName); mocks.VerifyAll(); } @@ -57,10 +67,9 @@ var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(null); - var assessmentSectionProvider = mocks.StrictMock(); mocks.ReplayAll(); - var merger = new AssessmentSectionMerger(inquiryHelper, assessmentSectionProvider); + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}); // Call Action call = () => merger.StartMerge(); @@ -71,17 +80,15 @@ } [Test] - public void GivenValidFilePath_WhenAssessmentSectionProviderReturnNull_Abort() + public void GivenValidFilePath_WhenGetAssessmentSectionActionReturnNull_Abort() { // Setup var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); - var assessmentSectionProvider = mocks.StrictMock(); - assessmentSectionProvider.Expect(asp => asp.GetAssessmentSections(null)).IgnoreArguments().Return(null); mocks.ReplayAll(); - var merger = new AssessmentSectionMerger(inquiryHelper, assessmentSectionProvider); + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}); // Call Action call = () => merger.StartMerge(); @@ -98,11 +105,9 @@ var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); - var assessmentSectionProvider = mocks.StrictMock(); - assessmentSectionProvider.Expect(asp => asp.GetAssessmentSections(null)).IgnoreArguments().Return(Enumerable.Empty()); mocks.ReplayAll(); - var merger = new AssessmentSectionMerger(inquiryHelper, assessmentSectionProvider); + var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => { owner.AssessmentSections = Enumerable.Empty(); }); // Call Action call = () => merger.StartMerge();