Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/AssessmentSectionMergeDataProviderDialog.cs =================================================================== diff -u -r48244f68eee25ef1d91701d82e4c4867f0252ffc -rc955304a80f98036956cb8159e87efd406723894 --- Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/AssessmentSectionMergeDataProviderDialog.cs (.../AssessmentSectionMergeDataProviderDialog.cs) (revision 48244f68eee25ef1d91701d82e4c4867f0252ffc) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/AssessmentSectionMergeDataProviderDialog.cs (.../AssessmentSectionMergeDataProviderDialog.cs) (revision c955304a80f98036956cb8159e87efd406723894) @@ -148,7 +148,7 @@ private bool FailureMechanismIsSelectedToMerge() where TFailureMechanism : IFailureMechanism { - return failureMechanismMergeDataRows.Any(row => row.FailureMechanism is TFailureMechanism && row.IsSelected); + return failureMechanismMergeDataRows.Any(row => row.FailurePath is TFailureMechanism && row.IsSelected); } #region Event Handling Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/FailureMechanismMergeDataRow.cs =================================================================== diff -u -rc36b47c2e1e8cf948767cca33f80ad735f370ad0 -rc955304a80f98036956cb8159e87efd406723894 --- Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/FailureMechanismMergeDataRow.cs (.../FailureMechanismMergeDataRow.cs) (revision c36b47c2e1e8cf948767cca33f80ad735f370ad0) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/FailureMechanismMergeDataRow.cs (.../FailureMechanismMergeDataRow.cs) (revision c955304a80f98036956cb8159e87efd406723894) @@ -29,76 +29,27 @@ /// Row representing the information of a to be /// used for merging. /// - internal class FailureMechanismMergeDataRow + internal class FailureMechanismMergeDataRow : FailurePathMergeDataRow { + private readonly IFailureMechanism failureMechanism; + /// /// Creates a new instance of . /// /// The wrapped . /// Thrown when /// is null. - public FailureMechanismMergeDataRow(IFailureMechanism failureMechanism) + public FailureMechanismMergeDataRow(IFailureMechanism failureMechanism) : base(failureMechanism) { - if (failureMechanism == null) - { - throw new ArgumentNullException(nameof(failureMechanism)); - } - - FailureMechanism = failureMechanism; + this.failureMechanism = failureMechanism; } - /// - /// Gets the wrapped failure mechanism of the row. - /// - public IFailureMechanism FailureMechanism { get; } - - /// - /// Gets and sets whether the failure mechanism is selected to be merged. - /// - public bool IsSelected { get; set; } - - /// - /// Gets the name of the failure mechanism. - /// - public string Name + public override int NumberOfCalculations { get { - return FailureMechanism.Name; + return failureMechanism.Calculations.Count(); } } - - /// - /// Gets indicator whether the failure mechanism is marked relevant. - /// - public bool IsRelevant - { - get - { - return FailureMechanism.IsRelevant; - } - } - - /// - /// Gets indicator whether the failure mechanism has sections. - /// - public bool HasSections - { - get - { - return FailureMechanism.Sections.Any(); - } - } - - /// - /// Gets the amount of calculations that are contained by the failure mechanism. - /// - public int NumberOfCalculations - { - get - { - return FailureMechanism.Calculations.Count(); - } - } } } \ No newline at end of file Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/FailurePathMergeDataRow.cs =================================================================== diff -u --- Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/FailurePathMergeDataRow.cs (revision 0) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Merge/FailurePathMergeDataRow.cs (revision c955304a80f98036956cb8159e87efd406723894) @@ -0,0 +1,105 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 System.Linq; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; + +namespace Riskeer.Integration.Forms.Merge +{ + /// + /// Row representing the information of a to be + /// used for merging. + /// + internal class FailurePathMergeDataRow + { + /// + /// Creates a new instance of . + /// + /// The wrapped . + /// Thrown when + /// is null. + public FailurePathMergeDataRow(IFailurePath failurePath) + { + if (failurePath == null) + { + throw new ArgumentNullException(nameof(failurePath)); + } + + FailurePath = failurePath; + } + + /// + /// Gets the wrapped failure path of the row. + /// + public IFailurePath FailurePath { get; } + + /// + /// Gets and sets whether the failure mechanism is selected to be merged. + /// + public bool IsSelected { get; set; } + + /// + /// Gets the name of the failure mechanism. + /// + public string Name + { + get + { + return FailurePath.Name; + } + } + + /// + /// Gets indicator whether the failure mechanism is marked relevant. + /// + public bool IsRelevant + { + get + { + return FailurePath.IsRelevant; + } + } + + /// + /// Gets indicator whether the failure mechanism has sections. + /// + public bool HasSections + { + get + { + return FailurePath.Sections.Any(); + } + } + + /// + /// Gets the amount of calculations that are contained by the failure mechanism. + /// + public virtual int NumberOfCalculations + { + get + { + return 0; + } + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Merge/FailureMechanismMergeDataRowTest.cs =================================================================== diff -u -rc36b47c2e1e8cf948767cca33f80ad735f370ad0 -rc955304a80f98036956cb8159e87efd406723894 --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Merge/FailureMechanismMergeDataRowTest.cs (.../FailureMechanismMergeDataRowTest.cs) (revision c36b47c2e1e8cf948767cca33f80ad735f370ad0) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Merge/FailureMechanismMergeDataRowTest.cs (.../FailureMechanismMergeDataRowTest.cs) (revision c955304a80f98036956cb8159e87efd406723894) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Riskeer.Common.Data.FailureMechanism; @@ -35,68 +34,26 @@ public class FailureMechanismMergeDataRowTest { [Test] - public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() - { - // Call - TestDelegate call = () => new FailureMechanismMergeDataRow(null); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("failureMechanism", exception.ParamName); - } - - [Test] public void Constructor_ExpectedValues() { // Setup - const string failureMechanismName = "Just a name"; - var random = new Random(21); - bool isRelevant = random.NextBoolean(); IEnumerable calculations = Enumerable.Repeat(new TestCalculation(), random.Next(0, 10)); var mocks = new MockRepository(); var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.Name).Return(failureMechanismName); failureMechanism.Stub(fm => fm.Calculations).Return(calculations); - failureMechanism.Stub(fm => fm.Sections).Return(Enumerable.Empty()); mocks.ReplayAll(); - failureMechanism.IsRelevant = isRelevant; - // Call var row = new FailureMechanismMergeDataRow(failureMechanism); // Assert - Assert.AreSame(failureMechanism, row.FailureMechanism); - - Assert.IsFalse(row.IsSelected); - Assert.AreEqual(failureMechanism.Name, row.Name); - Assert.AreEqual(isRelevant, row.IsRelevant); - Assert.IsFalse(row.HasSections); + Assert.IsInstanceOf(row); + Assert.AreSame(failureMechanism, row.FailurePath); Assert.AreEqual(calculations.Count(), row.NumberOfCalculations); mocks.ReplayAll(); } - - [Test] - public void HasSections_FailureMechanismWithSections_ReturnsTrue() - { - // Setup - var random = new Random(21); - IEnumerable sections = Enumerable.Repeat(FailureMechanismSectionTestFactory.CreateFailureMechanismSection(), - random.Next(1, 10)); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.Sections).Return(sections); - mocks.ReplayAll(); - - // Call - var row = new FailureMechanismMergeDataRow(failureMechanism); - - // Assert - Assert.IsTrue(row.HasSections); - } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Merge/FailurePathMergeDataRowTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Merge/FailurePathMergeDataRowTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Merge/FailurePathMergeDataRowTest.cs (revision c955304a80f98036956cb8159e87efd406723894) @@ -0,0 +1,99 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 System.Collections.Generic; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Integration.Forms.Merge; + +namespace Riskeer.Integration.Forms.Test.Merge +{ + [TestFixture] + public class FailurePathMergeDataRowTest + { + [Test] + public void Constructor_FailurePathNull_ThrowsArgumentNullException() + { + // Call + void Call() => new FailurePathMergeDataRow(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("failurePath", exception.ParamName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + const string failurePathName = "Just a name"; + + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + + var mocks = new MockRepository(); + var failurePath = mocks.Stub(); + failurePath.Stub(fm => fm.Name).Return(failurePathName); + failurePath.Stub(fm => fm.Sections).Return(Enumerable.Empty()); + mocks.ReplayAll(); + + failurePath.IsRelevant = isRelevant; + + // Call + var row = new FailurePathMergeDataRow(failurePath); + + // Assert + Assert.IsInstanceOf(row); + Assert.AreSame(failurePath, row.FailurePath); + Assert.AreEqual(isRelevant, failurePath.IsRelevant); + Assert.IsFalse(row.HasSections); + Assert.AreEqual(0, row.NumberOfCalculations); + + mocks.ReplayAll(); + } + + [Test] + public void HasSections_FailureMechanismWithSections_ReturnsTrue() + { + // Setup + var random = new Random(21); + IEnumerable sections = Enumerable.Repeat(FailureMechanismSectionTestFactory.CreateFailureMechanismSection(), + random.Next(1, 10)); + + var mocks = new MockRepository(); + var failurePath = mocks.Stub(); + failurePath.Stub(fm => fm.Sections).Return(sections); + mocks.ReplayAll(); + + // Call + var row = new FailurePathMergeDataRow(failurePath); + + // Assert + Assert.IsTrue(row.HasSections); + } + } +} \ No newline at end of file