Index: Riskeer/Common/test/Riskeer.Common.Plugin.TestUtil/ShouldCloseViewWithCalculationDataTester.cs =================================================================== diff -u -rbd7885ae0b850e7c716f6dd703bbbac2344bf564 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/Common/test/Riskeer.Common.Plugin.TestUtil/ShouldCloseViewWithCalculationDataTester.cs (.../ShouldCloseViewWithCalculationDataTester.cs) (revision bd7885ae0b850e7c716f6dd703bbbac2344bf564) +++ Riskeer/Common/test/Riskeer.Common.Plugin.TestUtil/ShouldCloseViewWithCalculationDataTester.cs (.../ShouldCloseViewWithCalculationDataTester.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -133,7 +133,7 @@ Assert.IsFalse(closeForData); } } - + [Test] public void ShouldCloseMethod_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() { @@ -240,7 +240,10 @@ /// A default implementation is added for creating a . protected virtual IFailureMechanism GetFailureMechanismWithCalculation() { - return new TestFailureMechanism(); + return new TestFailureMechanism(new[] + { + new TestCalculation() + }); } private class TestCalculationContext : Observable, ICalculationContext Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs =================================================================== diff -u -rc361e194e7f16a870558176f3cfa2fddd259d6c5 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision c361e194e7f16a870558176f3cfa2fddd259d6c5) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -42,6 +42,7 @@ using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.TreeNodeInfos; using Riskeer.Common.Forms.UpdateInfos; +using Riskeer.Common.Plugin; using Riskeer.Common.Service; using Riskeer.Common.Util.Helpers; using Riskeer.GrassCoverErosionOutwards.Data; @@ -145,7 +146,7 @@ { Image = RiskeerCommonFormsResources.GenericInputOutputIcon, GetViewName = (view, context) => RiskeerCommonFormsResources.Calculation_Input, - CloseForData = CloseInputViewForData, + CloseForData = RiskeerPluginHelper.ShouldCloseViewWithCalculationData, CreateInstance = context => new WaveConditionsInputView( context.Calculation, () => WaveConditionsInputHelper.GetHydraulicBoundaryLocationCalculation(context.WrappedData, context.AssessmentSection), @@ -302,42 +303,6 @@ return failureMechanism != null && ReferenceEquals(view.FailureMechanism.SectionResults, failureMechanism.SectionResults); } - private static bool CloseInputViewForData(WaveConditionsInputView view, object dataToCloseFor) - { - GrassCoverErosionOutwardsFailureMechanism failureMechanism = null; - - if (dataToCloseFor is IAssessmentSection assessmentSection) - { - failureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .FirstOrDefault(); - } - - IEnumerable calculations = null; - - if (failureMechanism != null) - { - calculations = failureMechanism.WaveConditionsCalculationGroup.GetCalculations() - .OfType(); - } - - if (dataToCloseFor is GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext calculationGroupContext) - { - calculations = calculationGroupContext.WrappedData.GetCalculations() - .OfType(); - } - - if (dataToCloseFor is GrassCoverErosionOutwardsWaveConditionsCalculationContext calculationContext) - { - calculations = new[] - { - calculationContext.WrappedData - }; - } - - return calculations != null && calculations.Any(ci => ReferenceEquals(view.Data, ci)); - } - #endregion #region TreeNodeInfos Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest.cs =================================================================== diff -u -ra37ea507632afd8fefc92fec5e3246dcbc86b4b0 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest.cs) (revision a37ea507632afd8fefc92fec5e3246dcbc86b4b0) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -28,12 +28,14 @@ using Core.Components.Chart.Data; using Core.Gui.Plugin; using NUnit.Framework; -using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Plugin.TestUtil; using Riskeer.GrassCoverErosionOutwards.Data; using Riskeer.GrassCoverErosionOutwards.Forms.PresentationObjects; using Riskeer.GrassCoverErosionOutwards.Forms.Views; @@ -45,7 +47,7 @@ namespace Riskeer.GrassCoverErosionOutwards.Plugin.Test.ViewInfos { [TestFixture] - public class GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest + public class GrassCoverErosionOutwardsWaveConditionsInputViewInfoTest : ShouldCloseViewWithCalculationDataTester { private const int lowerBoundaryRevetmentChartDataIndex = 1; private const int upperBoundaryRevetmentChartDataIndex = 2; @@ -154,416 +156,63 @@ } } - #region CloseForData + #region ShouldCloseViewWithCalculationDataTester - [Test] - public void CloseForData_ViewCorrespondingToRemovedCalculationContext_ReturnsTrue() + protected override bool ShouldCloseMethod(IView view, object o) { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationContext = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(calculation, - new CalculationGroup(), - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return info.CloseForData(view, o); } - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedCalculationContext_ReturnsFalse() + protected override IView GetView(ICalculation data) { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationToRemove = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - - var calculationContext = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(calculationToRemove, - new CalculationGroup(), - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return new WaveConditionsInputView((ICalculation) data, + () => new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), + new GrassCoverErosionOutwardsWaveConditionsInputViewStyle()); } - [Test] - public void CloseForData_ViewCorrespondingWithRemovedCalculationGroupContext_ReturnsTrue() + protected override ICalculation GetCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var calculationGroupContext = new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext(calculationGroup, - null, - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return new GrassCoverErosionOutwardsWaveConditionsCalculation(); } - [Test] - public void CloseForData_ViewNotCorrespondingWithRemovedCalculationGroupContext_ReturnsFalse() + protected override ICalculationContext GetCalculationContextWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var calculationGroupContext = new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext(new CalculationGroup(), - null, - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return new GrassCoverErosionOutwardsWaveConditionsCalculationContext( + new GrassCoverErosionOutwardsWaveConditionsCalculation(), + new CalculationGroup(), + new GrassCoverErosionOutwardsFailureMechanism(), + new AssessmentSectionStub()); } - [Test] - public void CloseForData_NestedViewCorrespondingWithRemovedParentCalculationGroupContext_ReturnsTrue() + protected override ICalculationContext GetCalculationGroupContextWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - var nestedGroup = new CalculationGroup(); - nestedGroup.Children.Add(calculation); - calculationGroup.Children.Add(nestedGroup); - - var calculationGroupContext = new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext(calculationGroup, - null, - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext( + new CalculationGroup + { + Children = + { + new GrassCoverErosionOutwardsWaveConditionsCalculation() + } + }, + null, + new GrassCoverErosionOutwardsFailureMechanism(), + new AssessmentSectionStub()); } - [Test] - public void CloseForData_NestedViewNotCorrespondingWithRemovedParentCalculationGroupContext_ReturnsFalse() + protected override IFailureMechanism GetFailureMechanismWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - var nestedGroup = new CalculationGroup(); - nestedGroup.Children.Add(calculation); - calculationGroup.Children.Add(nestedGroup); - - var calculationGroupContext = new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext(new CalculationGroup(), - null, - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) + return new GrassCoverErosionOutwardsFailureMechanism { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + WaveConditionsCalculationGroup = + { + Children = + { + new GrassCoverErosionOutwardsWaveConditionsCalculation() + } + } + }; } - [Test] - public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var context = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(calculation, - new CalculationGroup(), - failureMechanism, - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var context = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(new GrassCoverErosionOutwardsWaveConditionsCalculation(), - new CalculationGroup(), - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var context = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(calculation, - calculationGroup, - failureMechanism, - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var context = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(new GrassCoverErosionOutwardsWaveConditionsCalculation(), - calculationGroup, - new GrassCoverErosionOutwardsFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(new GrassCoverErosionOutwardsWaveConditionsCalculation())) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(new GrassCoverErosionOutwardsWaveConditionsCalculation())) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - private static IView GetView(ICalculation data) - { - return new WaveConditionsInputView((ICalculation) data, - () => new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), - new GrassCoverErosionOutwardsWaveConditionsInputViewStyle()); - } - #endregion - } } \ No newline at end of file Index: Riskeer/StabilityStoneCover/src/Riskeer.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs =================================================================== diff -u -r9116acdf8bbcbe18997485db44205aadf363f702 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/StabilityStoneCover/src/Riskeer.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs (.../StabilityStoneCoverPlugin.cs) (revision 9116acdf8bbcbe18997485db44205aadf363f702) +++ Riskeer/StabilityStoneCover/src/Riskeer.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs (.../StabilityStoneCoverPlugin.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -42,6 +42,7 @@ using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.TreeNodeInfos; using Riskeer.Common.Forms.UpdateInfos; +using Riskeer.Common.Plugin; using Riskeer.Common.Service; using Riskeer.Common.Util.Helpers; using Riskeer.Revetment.Data; @@ -126,7 +127,7 @@ { Image = RiskeerCommonFormsResources.GenericInputOutputIcon, GetViewName = (view, context) => RiskeerCommonFormsResources.Calculation_Input, - CloseForData = CloseInputViewForData, + CloseForData = RiskeerPluginHelper.ShouldCloseViewWithCalculationData, CreateInstance = context => new WaveConditionsInputView( context.Calculation, () => WaveConditionsInputHelper.GetHydraulicBoundaryLocationCalculation(context.WrappedData, context.AssessmentSection), @@ -299,42 +300,6 @@ return failureMechanism != null && ReferenceEquals(view.FailureMechanism.SectionResults, failureMechanism.SectionResults); } - private static bool CloseInputViewForData(WaveConditionsInputView view, object dataToCloseFor) - { - StabilityStoneCoverFailureMechanism failureMechanism = null; - - if (dataToCloseFor is IAssessmentSection assessmentSection) - { - failureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .FirstOrDefault(); - } - - IEnumerable calculations = null; - - if (failureMechanism != null) - { - calculations = failureMechanism.WaveConditionsCalculationGroup.GetCalculations() - .OfType(); - } - - if (dataToCloseFor is StabilityStoneCoverWaveConditionsCalculationGroupContext calculationGroupContext) - { - calculations = calculationGroupContext.WrappedData.GetCalculations() - .OfType(); - } - - if (dataToCloseFor is StabilityStoneCoverWaveConditionsCalculationContext calculationContext) - { - calculations = new[] - { - calculationContext.WrappedData - }; - } - - return calculations != null && calculations.Any(ci => ReferenceEquals(view.Data, ci)); - } - #endregion #region TreeNodeInfos Index: Riskeer/StabilityStoneCover/test/Riskeer.StabilityStoneCover.Plugin.Test/ViewInfos/StabilityStoneCoverWaveConditionsInputViewInfoTest.cs =================================================================== diff -u -ra37ea507632afd8fefc92fec5e3246dcbc86b4b0 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/StabilityStoneCover/test/Riskeer.StabilityStoneCover.Plugin.Test/ViewInfos/StabilityStoneCoverWaveConditionsInputViewInfoTest.cs (.../StabilityStoneCoverWaveConditionsInputViewInfoTest.cs) (revision a37ea507632afd8fefc92fec5e3246dcbc86b4b0) +++ Riskeer/StabilityStoneCover/test/Riskeer.StabilityStoneCover.Plugin.Test/ViewInfos/StabilityStoneCoverWaveConditionsInputViewInfoTest.cs (.../StabilityStoneCoverWaveConditionsInputViewInfoTest.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -28,12 +28,14 @@ using Core.Components.Chart.Data; using Core.Gui.Plugin; using NUnit.Framework; -using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Plugin.TestUtil; using Riskeer.Revetment.Data; using Riskeer.Revetment.Data.TestUtil; using Riskeer.Revetment.Forms.Views; @@ -45,7 +47,7 @@ namespace Riskeer.StabilityStoneCover.Plugin.Test.ViewInfos { [TestFixture] - public class StabilityStoneCoverWaveConditionsInputViewInfoTest + public class StabilityStoneCoverWaveConditionsInputViewInfoTest : ShouldCloseViewWithCalculationDataTester { private const int lowerBoundaryRevetmentChartDataIndex = 1; private const int upperBoundaryRevetmentChartDataIndex = 2; @@ -154,415 +156,63 @@ } } - #region CloseForData + #region ShouldCloseViewWithCalculationDataTester - [Test] - public void CloseForData_ViewCorrespondingToRemovedCalculationContext_ReturnsTrue() + protected override bool ShouldCloseMethod(IView view, object o) { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationContext = new StabilityStoneCoverWaveConditionsCalculationContext(calculation, - new CalculationGroup(), - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return info.CloseForData(view, o); } - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedCalculationContext_ReturnsFalse() + protected override IView GetView(ICalculation data) { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationToRemove = new StabilityStoneCoverWaveConditionsCalculation(); - - var calculationContext = new StabilityStoneCoverWaveConditionsCalculationContext(calculationToRemove, - new CalculationGroup(), - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return new WaveConditionsInputView((ICalculation) data, + () => new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), + new StabilityStoneCoverWaveConditionsInputViewStyle()); } - [Test] - public void CloseForData_ViewCorrespondingWithRemovedCalculationGroupContext_ReturnsTrue() + protected override ICalculation GetCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var calculationGroupContext = new StabilityStoneCoverWaveConditionsCalculationGroupContext(calculationGroup, - null, - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return new StabilityStoneCoverWaveConditionsCalculation(); } - [Test] - public void CloseForData_ViewNotCorrespondingWithRemovedCalculationGroupContext_ReturnsFalse() + protected override ICalculationContext GetCalculationContextWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var calculationGroupContext = new StabilityStoneCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - null, - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return new StabilityStoneCoverWaveConditionsCalculationContext( + new StabilityStoneCoverWaveConditionsCalculation(), + new CalculationGroup(), + new StabilityStoneCoverFailureMechanism(), + new AssessmentSectionStub()); } - [Test] - public void CloseForData_NestedViewCorrespondingWithRemovedParentCalculationGroupContext_ReturnsTrue() + protected override ICalculationContext GetCalculationGroupContextWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - var nestedGroup = new CalculationGroup(); - nestedGroup.Children.Add(calculation); - calculationGroup.Children.Add(nestedGroup); - - var calculationGroupContext = new StabilityStoneCoverWaveConditionsCalculationGroupContext(calculationGroup, - null, - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return new StabilityStoneCoverWaveConditionsCalculationGroupContext( + new CalculationGroup + { + Children = + { + new StabilityStoneCoverWaveConditionsCalculation() + } + }, + null, + new StabilityStoneCoverFailureMechanism(), + new AssessmentSectionStub()); } - [Test] - public void CloseForData_NestedViewNotCorrespondingWithRemovedParentCalculationGroupContext_ReturnsFalse() + protected override IFailureMechanism GetFailureMechanismWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - var nestedGroup = new CalculationGroup(); - nestedGroup.Children.Add(calculation); - calculationGroup.Children.Add(nestedGroup); - - var calculationGroupContext = new StabilityStoneCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - null, - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) + return new StabilityStoneCoverFailureMechanism { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + WaveConditionsCalculationGroup = + { + Children = + { + new StabilityStoneCoverWaveConditionsCalculation() + } + } + }; } - [Test] - public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var context = new StabilityStoneCoverWaveConditionsCalculationContext(calculation, - new CalculationGroup(), - failureMechanism, - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var context = new StabilityStoneCoverWaveConditionsCalculationContext(new StabilityStoneCoverWaveConditionsCalculation(), - new CalculationGroup(), - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var context = new StabilityStoneCoverWaveConditionsCalculationContext(calculation, - calculationGroup, - failureMechanism, - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var context = new StabilityStoneCoverWaveConditionsCalculationContext(new StabilityStoneCoverWaveConditionsCalculation(), - calculationGroup, - new StabilityStoneCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(new StabilityStoneCoverWaveConditionsCalculation())) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var calculation = new StabilityStoneCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new StabilityStoneCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(new StabilityStoneCoverWaveConditionsCalculation())) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - private static IView GetView(ICalculation data) - { - return new WaveConditionsInputView((ICalculation) data, - () => new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), - new StabilityStoneCoverWaveConditionsInputViewStyle()); - } - #endregion } } \ No newline at end of file Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs =================================================================== diff -u -rc361e194e7f16a870558176f3cfa2fddd259d6c5 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision c361e194e7f16a870558176f3cfa2fddd259d6c5) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -42,6 +42,7 @@ using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.TreeNodeInfos; using Riskeer.Common.Forms.UpdateInfos; +using Riskeer.Common.Plugin; using Riskeer.Common.Service; using Riskeer.Common.Util.Helpers; using Riskeer.Revetment.Data; @@ -123,7 +124,7 @@ { Image = RiskeerCommonFormsResources.GenericInputOutputIcon, GetViewName = (view, context) => RiskeerCommonFormsResources.Calculation_Input, - CloseForData = CloseInputViewForData, + CloseForData = RiskeerPluginHelper.ShouldCloseViewWithCalculationData, CreateInstance = context => new WaveConditionsInputView( context.Calculation, () => WaveConditionsInputHelper.GetHydraulicBoundaryLocationCalculation(context.WrappedData, context.AssessmentSection), @@ -297,43 +298,7 @@ return failureMechanism != null && ReferenceEquals(view.FailureMechanism.SectionResults, failureMechanism.SectionResults); } - private static bool CloseInputViewForData(WaveConditionsInputView view, object dataToCloseFor) - { - WaveImpactAsphaltCoverFailureMechanism failureMechanism = null; - if (dataToCloseFor is IAssessmentSection assessmentSection) - { - failureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .FirstOrDefault(); - } - - IEnumerable calculations = null; - - if (failureMechanism != null) - { - calculations = failureMechanism.WaveConditionsCalculationGroup.GetCalculations() - .OfType(); - } - - if (dataToCloseFor is WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext calculationGroupContext) - { - calculations = calculationGroupContext.WrappedData.GetCalculations() - .OfType(); - } - - if (dataToCloseFor is WaveImpactAsphaltCoverWaveConditionsCalculationContext calculationContext) - { - calculations = new[] - { - calculationContext.WrappedData - }; - } - - return calculations != null && calculations.Any(ci => ReferenceEquals(view.Data, ci)); - } - - #endregion #region TreeNodeInfos Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest.cs =================================================================== diff -u -ra37ea507632afd8fefc92fec5e3246dcbc86b4b0 -r9959b748c7055a8d2716a60be77ac8edb8663e86 --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest.cs) (revision a37ea507632afd8fefc92fec5e3246dcbc86b4b0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest.cs) (revision 9959b748c7055a8d2716a60be77ac8edb8663e86) @@ -28,12 +28,14 @@ using Core.Components.Chart.Data; using Core.Gui.Plugin; using NUnit.Framework; -using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Plugin.TestUtil; using Riskeer.Revetment.Data; using Riskeer.Revetment.Data.TestUtil; using Riskeer.Revetment.Forms.Views; @@ -45,7 +47,7 @@ namespace Riskeer.WaveImpactAsphaltCover.Plugin.Test.ViewInfos { [TestFixture] - public class WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest + public class WaveImpactAsphaltCoverWaveConditionsInputViewInfoTest : ShouldCloseViewWithCalculationDataTester { private const int lowerBoundaryRevetmentChartDataIndex = 1; private const int upperBoundaryRevetmentChartDataIndex = 2; @@ -153,416 +155,64 @@ Assert.IsEmpty(designWaterLevelChartData.Points); } } - - #region CloseForData - [Test] - public void CloseForData_ViewCorrespondingToRemovedCalculationContext_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); + #region ShouldCloseViewWithCalculationDataTester - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationContext = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, - new CalculationGroup(), - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedCalculationContext_ReturnsFalse() + protected override bool ShouldCloseMethod(IView view, object o) { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationToRemove = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - - var calculationContext = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculationToRemove, - new CalculationGroup(), - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return info.CloseForData(view, o); } - [Test] - public void CloseForData_ViewCorrespondingWithRemovedCalculationGroupContext_ReturnsTrue() + protected override IView GetView(ICalculation data) { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var calculationGroupContext = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(calculationGroup, - null, - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return new WaveConditionsInputView((ICalculation) data, + () => new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), + new WaveImpactAsphaltCoverWaveConditionsInputViewStyle()); } - [Test] - public void CloseForData_ViewNotCorrespondingWithRemovedCalculationGroupContext_ReturnsFalse() + protected override ICalculation GetCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var calculationGroupContext = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - null, - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return new WaveImpactAsphaltCoverWaveConditionsCalculation(); } - [Test] - public void CloseForData_NestedViewCorrespondingWithRemovedParentCalculationGroupContext_ReturnsTrue() + protected override ICalculationContext GetCalculationContextWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - var nestedGroup = new CalculationGroup(); - nestedGroup.Children.Add(calculation); - calculationGroup.Children.Add(nestedGroup); - - var calculationGroupContext = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(calculationGroup, - null, - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + return new WaveImpactAsphaltCoverWaveConditionsCalculationContext( + new WaveImpactAsphaltCoverWaveConditionsCalculation(), + new CalculationGroup(), + new WaveImpactAsphaltCoverFailureMechanism(), + new AssessmentSectionStub()); } - [Test] - public void CloseForData_NestedViewNotCorrespondingWithRemovedParentCalculationGroupContext_ReturnsFalse() + protected override ICalculationContext GetCalculationGroupContextWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - var nestedGroup = new CalculationGroup(); - nestedGroup.Children.Add(calculation); - calculationGroup.Children.Add(nestedGroup); - - var calculationGroupContext = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - null, - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, calculationGroupContext); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } + return new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext( + new CalculationGroup + { + Children = + { + new WaveImpactAsphaltCoverWaveConditionsCalculation() + } + }, + null, + new WaveImpactAsphaltCoverFailureMechanism(), + new AssessmentSectionStub()); } - [Test] - public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + protected override IFailureMechanism GetFailureMechanismWithCalculation() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, - new CalculationGroup(), - failureMechanism, - assessmentSection); - - using (var view = GetView(calculation)) + return new WaveImpactAsphaltCoverFailureMechanism { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } + WaveConditionsCalculationGroup = + { + Children = + { + new WaveImpactAsphaltCoverWaveConditionsCalculation() + } + } + }; } - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(new WaveImpactAsphaltCoverWaveConditionsCalculation(), - new CalculationGroup(), - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, - calculationGroup, - failureMechanism, - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(new WaveImpactAsphaltCoverWaveConditionsCalculation(), - calculationGroup, - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, context); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(new WaveImpactAsphaltCoverWaveConditionsCalculation())) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var mocks = new MockRepository(); - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(calculation)) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsTrue(closeForData); - mocks.VerifyAll(); - } - } - - [Test] - public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() - { - // Setup - var mocks = new MockRepository(); - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - var calculationGroup = new CalculationGroup(); - calculationGroup.Children.Add(calculation); - - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationGroup); - - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] - { - failureMechanism - }); - - mocks.ReplayAll(); - - using (var view = GetView(new WaveImpactAsphaltCoverWaveConditionsCalculation())) - { - // Call - bool closeForData = info.CloseForData(view, assessmentSection); - - // Assert - Assert.IsFalse(closeForData); - mocks.VerifyAll(); - } - } - - private static IView GetView(ICalculation data) - { - return new WaveConditionsInputView((ICalculation) data, - () => new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), - new WaveImpactAsphaltCoverWaveConditionsInputViewStyle()); - } - #endregion } } \ No newline at end of file