Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs =================================================================== diff -u -rdf47231d9fd5a49e09f120f0e054e1b9d66cbcec -rc3fd577c21a688d79caacbfcd5497555f539c3fa --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs (.../AssessmentSectionMerger.cs) (revision df47231d9fd5a49e09f120f0e054e1b9d66cbcec) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/AssessmentSectionMerger.cs (.../AssessmentSectionMerger.cs) (revision c3fd577c21a688d79caacbfcd5497555f539c3fa) @@ -108,6 +108,14 @@ LogError(Resources.AssessmentSectionMerger_No_matching_AssessmentSections); return; } + + IEnumerable matchingAssessmentSections = assessmentSections.Where(section => comparer.Compare(assessmentSection, section)); + + if (!matchingAssessmentSections.Any()) + { + LogError(Resources.AssessmentSectionMerger_No_matching_AssessmentSections); + return; + } } private string SelectProject() Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs =================================================================== diff -u -rdf47231d9fd5a49e09f120f0e054e1b9d66cbcec -rc3fd577c21a688d79caacbfcd5497555f539c3fa --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs (.../AssessmentSectionMergerTest.cs) (revision df47231d9fd5a49e09f120f0e054e1b9d66cbcec) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/AssessmentSectionMergerTest.cs (.../AssessmentSectionMergerTest.cs) (revision c3fd577c21a688d79caacbfcd5497555f539c3fa) @@ -27,6 +27,7 @@ using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.Merge; using Ringtoets.Integration.Service.Comparers; namespace Ringtoets.Integration.Plugin.Test @@ -127,9 +128,9 @@ } [Test] - public void GivenValidFilePath_WhenGetAssessmentSectionActionReturnNull_Abort() + public void GivenValidFilePath_WhenGetAssessmentSectionActionReturnNull_ThenAbort() { - // Setup + // Given var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock(); inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); @@ -138,33 +139,95 @@ var merger = new AssessmentSectionMerger(inquiryHelper, (path, owner) => {}, comparer); - // Call + // When Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); - // Assert + // Then TestHelper.AssertLogMessagesCount(call, 0); mocks.VerifyAll(); } [Test] - public void GivenValidFilePath_WhenAssessmentSectionProviderReturnEmptyCollection_LogErrorAndAbort() + public void GivenValidFilePath_WhenAssessmentSectionProviderReturnEmptyCollection_ThenLogErrorAndAbort() { - // Setup + // Given 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(); }, - comparer); + Action getAssessmentSectionsAction = (path, owner) => + { + owner.AssessmentSections = Enumerable.Empty(); + }; - // Call + var merger = new AssessmentSectionMerger(inquiryHelper, getAssessmentSectionsAction, comparer); + + // When Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); - // Assert + // Then TestHelper.AssertLogMessageWithLevelIsGenerated(call, new Tuple("Er zijn geen trajecten gevonden die samengevoegd kunnen worden.", LogLevelConstant.Error), 1); mocks.VerifyAll(); } + + [Test] + public void GivenAssessmentSection_WhenComparerReturnFalse_ThenLogErrorAndAbort() + { + // Given + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); + var comparer = mocks.StrictMock(); + comparer.Expect(c => c.Compare(null, null)).IgnoreArguments().Return(false); + mocks.ReplayAll(); + + Action getAssessmentSectionsAction = (path, owner) => + { + owner.AssessmentSections = new [] + { + new AssessmentSection(AssessmentSectionComposition.Dike) + }; + }; + + var merger = new AssessmentSectionMerger(inquiryHelper, getAssessmentSectionsAction, comparer); + + // When + Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); + + // Then + TestHelper.AssertLogMessageWithLevelIsGenerated(call, new Tuple("Er zijn geen trajecten gevonden die samengevoegd kunnen worden.", LogLevelConstant.Error), 1); + mocks.VerifyAll(); + } + + [Test] + public void GivenAssessmentSection_WhenComparerReturnTrue_ThenContinue() + { + // Given + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + inquiryHelper.Expect(helper => helper.GetSourceFileLocation(null)).IgnoreArguments().Return(string.Empty); + var comparer = mocks.StrictMock(); + comparer.Expect(c => c.Compare(null, null)).IgnoreArguments().Return(true); + mocks.ReplayAll(); + + Action getAssessmentSectionsAction = (path, owner) => + { + owner.AssessmentSections = new [] + { + new AssessmentSection(AssessmentSectionComposition.Dike) + }; + }; + + var merger = new AssessmentSectionMerger(inquiryHelper, getAssessmentSectionsAction, comparer); + + // When + Action call = () => merger.StartMerge(new AssessmentSection(AssessmentSectionComposition.Dike)); + + // Then + TestHelper.AssertLogMessagesCount(call, 0); + mocks.VerifyAll(); + } } } \ No newline at end of file