Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsWaveHeightLocationsView.cs =================================================================== diff -u -rf5bac1f11df4ee4881109371c50120763e303642 -r1b9d535d0b4f21bd0adb64184e5273d8bf691c4e --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsWaveHeightLocationsView.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsView.cs) (revision f5bac1f11df4ee4881109371c50120763e303642) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsWaveHeightLocationsView.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsView.cs) (revision 1b9d535d0b4f21bd0adb64184e5273d8bf691c4e) @@ -29,6 +29,7 @@ using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; using Ringtoets.GrassCoverErosionOutwards.Service.MessageProviders; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.GrassCoverErosionOutwards.Forms.Views { @@ -37,14 +38,19 @@ /// for the public class GrassCoverErosionOutwardsWaveHeightLocationsView : HydraulicBoundaryLocationsView { - private readonly Observer hydraulicBoundaryLocationObserver; + private readonly Observer assessmentSectionObserver; + private readonly Observer hydraulicBoundaryLocationsObserver; + private IAssessmentSection assessmentSection; + private GrassCoverErosionOutwardsFailureMechanism failureMechanism; + /// /// Creates a new instance of /// public GrassCoverErosionOutwardsWaveHeightLocationsView() { - hydraulicBoundaryLocationObserver = new Observer(UpdateHydraulicBoundaryLocations); + assessmentSectionObserver = new Observer(UpdateCalculateForSelectedButton); + hydraulicBoundaryLocationsObserver = new Observer(UpdateHydraulicBoundaryLocations); } public override object Data @@ -57,17 +63,39 @@ { var data = (ObservableList) value; base.Data = data; - hydraulicBoundaryLocationObserver.Observable = data; + hydraulicBoundaryLocationsObserver.Observable = data; } } - public override IAssessmentSection AssessmentSection { get; set; } + public override IAssessmentSection AssessmentSection + { + get + { + return assessmentSection; + } + set + { + assessmentSection = value; + assessmentSectionObserver.Observable = assessmentSection; + } + } /// /// Gets or sets the for which the /// hydraulic boundary locations are shown. /// - public GrassCoverErosionOutwardsFailureMechanism FailureMechanism { get; set; } + public GrassCoverErosionOutwardsFailureMechanism FailureMechanism + { + get + { + return failureMechanism; + } + set + { + failureMechanism = value; + UpdateCalculateForSelectedButton(); + } + } protected override WaveHeightLocationRow CreateNewRow(HydraulicBoundaryLocation location) { @@ -114,10 +142,21 @@ protected override void Dispose(bool disposing) { - hydraulicBoundaryLocationObserver.Dispose(); + assessmentSectionObserver.Dispose(); + hydraulicBoundaryLocationsObserver.Dispose(); base.Dispose(disposing); } + protected override string ValidateCalculatableObjects() + { + if (FailureMechanism != null && FailureMechanism.Contribution <= 0) + { + return RingtoetsCommonFormsResources.Contribution_of_failure_mechanism_zero; + } + + return base.ValidateCalculatableObjects(); + } + private void UpdateHydraulicBoundaryLocations() { if (IsDataGridDataSourceChanged()) Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs =================================================================== diff -u -rf5bac1f11df4ee4881109371c50120763e303642 -r1b9d535d0b4f21bd0adb64184e5273d8bf691c4e --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision f5bac1f11df4ee4881109371c50120763e303642) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision 1b9d535d0b4f21bd0adb64184e5273d8bf691c4e) @@ -52,18 +52,22 @@ private const int locationIdColumnIndex = 2; private const int locationColumnIndex = 3; private const int locationWaveHeightColumnIndex = 4; + private Form testForm; + private MockRepository mockRepository; [SetUp] public void Setup() { testForm = new Form(); + mockRepository = new MockRepository(); } [TearDown] public void TearDown() { testForm.Dispose(); + mockRepository.VerifyAll(); } [Test] @@ -279,7 +283,6 @@ var rows = dataGridView.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var mockRepository = new MockRepository(); var guiServiceMock = mockRepository.StrictMock(); var observer = mockRepository.StrictMock(); @@ -304,7 +307,8 @@ assessmentSectionStub.Stub(ass => ass.Id).Return(string.Empty); assessmentSectionStub.Stub(ass => ass.FailureMechanismContribution) .Return(new FailureMechanismContribution(Enumerable.Empty(), 1, 1)); - + assessmentSectionStub.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionStub.Stub(a => a.Detach(null)).IgnoreArguments(); mockRepository.ReplayAll(); view.AssessmentSection = assessmentSectionStub; @@ -327,7 +331,6 @@ Assert.IsTrue((bool) rows[0].Cells[locationCalculateColumnIndex].Value); Assert.IsFalse((bool) rows[1].Cells[locationCalculateColumnIndex].Value); Assert.IsFalse((bool) rows[2].Cells[locationCalculateColumnIndex].Value); - mockRepository.VerifyAll(); } [Test] Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs =================================================================== diff -u -re182f6f394aa75e739467a77e7bcacd9a8b25429 -r1b9d535d0b4f21bd0adb64184e5273d8bf691c4e --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs) (revision e182f6f394aa75e739467a77e7bcacd9a8b25429) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs) (revision 1b9d535d0b4f21bd0adb64184e5273d8bf691c4e) @@ -132,6 +132,8 @@ { new GrassCoverErosionOutwardsFailureMechanism() }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); mocks.ReplayAll(); using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) @@ -156,12 +158,12 @@ var mocks = new MockRepository(); var assessmentSectionA = mocks.Stub(); var assessmentSectionB = mocks.Stub(); - assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] { new GrassCoverErosionOutwardsFailureMechanism() }); - + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] { new GrassCoverErosionOutwardsFailureMechanism() @@ -193,6 +195,8 @@ { new GrassCoverErosionOutwardsFailureMechanism() }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); mocks.ReplayAll(); var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( @@ -221,11 +225,12 @@ var mocks = new MockRepository(); var assessmentSectionA = mocks.Stub(); var assessmentSectionB = mocks.Stub(); - assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] { new GrassCoverErosionOutwardsFailureMechanism() }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] { new GrassCoverErosionOutwardsFailureMechanism() @@ -256,18 +261,20 @@ { // Setup var mocks = new MockRepository(); - var assessmentSectionA = mocks.Stub(); - assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] { new GrassCoverErosionOutwardsFailureMechanism() }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); mocks.ReplayAll(); using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) using (var plugin = new GrassCoverErosionOutwardsPlugin()) { var info = GetInfo(plugin); - view.AssessmentSection = assessmentSectionA; + view.AssessmentSection = assessmentSection; // Call var closeForData = info.CloseForData(view, new object()); @@ -295,7 +302,7 @@ } } - private ViewInfo GetInfo(PluginBase plugin) + private static ViewInfo GetInfo(PluginBase plugin) { return plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(GrassCoverErosionOutwardsWaveHeightLocationsView)); }