Fisheye: Tag 6fa1bd13de71a612bbb0abcee6df366e7a318943 refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionContextProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionProperties.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionProperties.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/FailureMechanismContributionProperties.cs (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -0,0 +1,157 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.ComponentModel; +using Core.Common.Base; +using Core.Common.Gui.Attributes; +using Core.Common.Gui.PropertyBag; +using Core.Common.Utils; +using Core.Common.Utils.Attributes; +using Core.Common.Utils.Reflection; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Integration.Forms.Properties; +using Ringtoets.Integration.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Forms.PropertyClasses +{ + /// + /// ViewModel of for properties panel. + /// + public class FailureMechanismContributionProperties : ObjectProperties + { + private IFailureMechanismContributionNormChangeHandler normChangeHandler; + private IAssessmentSectionCompositionChangeHandler compositionChangeHandler; + + [TypeConverter(typeof(EnumTypeConverter))] + [ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_General")] + [ResourcesDisplayName(typeof(Resources), "FailureMechanismContribution_Composition_DisplayName")] + [ResourcesDescription(typeof(Resources), "FailureMechanismContribution_Composition_Description")] + public AssessmentSectionComposition AssessmentSectionComposition + { + get + { + return AssessmentSection.Composition; + } + set + { + if (compositionChangeHandler.ConfirmCompositionChange()) + { + IEnumerable changedObjects = compositionChangeHandler.ChangeComposition(AssessmentSection, value); + foreach (IObservable changedObject in changedObjects) + { + changedObject.NotifyObservers(); + } + + data.NotifyObservers(); + } + } + } + + [ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_General")] + [ResourcesDisplayName(typeof(Resources), "FailureMechanismContribution_ReturnPeriod_DisplayName")] + [ResourcesDescription(typeof(Resources), "FailureMechanismContribution_ReturnPeriod_Description")] + public int ReturnPeriod + { + get + { + return Convert.ToInt32(1.0/data.Norm); + } + set + { + if (value < 100 || value > 1000000) + { + throw new ArgumentOutOfRangeException("value", Resources.FailureMechanismContributionContextProperties_ReturnPeriod_Value_for_ReturnPeriod_Must_be_in_range_100_to_1000000); + } + + if (value != 0 && normChangeHandler.ConfirmNormChange()) + { + double newNormValue = 1.0/Convert.ToInt32(value); + IEnumerable changedObjects = normChangeHandler.ChangeNorm(AssessmentSection, newNormValue); + foreach (IObservable changedObject in changedObjects) + { + changedObject.NotifyObservers(); + } + } + } + } + + /// + /// Gets or sets the assessment section this property control belongs to. + /// + [DynamicVisible] + public IAssessmentSection AssessmentSection { get; set; } + + /// + /// Gets or sets the for when the norm changes. + /// + /// Thrown when nullis set. + [DynamicVisible] + public IFailureMechanismContributionNormChangeHandler NormChangeHandler + { + private get + { + return normChangeHandler; + } + set + { + if (value == null) + { + throw new ArgumentNullException("value", @"NormChangeHandler is null"); + } + normChangeHandler = value; + } + } + + /// + /// Gets or sets the for when the norm changes. + /// + /// Thrown when nullis set. + [DynamicVisible] + public IAssessmentSectionCompositionChangeHandler CompositionChangeHandler + { + private get + { + return compositionChangeHandler; + } + set + { + if (value == null) + { + throw new ArgumentNullException("value", @"CompositionChangeHandler is null"); + } + compositionChangeHandler = value; + } + } + + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + // Hide all the properties that are used to set the data + return propertyName != TypeUtils.GetMemberName(p => p.AssessmentSection) + && propertyName != TypeUtils.GetMemberName(p => p.NormChangeHandler) + && propertyName != TypeUtils.GetMemberName(p => p.CompositionChangeHandler); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r1ddd0ecb63ccdcb00ce2f1f757ba5e0c64a5fb90 -r6fa1bd13de71a612bbb0abcee6df366e7a318943 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 1ddd0ecb63ccdcb00ce2f1f757ba5e0c64a5fb90) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -58,7 +58,7 @@ - + Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs =================================================================== diff -u -r2024fc0233ddd151281ad3fec5d7cddcb147b444 -r6fa1bd13de71a612bbb0abcee6df366e7a318943 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 2024fc0233ddd151281ad3fec5d7cddcb147b444) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -30,9 +30,7 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; -using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; using CommonGuiResources = Core.Common.Gui.Properties.Resources; -using RingtoetsGrassCoverErosionOutwardsFormsResources = Ringtoets.GrassCoverErosionOutwards.Forms.Properties.Resources; using RingtoetsIntegrationFormsResources = Ringtoets.Integration.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.Views Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r65eb603f0c22966e05487433a9deb80e3041fc47 -r6fa1bd13de71a612bbb0abcee6df366e7a318943 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 65eb603f0c22966e05487433a9deb80e3041fc47) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -270,7 +270,7 @@ yield return new PropertyInfo(); yield return new PropertyInfo(); yield return new PropertyInfo(); - yield return new PropertyInfo() + yield return new PropertyInfo() { GetObjectPropertiesData = context => context.WrappedData, AfterCreate = (properties, context) => Fisheye: Tag 6fa1bd13de71a612bbb0abcee6df366e7a318943 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionContextPropertiesIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionPropertiesIntegrationTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionPropertiesIntegrationTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionPropertiesIntegrationTest.cs (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -0,0 +1,579 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Core.Common.Base; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Forms.PropertyClasses; +using Ringtoets.Integration.Plugin.Handlers; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.KernelWrapper.TestUtil; + +namespace Ringtoets.Integration.Forms.Test +{ + [TestFixture] + public class FailureMechanismContributionPropertiesIntegrationTest : NUnitFormTest + { + private const string messageAllHydraulicBoundaryLocationOutputCleared = + "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd."; + + private const string messageCalculationsremoved = "De resultaten van {0} berekeningen zijn verwijderd."; + + [Test] + public void ReturnPeriodProperty_ValueChanged_ClearsDependentDataAndNotifiesObserversAndLogsMessages() + { + // Setup + const int newReturnPeriod = 200; + const int numberOfCalculations = 3; + + var hydraulicBoundaryLocation = TestHydraulicBoundaryLocation.CreateFullyCalculated(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + Locations = + { + hydraulicBoundaryLocation + } + }; + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase + }; + + var emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + var pipingCalculation = new PipingCalculation(new GeneralPipingInput()) + { + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() + }; + var emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + var grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), + new TestDikeHeightAssessmentOutput(0)) + }; + var emptyHeightStructuresCalculation = new StructuresCalculation(); + var heightStructuresCalculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + var grassCoverErosionOutwardsHydraulicBoundaryLocation = hydraulicBoundaryLocation; + grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeightOutput = new TestHydraulicBoundaryLocationOutput( + hydraulicBoundaryLocation.WaveHeight); + grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput( + hydraulicBoundaryLocation.DesignWaterLevel); + + assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Add(grassCoverErosionOutwardsHydraulicBoundaryLocation); + + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(pipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(grassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); + + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + MockRepository mockRepository = new MockRepository(); + IObserver observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + IObserver pipingCalculationObserver = mockRepository.StrictMock(); + pipingCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver grassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); + grassCoverErosionInwardsCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver heightStructuresCalculationObserver = mockRepository.StrictMock(); + heightStructuresCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver emptyPipingCalculationObserver = mockRepository.StrictMock(); + IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); + IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock(); + + IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); + hydraulicBoundaryDatabaseObserver.Expect(hbdo => hbdo.UpdateObserver()); + IObserver grassCoverErosionOutwardsObserver = mockRepository.StrictMock(); + grassCoverErosionOutwardsObserver.Expect(o => o.UpdateObserver()); + mockRepository.ReplayAll(); + + failureMechanismContribution.Attach(observerMock); + hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver); + + emptyPipingCalculation.Attach(emptyPipingCalculationObserver); + emptyGrassCoverErosionInwardsCalculation.Attach(emptyGrassCoverErosionInwardsCalculationObserver); + emptyHeightStructuresCalculation.Attach(emptyHeightStructuresCalculationObserver); + + pipingCalculation.Attach(pipingCalculationObserver); + grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver); + heightStructuresCalculation.Attach(heightStructuresCalculationObserver); + + assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserver); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = new FailureMechanismContributionNormChangeHandler() + }; + + // Precondition + int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); + Assert.AreEqual(originalReturnPeriodValue, properties.ReturnPeriod); + Assert.IsFalse(double.IsNaN(hydraulicBoundaryLocation.WaveHeight)); + Assert.IsFalse(double.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel)); + Assert.IsFalse(double.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight)); + Assert.IsFalse(double.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel)); + Assert.IsNotNull(pipingCalculation.Output); + Assert.IsNotNull(pipingCalculation.SemiProbabilisticOutput); + Assert.IsNotNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNotNull(heightStructuresCalculation.Output); + + DialogBoxHandler = (name, wnd) => + { + var dialogTester = new MessageBoxTester(wnd); + dialogTester.ClickOk(); + }; + + // Call + Action call = () => properties.ReturnPeriod = newReturnPeriod; + + // Assert + TestHelper.AssertLogMessages(call, msgs => + { + string[] messages = msgs.ToArray(); + Assert.AreEqual(string.Format(messageCalculationsremoved, numberOfCalculations), messages[0]); + Assert.AreEqual(messageAllHydraulicBoundaryLocationOutputCleared, messages[1]); + }); + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); + Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); + Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight); + Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel); + Assert.IsNull(pipingCalculation.Output); + Assert.IsNull(pipingCalculation.SemiProbabilisticOutput); + Assert.IsNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNull(heightStructuresCalculation.Output); + + mockRepository.VerifyAll(); + } + + [Test] + public void ReturnPeriodProperty_HydraulicBoundarySetAndCalculationsNoOutput_HydraulicBoundaryDatabaseObserversNotifiedAndMessagesLogged() + { + // Setup + const int newReturnPeriod = 200; + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + Locations = + { + TestHydraulicBoundaryLocation.CreateFullyCalculated() + } + }; + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase + }; + + var emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + var emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + var emptyHeightStructuresCalculation = new StructuresCalculation(); + + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + var mockRepository = new MockRepository(); + IObserver observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + IObserver calculationObserver = mockRepository.StrictMock(); // No update observers expected. + IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); + hydraulicBoundaryDatabaseObserver.Expect(hbdo => hbdo.UpdateObserver()); + mockRepository.ReplayAll(); + + failureMechanismContribution.Attach(observerMock); + hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver); + + emptyPipingCalculation.Attach(calculationObserver); + emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver); + emptyHeightStructuresCalculation.Attach(calculationObserver); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = new FailureMechanismContributionNormChangeHandler() + }; + + HydraulicBoundaryLocation hydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations[0]; + + // Precondition + int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); + Assert.AreEqual(originalReturnPeriodValue, properties.ReturnPeriod); + Assert.IsFalse(double.IsNaN(hydraulicBoundaryLocation.WaveHeight)); + Assert.IsFalse(double.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel)); + + DialogBoxHandler = (name, wnd) => + { + var dialogTester = new MessageBoxTester(wnd); + dialogTester.ClickOk(); + }; + + // Call + Action call = () => properties.ReturnPeriod = newReturnPeriod; + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, messageAllHydraulicBoundaryLocationOutputCleared, 1); + + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); + Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); + + mockRepository.VerifyAll(); + } + + [Test] + public void ReturnPeriodProperty_HydraulicBoundaryLocationNoOutputAndCalculationWithOutputAndValueChanged_CalculationObserverNotifiedAndMessageLogged() + { + // Setup + const int newReturnPeriod = 200; + const int numberOfCalculations = 3; + + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase.Locations.Add(new TestHydraulicBoundaryLocation()); + + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase + }; + + PipingCalculation emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + PipingCalculation pipingCalculation = new PipingCalculation(new GeneralPipingInput()) + { + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() + }; + GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + GrassCoverErosionInwardsCalculation grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), + new TestDikeHeightAssessmentOutput(0)) + }; + var emptyHeightStructuresCalculation = new StructuresCalculation(); + var heightStructuresCalculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(pipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(grassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); + + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + MockRepository mockRepository = new MockRepository(); + IObserver observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + IObserver pipingCalculationObserver = mockRepository.StrictMock(); + pipingCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver grassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); + grassCoverErosionInwardsCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver heightStructuresCalculationObserver = mockRepository.StrictMock(); + heightStructuresCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver emptyPipingCalculationObserver = mockRepository.StrictMock(); + IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); + IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock(); + + IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); // No update observer expected. + mockRepository.ReplayAll(); + + failureMechanismContribution.Attach(observerMock); + hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver); + + emptyPipingCalculation.Attach(emptyPipingCalculationObserver); + emptyGrassCoverErosionInwardsCalculation.Attach(emptyGrassCoverErosionInwardsCalculationObserver); + emptyHeightStructuresCalculation.Attach(emptyHeightStructuresCalculationObserver); + + pipingCalculation.Attach(pipingCalculationObserver); + grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver); + heightStructuresCalculation.Attach(heightStructuresCalculationObserver); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = new FailureMechanismContributionNormChangeHandler() + }; + + // Precondition + int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); + Assert.AreEqual(originalReturnPeriodValue, properties.ReturnPeriod); + Assert.IsNotNull(pipingCalculation.Output); + Assert.IsNotNull(pipingCalculation.SemiProbabilisticOutput); + Assert.IsNotNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNotNull(heightStructuresCalculation.Output); + + DialogBoxHandler = (name, wnd) => + { + var dialogTester = new MessageBoxTester(wnd); + dialogTester.ClickOk(); + }; + + // Call + Action call = () => properties.ReturnPeriod = newReturnPeriod; + + // Assert + string expectedMessage = string.Format(messageCalculationsremoved, + numberOfCalculations); + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + Assert.IsNull(pipingCalculation.Output); + Assert.IsNull(pipingCalculation.SemiProbabilisticOutput); + Assert.IsNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNull(heightStructuresCalculation.Output); + + mockRepository.VerifyAll(); + } + + [Test] + public void ReturnPeriodProperty_NoHydraulicBoundaryLocationNoOutputAndCalculationWithOutputAndValueChanged_CalculationObserverNotifiedAndMessageLogged() + { + // Setup + const int newReturnPeriod = 200; + const int numberOfCalculations = 3; + + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + + PipingCalculation emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + PipingCalculation pipingCalculation = new PipingCalculation(new GeneralPipingInput()) + { + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() + }; + GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + GrassCoverErosionInwardsCalculation grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), + new TestDikeHeightAssessmentOutput(0)) + }; + var emptyHeightStructuresCalculation = new StructuresCalculation(); + var heightStructuresCalculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(pipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(grassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); + + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + MockRepository mockRepository = new MockRepository(); + IObserver observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + IObserver pipingCalculationObserver = mockRepository.StrictMock(); + pipingCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver grassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); + grassCoverErosionInwardsCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver heightStructuresCalculationObserver = mockRepository.StrictMock(); + heightStructuresCalculationObserver.Expect(o => o.UpdateObserver()); + IObserver emptyPipingCalculationObserver = mockRepository.StrictMock(); + IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); + IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock(); + + mockRepository.ReplayAll(); + + failureMechanismContribution.Attach(observerMock); + + emptyPipingCalculation.Attach(emptyPipingCalculationObserver); + emptyGrassCoverErosionInwardsCalculation.Attach(emptyGrassCoverErosionInwardsCalculationObserver); + emptyHeightStructuresCalculation.Attach(emptyHeightStructuresCalculationObserver); + + pipingCalculation.Attach(pipingCalculationObserver); + grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver); + heightStructuresCalculation.Attach(heightStructuresCalculationObserver); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = new FailureMechanismContributionNormChangeHandler() + }; + + // Precondition + int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); + Assert.AreEqual(originalReturnPeriodValue, properties.ReturnPeriod); + Assert.IsNotNull(pipingCalculation.Output); + Assert.IsNotNull(pipingCalculation.SemiProbabilisticOutput); + Assert.IsNotNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNotNull(heightStructuresCalculation.Output); + + DialogBoxHandler = (name, wnd) => + { + var dialogTester = new MessageBoxTester(wnd); + dialogTester.ClickOk(); + }; + + // Call + Action call = () => properties.ReturnPeriod = newReturnPeriod; + + // Assert + string expectedMessage = string.Format(messageCalculationsremoved, + numberOfCalculations); + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + Assert.IsNull(pipingCalculation.Output); + Assert.IsNull(pipingCalculation.SemiProbabilisticOutput); + Assert.IsNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNull(heightStructuresCalculation.Output); + + mockRepository.VerifyAll(); + } + + [Test] + public void ReturnPeriodProperty_HydraulicBoundaryLocationNoOutputAndNoCalculationsWithOutputAndValueChanged_NoObserversNotifiedAndMessagesLogged() + { + // Setup + const int newReturnPeriod = 200; + + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase.Locations.Add(new TestHydraulicBoundaryLocation()); + + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase + }; + + PipingCalculation emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + var emptyHeightStructuresCalculation = new StructuresCalculation(); + + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + MockRepository mockRepository = new MockRepository(); + IObserver observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + IObserver calculationObserver = mockRepository.StrictMock(); + IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + failureMechanismContribution.Attach(observerMock); + emptyPipingCalculation.Attach(calculationObserver); + emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver); + emptyHeightStructuresCalculation.Attach(calculationObserver); + hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = new FailureMechanismContributionNormChangeHandler() + }; + + // Precondition + int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); + Assert.AreEqual(originalReturnPeriodValue, properties.ReturnPeriod); + + DialogBoxHandler = (name, wnd) => + { + var dialogTester = new MessageBoxTester(wnd); + dialogTester.ClickOk(); + }; + + // Call + Action call = () => properties.ReturnPeriod = newReturnPeriod; + + // Assert + TestHelper.AssertLogMessagesCount(call, 0); + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + + mockRepository.VerifyAll(); // No update observer expected. + } + + [Test] + public void ReturnPeriodProperty_NoHydraulicBoundaryDatabaseAndNoCalculationsWithOutputAndValueChanged_NoObserversNotifiedAndMessagesLogged() + { + // Setup + const int newReturnPeriod = 200; + + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + + PipingCalculation emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + var emptyHeightStructuresCalculation = new StructuresCalculation(); + + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = new FailureMechanismContributionNormChangeHandler() + }; + + // Precondition + int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); + Assert.AreEqual(originalReturnPeriodValue, properties.ReturnPeriod); + + // Call + failureMechanismContribution.Norm = 1.0/newReturnPeriod; + Action call = () => failureMechanismContribution.NotifyObservers(); + + // Assert + TestHelper.AssertLogMessagesCount(call, 0); + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs =================================================================== diff -u -r2024fc0233ddd151281ad3fec5d7cddcb147b444 -r6fa1bd13de71a612bbb0abcee6df366e7a318943 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 2024fc0233ddd151281ad3fec5d7cddcb147b444) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -98,7 +98,7 @@ mocks.VerifyAll(); } - private void AssertDataGridViewDataSource(IEnumerable expectedDistributionElements, DataGridView dataGridView) + private static void AssertDataGridViewDataSource(IEnumerable expectedDistributionElements, DataGridView dataGridView) { FailureMechanismContributionItem[] itemArray = expectedDistributionElements.ToArray(); Assert.AreEqual(itemArray.Length, dataGridView.RowCount); Fisheye: Tag 6fa1bd13de71a612bbb0abcee6df366e7a318943 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionContextPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/FailureMechanismContributionPropertiesTest.cs (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -0,0 +1,430 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.ComponentModel; +using System.Linq; +using Core.Common.Base; +using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Forms.PropertyClasses; +using Ringtoets.Integration.Forms.Views; +using Ringtoets.Integration.Plugin.Handlers; + +namespace Ringtoets.Integration.Forms.Test.PropertyClasses +{ + [TestFixture] + public class FailureMechanismContributionPropertiesTest : NUnitFormTest + { + [Test] + public void DefaultConstructor_ExpectedValues() + { + // Call + var properties = new FailureMechanismContributionProperties(); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.IsNull(properties.Data); + } + + [Test] + public void Constructor_Always_PropertiesHaveExpectedAttributeValues() + { + // Call + var failureMechanismContributionProperties = new FailureMechanismContributionProperties(); + + // Assert + var dynamicPropertyBag = new DynamicPropertyBag(failureMechanismContributionProperties); + PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] + { + new BrowsableAttribute(true) + }); + + Assert.AreEqual(2, dynamicProperties.Count); + + var expectedCategory = "Algemeen"; + + PropertyDescriptor compositionProperty = dynamicProperties[0]; + Assert.IsNotNull(compositionProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(compositionProperty, + expectedCategory, + "Trajecttype", + "Selecteer het type traject, bepalend voor de faalkansbegroting."); + + PropertyDescriptor returnPeriodProperty = dynamicProperties[1]; + Assert.IsNotNull(returnPeriodProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(returnPeriodProperty, + expectedCategory, + "Norm (terugkeertijd) [jaar]", + "Terugkeertijd van de norm, gelijk aan 1/norm."); + } + + [Test] + public void GetProperties_WithData_ReturnExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionComposition = AssessmentSectionComposition.DikeAndDune; + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(section => section.Composition).Return(assessmentSectionComposition); + mocks.ReplayAll(); + + int returnPeriod = 30000; + var failureMechanisms = Enumerable.Empty(); + var contribution = new FailureMechanismContribution(failureMechanisms, 1.1, 1.0/returnPeriod); + + var properties = new FailureMechanismContributionProperties + { + Data = contribution, + AssessmentSection = assessmentSection + }; + + // Call + int returnPeriodPropertyValue = properties.ReturnPeriod; + AssessmentSectionComposition compositionPropertyValue = properties.AssessmentSectionComposition; + + // Assert + Assert.AreEqual(returnPeriod, returnPeriodPropertyValue); + Assert.AreEqual(assessmentSectionComposition, compositionPropertyValue); + mocks.VerifyAll(); + } + + [Test] + public void NormChangeHandler_SetNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new FailureMechanismContributionProperties + { + NormChangeHandler = null + }; + + // Assert + ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "NormChangeHandler is null"); + string paramName = exception.ParamName; + Assert.AreEqual("value", paramName); + } + + [Test] + public void CompositionChangeHandler_SetNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new FailureMechanismContributionProperties + { + CompositionChangeHandler = null + }; + + // Assert + ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "CompositionChangeHandler is null"); + string paramName = exception.ParamName; + Assert.AreEqual("value", paramName); + } + + [Test] + public void GivenReturnPeriod_WhenConfirmingReturnPeriodValueChange_ReturnPeriodSetAndNotifiesObserver() + { + // Given + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + var normChangeHandler = new FailureMechanismContributionNormChangeHandler(); + + var mocks = new MockRepository(); + var compositionChangeHandler = mocks.Stub(); + mocks.ReplayAll(); + + var observer = mocks.StrictMock(); + failureMechanismContribution.Attach(observer); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = normChangeHandler, + CompositionChangeHandler = compositionChangeHandler + }; + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + messageBox.ClickOk(); + }; + + // When + const int newReturnPeriod = 200; + properties.ReturnPeriod = newReturnPeriod; + + // Then + Assert.AreEqual(newReturnPeriod, properties.ReturnPeriod); + Assert.AreEqual(1.0/newReturnPeriod, failureMechanismContribution.Norm); + mocks.VerifyAll(); + } + + [Test] + public void GivenReturnPeriod_WhenCancellingReturnPeriodValueChange_NothingHappens() + { + // Given + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + int originalReturnPeriod = Convert.ToInt32(1/failureMechanismContribution.Norm); + + var normChangeHandler = new FailureMechanismContributionNormChangeHandler(); + + var mocks = new MockRepository(); + var compositionChangeHandler = mocks.Stub(); + mocks.ReplayAll(); + + var observer = mocks.StrictMock(); + failureMechanismContribution.Attach(observer); + mocks.ReplayAll(); + + var properties = new FailureMechanismContributionProperties + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = normChangeHandler, + CompositionChangeHandler = compositionChangeHandler + }; + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + messageBox.ClickCancel(); + }; + + // When + const int newReturnPeriod = 200; + properties.ReturnPeriod = newReturnPeriod; + + // Then + Assert.AreEqual(originalReturnPeriod, properties.ReturnPeriod); + Assert.AreEqual(1.0/originalReturnPeriod, failureMechanismContribution.Norm); + mocks.VerifyAll(); + } + + [Test] + public void GivenAssessmentSectionComposition_WhenConfirmingCompositionValueChange_AssessmentSectionCompositionSetAndNotifiesObserver() + { + // Given + const AssessmentSectionComposition originalComposition = AssessmentSectionComposition.Dike; + AssessmentSection assessmentSection = new AssessmentSection(originalComposition); + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + var compositionChangeHandler = new AssessmentSectionCompositionChangeHandler(); + + var mocks = new MockRepository(); + var normChangeHandler = mocks.Stub(); + + var observer = mocks.StrictMock(); + failureMechanismContribution.Attach(observer); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var properties = new FailureMechanismContributionProperties() + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = normChangeHandler, + CompositionChangeHandler = compositionChangeHandler + }; + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + messageBox.ClickOk(); + }; + + // When + const AssessmentSectionComposition newComposition = AssessmentSectionComposition.DikeAndDune; + properties.AssessmentSectionComposition = newComposition; + + // Then + Assert.AreEqual(newComposition, properties.AssessmentSectionComposition); + Assert.AreEqual(newComposition, assessmentSection.Composition); + mocks.VerifyAll(); + } + + [Test] + public void GivenAssessmentSectionComposition_WhenCancellingCompositionValueChange_NothingHappens() + { + // Given + const AssessmentSectionComposition originalComposition = AssessmentSectionComposition.Dike; + AssessmentSection assessmentSection = new AssessmentSection(originalComposition); + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + + var compositionChangeHandler = new AssessmentSectionCompositionChangeHandler(); + + var mocks = new MockRepository(); + var normChangeHandler = mocks.Stub(); + + var observer = mocks.StrictMock(); + failureMechanismContribution.Attach(observer); + mocks.ReplayAll(); + + var properties = new FailureMechanismContributionProperties() + { + Data = failureMechanismContribution, + AssessmentSection = assessmentSection, + NormChangeHandler = normChangeHandler, + CompositionChangeHandler = compositionChangeHandler + }; + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + messageBox.ClickCancel(); + }; + + // When + const AssessmentSectionComposition newComposition = AssessmentSectionComposition.DikeAndDune; + properties.AssessmentSectionComposition = newComposition; + + // Then + Assert.AreEqual(originalComposition, properties.AssessmentSectionComposition); + Assert.AreEqual(originalComposition, assessmentSection.Composition); + mocks.VerifyAll(); + } + + [Test] + public void ReturnPeriod_ValueChanges_NotifiesChangedObjectsInAssessmentSection() + { + // Setup + const int returnPeriod = 200; + const double norm = 1.0/returnPeriod; + + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + + var mocks = new MockRepository(); + var observable1 = mocks.StrictMock(); + observable1.Expect(o => o.NotifyObservers()); + var observable2 = mocks.StrictMock(); + observable2.Expect(o => o.NotifyObservers()); + + var normChangeHandler = mocks.StrictMock(); + normChangeHandler.Expect(h => h.ConfirmNormChange()).Return(true); + normChangeHandler.Expect(h => h.ChangeNorm(assessmentSection, norm)) + .Return(new[] + { + observable1, + observable2 + }); + mocks.ReplayAll(); + + var properties = new FailureMechanismContributionProperties + { + AssessmentSection = assessmentSection, + NormChangeHandler = normChangeHandler, + Data = assessmentSection.FailureMechanismContribution + }; + + // Call + properties.ReturnPeriod = returnPeriod; + + // Assert + mocks.VerifyAll(); + } + + [Test] + [TestCase(int.MinValue)] + [TestCase(int.MaxValue)] + [TestCase(99)] + [TestCase(1000001)] + public void ReturnPeriod_InvalidValue_ThrowsArgumentOutOfRangeException(int invalidReturnPeriod) + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionComposition = AssessmentSectionComposition.DikeAndDune; + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(section => section.Composition).Return(assessmentSectionComposition); + mocks.ReplayAll(); + + var failureMechanisms = Enumerable.Empty(); + var contribution = new FailureMechanismContribution(failureMechanisms, 1.1, 1.0/200); + + var properties = new FailureMechanismContributionProperties() + { + Data = contribution, + AssessmentSection = assessmentSection + }; + + // Call + TestDelegate call = () => properties.ReturnPeriod = invalidReturnPeriod; + + // Assert + string expectedMessage = "De waarde voor de 'Norm (terugkeertijd)' moet in het bereik [100, 1000000] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + [TestCase(AssessmentSectionComposition.Dike, AssessmentSectionComposition.Dune)] + [TestCase(AssessmentSectionComposition.Dike, AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.Dune, AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.Dune, AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dune)] + public void AssessmentSectionComposition_CompositionValueChanges_NotifiesChangedObjectsInAssessmentSection( + AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition) + { + // Setup + var assessmentSection = new AssessmentSection(initialComposition); + + var mocks = new MockRepository(); + var observable1 = mocks.StrictMock(); + observable1.Expect(o => o.NotifyObservers()); + var observable2 = mocks.StrictMock(); + observable2.Expect(o => o.NotifyObservers()); + + var compositionChangeHandler = mocks.StrictMock(); + compositionChangeHandler.Expect(h => h.ConfirmCompositionChange()) + .Return(true); + compositionChangeHandler.Expect(h => h.ChangeComposition(assessmentSection, newComposition)) + .Return(new[] + { + observable1, + observable2 + }); + mocks.ReplayAll(); + + var properties = new FailureMechanismContributionProperties + { + AssessmentSection = assessmentSection, + CompositionChangeHandler = compositionChangeHandler, + Data = assessmentSection.FailureMechanismContribution + }; + + // Call + properties.AssessmentSectionComposition = newComposition; + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r65eb603f0c22966e05487433a9deb80e3041fc47 -r6fa1bd13de71a612bbb0abcee6df366e7a318943 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 65eb603f0c22966e05487433a9deb80e3041fc47) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -72,7 +72,7 @@ - + @@ -84,7 +84,7 @@ - + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -rc18f1b5eca111867195ebedf813fae22a12ce793 -r6fa1bd13de71a612bbb0abcee6df366e7a318943 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision c18f1b5eca111867195ebedf813fae22a12ce793) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 6fa1bd13de71a612bbb0abcee6df366e7a318943) @@ -229,7 +229,7 @@ PropertyInfo failureMechanismContributionProperties = PluginTestHelper.AssertPropertyInfoDefined( propertyInfos, typeof(FailureMechanismContributionContext), - typeof(FailureMechanismContributionContextProperties)); + typeof(FailureMechanismContributionProperties)); Assert.IsNull(failureMechanismContributionProperties.AdditionalDataCheck); Assert.IsNotNull(failureMechanismContributionProperties.GetObjectPropertiesData); Assert.IsNotNull(failureMechanismContributionProperties.AfterCreate);