Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs =================================================================== diff -u -r75443ac72bf8b348e362dbf4b40f535495f6b2b3 -r6ad24145747b52bf9b7d886e79767ddaa406e79b --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision 75443ac72bf8b348e362dbf4b40f535495f6b2b3) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision 6ad24145747b52bf9b7d886e79767ddaa406e79b) @@ -21,33 +21,233 @@ using System; using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.Gui.PropertyBag; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.UITypeEditors; +using Ringtoets.HydraRing.Data; namespace Ringtoets.Common.Forms.Test.PropertyClasses { [TestFixture] public class StructuresInputBasePropertiesTest { + private MockRepository mockRepository; + + [SetUp] + public void SetUp() + { + mockRepository = new MockRepository(); + } + [Test] public void Constructor_ExpectedValues() { // Call var properties = new SimpleStructuresInputProperties(new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties()); // Assert - Assert.IsInstanceOf, IFailureMechanism>>(properties); + Assert.IsInstanceOf, IFailureMechanism>>>(properties); + Assert.IsInstanceOf(properties); + Assert.IsInstanceOf>(properties); + Assert.IsInstanceOf(properties); Assert.IsNull(properties.Data); } + [Test] + public void Constructor_ConstructionPropertiesIsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new SimpleStructuresInputProperties(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("constructionProperties", paramName); + } + + [Test] + public void Data_SetNewInputContextInstance_ReturnCorrectPropertyValues() + { + // Setup + var assessmentSectionStub = mockRepository.Stub(); + var failureMechanismStub = mockRepository.Stub(); + + mockRepository.ReplayAll(); + + var calculation = new StructuresCalculation(); + var properties = new SimpleStructuresInputProperties(new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties()); + var inputContext = new SimpleInputContext(calculation.InputParameters, + calculation, + failureMechanismStub, + assessmentSectionStub); + + // Call + properties.Data = inputContext; + + // Assert + SimpleStructureInput input = calculation.InputParameters; + var expectedFailureProbabilityStructureWithErosion = ProbabilityFormattingHelper.Format(input.FailureProbabilityStructureWithErosion); + + Assert.IsNull(properties.Structure); + Assert.IsNull(properties.StructureLocation); + Assert.AreSame(input.ModelFactorSuperCriticalFlow, properties.ModelFactorSuperCriticalFlow.Data); + Assert.AreEqual(input.StructureNormalOrientation, properties.StructureNormalOrientation); + Assert.AreSame(input.AllowedLevelIncreaseStorage, properties.AllowedLevelIncreaseStorage.Data); + Assert.AreSame(input.StorageStructureArea, properties.StorageStructureArea.Data); + Assert.AreSame(input.FlowWidthAtBottomProtection, properties.FlowWidthAtBottomProtection.Data); + Assert.AreSame(input.WidthFlowApertures, properties.WidthFlowApertures.Data); + Assert.AreSame(input.CriticalOvertoppingDischarge, properties.CriticalOvertoppingDischarge.Data); + Assert.IsNull(properties.ForeshoreProfile); + Assert.IsInstanceOf(properties.UseBreakWater); + Assert.IsInstanceOf(properties.UseForeshore); + Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); + Assert.AreSame(input.HydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); + Assert.AreSame(input.StormDuration, properties.StormDuration.Data); + + mockRepository.VerifyAll(); + } + + [Test] + public void Data_SetNewInputContextInstanceWithData_ReturnCorrectPropertyValues() + { + // Setup + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + Locations = + { + new HydraulicBoundaryLocation(0, "", 0, 0) + } + }; + var assessmentSectionStub = mockRepository.Stub(); + var failureMechanismStub = mockRepository.Stub(); + + assessmentSectionStub.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + mockRepository.ReplayAll(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new SimpleStructure() + } + }; + var properties = new SimpleStructuresInputProperties(new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties()); + var inputContext = new SimpleInputContext(calculation.InputParameters, + calculation, + failureMechanismStub, + assessmentSectionStub); + + // Call + properties.Data = inputContext; + + // Assert + SimpleStructureInput input = calculation.InputParameters; + var expectedStructureLocation = new Point2D(new RoundedDouble(0, input.Structure.Location.X), new RoundedDouble(0, input.Structure.Location.Y)); + var expectedFailureProbabilityStructureWithErosion = ProbabilityFormattingHelper.Format(input.FailureProbabilityStructureWithErosion); + + Assert.AreSame(input.Structure, properties.Structure); + Assert.AreEqual(expectedStructureLocation, properties.StructureLocation); + Assert.AreSame(input.ModelFactorSuperCriticalFlow, properties.ModelFactorSuperCriticalFlow.Data); + Assert.AreEqual(input.StructureNormalOrientation, properties.StructureNormalOrientation); + Assert.AreSame(input.AllowedLevelIncreaseStorage, properties.AllowedLevelIncreaseStorage.Data); + Assert.AreSame(input.StorageStructureArea, properties.StorageStructureArea.Data); + Assert.AreSame(input.FlowWidthAtBottomProtection, properties.FlowWidthAtBottomProtection.Data); + Assert.AreSame(input.WidthFlowApertures, properties.WidthFlowApertures.Data); + Assert.AreSame(input.CriticalOvertoppingDischarge, properties.CriticalOvertoppingDischarge.Data); + Assert.AreSame(input.ForeshoreProfile, properties.ForeshoreProfile); + Assert.IsInstanceOf(properties.UseBreakWater); + Assert.IsInstanceOf(properties.UseForeshore); + Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); + Assert.AreSame(input.HydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); + Assert.AreSame(input.StormDuration, properties.StormDuration.Data); + + Assert.AreEqual(1, properties.GetAvailableHydraulicBoundaryLocations().Count()); + CollectionAssert.AreEqual(inputContext.AvailableHydraulicBoundaryLocations, properties.GetAvailableHydraulicBoundaryLocations()); + + mockRepository.VerifyAll(); + } + + [Test] + public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() + { + // Setup + const int numberOfChangedProperties = 5; + var observerMock = mockRepository.StrictMock(); + var assessmentSectionStub = mockRepository.Stub(); + var failureMechanismStub = mockRepository.Stub(); + + observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties); + + mockRepository.ReplayAll(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new SimpleStructure() + } + }; + var inputContext = new SimpleInputContext(calculation.InputParameters, + calculation, + failureMechanismStub, + assessmentSectionStub); + var properties = new SimpleStructuresInputProperties(new StructuresInputBaseProperties, IFailureMechanism>.ConstructionProperties()) + { + Data = inputContext + }; + + inputContext.Attach(observerMock); + + var random = new Random(100); + double newStructureNormalOrientation = random.NextDouble(); + var newStructure = new SimpleStructure(); + ForeshoreProfile newForeshoreProfile = CreateForeshoreProfile(); + HydraulicBoundaryLocation newHydraulicBoundaryLocation = CreateHydraulicBoundaryLocation(); + + // Call + properties.Structure = newStructure; + properties.StructureNormalOrientation = (RoundedDouble) newStructureNormalOrientation; + properties.FailureProbabilityStructureWithErosion = "1e-2"; + properties.HydraulicBoundaryLocation = newHydraulicBoundaryLocation; + properties.ForeshoreProfile = newForeshoreProfile; + + // Assert + Assert.AreSame(newStructure, properties.Structure); + Assert.AreEqual(newStructureNormalOrientation, properties.StructureNormalOrientation, properties.StructureNormalOrientation.GetAccuracy()); + Assert.AreEqual(0.01, inputContext.WrappedData.FailureProbabilityStructureWithErosion); + Assert.AreEqual("1/100", properties.FailureProbabilityStructureWithErosion); + Assert.AreSame(newHydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); + Assert.AreSame(newForeshoreProfile, properties.ForeshoreProfile); + mockRepository.VerifyAll(); + } + + private static HydraulicBoundaryLocation CreateHydraulicBoundaryLocation() + { + return new HydraulicBoundaryLocation(0, "", 0, 0); + } + + private static ForeshoreProfile CreateForeshoreProfile() + { + return new ForeshoreProfile(new Point2D(0, 0), Enumerable.Empty(), null, new ForeshoreProfile.ConstructionProperties()); + } + private class SimpleStructure : StructureBase { - public SimpleStructure() : base("Name", "Id", new Point2D(0, 0), 0.0) { } + public SimpleStructure() : base("Name", "Id", new Point2D(0, 0), 0.0) {} } private class SimpleStructureInput : StructuresInputBase @@ -61,18 +261,21 @@ public override IEnumerable GetAvailableForeshoreProfiles() { - throw new NotImplementedException(); + yield return CreateForeshoreProfile(); } public override IEnumerable GetAvailableStructures() { - throw new NotImplementedException(); + yield return new SimpleStructure(); } - protected override void AfterSettingStructure() - { - throw new NotImplementedException(); - } + protected override void AfterSettingStructure() {} } + + private class SimpleInputContext : InputContextBase, IFailureMechanism> + { + public SimpleInputContext(SimpleStructureInput wrappedData, StructuresCalculation calculation, IFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + : base(wrappedData, calculation, failureMechanism, assessmentSection) {} + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs =================================================================== diff -u -r75443ac72bf8b348e362dbf4b40f535495f6b2b3 -r6ad24145747b52bf9b7d886e79767ddaa406e79b --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision 75443ac72bf8b348e362dbf4b40f535495f6b2b3) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision 6ad24145747b52bf9b7d886e79767ddaa406e79b) @@ -35,7 +35,6 @@ using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Data.TestUtil; @@ -89,7 +88,7 @@ public void Data_SetNewInputContextInstance_ReturnCorrectPropertyValues() { // Setup - var assessmentSectionMock = mockRepository.StrictMock(); + var assessmentSectionStub = mockRepository.Stub(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); @@ -99,31 +98,15 @@ var inputContext = new HeightStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, - assessmentSectionMock); + assessmentSectionStub); // Call properties.Data = inputContext; // Assert HeightStructuresInput input = calculation.InputParameters; - var expectedFailureProbabilityStructureWithErosion = ProbabilityFormattingHelper.Format(input.FailureProbabilityStructureWithErosion); - Assert.IsNull(properties.Structure); - Assert.IsNull(properties.StructureLocation); - Assert.AreSame(input.ModelFactorSuperCriticalFlow, properties.ModelFactorSuperCriticalFlow.Data); - Assert.AreEqual(input.StructureNormalOrientation, properties.StructureNormalOrientation); Assert.AreSame(input.LevelCrestStructure, properties.LevelCrestStructure.Data); - Assert.AreSame(input.AllowedLevelIncreaseStorage, properties.AllowedLevelIncreaseStorage.Data); - Assert.AreSame(input.StorageStructureArea, properties.StorageStructureArea.Data); - Assert.AreSame(input.FlowWidthAtBottomProtection, properties.FlowWidthAtBottomProtection.Data); - Assert.AreSame(input.WidthFlowApertures, properties.WidthFlowApertures.Data); - Assert.AreSame(input.CriticalOvertoppingDischarge, properties.CriticalOvertoppingDischarge.Data); - Assert.IsNull(properties.ForeshoreProfile); - Assert.IsInstanceOf(properties.UseBreakWater); - Assert.IsInstanceOf(properties.UseForeshore); - Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); - Assert.AreSame(input.HydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); - Assert.AreSame(input.StormDuration, properties.StormDuration.Data); Assert.AreEqual(input.DeviationWaveDirection, properties.DeviationWaveDirection); mockRepository.VerifyAll(); @@ -140,8 +123,8 @@ new HydraulicBoundaryLocation(0, "", 0, 0) } }; - var assessmentSectionMock = mockRepository.Stub(); - assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + var assessmentSectionStub = mockRepository.Stub(); + assessmentSectionStub.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism @@ -160,41 +143,23 @@ InputParameters = { Structure = new TestHeightStructure(), - HydraulicBoundaryLocation = CreateValidHydraulicBoundaryLocation(), - ForeshoreProfile = CreateValidForeshoreProfile() + HydraulicBoundaryLocation = CreateHydraulicBoundaryLocation(), + ForeshoreProfile = CreateForeshoreProfile() } }; var inputContext = new HeightStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, - assessmentSectionMock); + assessmentSectionStub); var properties = new HeightStructuresInputContextProperties(); // Call properties.Data = inputContext; // Assert HeightStructuresInput input = calculation.InputParameters; - var expectedStructureLocation = new Point2D(new RoundedDouble(0, input.Structure.Location.X), new RoundedDouble(0, input.Structure.Location.Y)); - var expectedFailureProbabilityStructureWithErosion = ProbabilityFormattingHelper.Format(input.FailureProbabilityStructureWithErosion); - - Assert.AreSame(input.Structure, properties.Structure); - Assert.AreEqual(expectedStructureLocation, properties.StructureLocation); - Assert.AreSame(input.ModelFactorSuperCriticalFlow, properties.ModelFactorSuperCriticalFlow.Data); - Assert.AreEqual(input.StructureNormalOrientation, properties.StructureNormalOrientation); Assert.AreSame(input.LevelCrestStructure, properties.LevelCrestStructure.Data); - Assert.AreSame(input.AllowedLevelIncreaseStorage, properties.AllowedLevelIncreaseStorage.Data); - Assert.AreSame(input.StorageStructureArea, properties.StorageStructureArea.Data); - Assert.AreSame(input.FlowWidthAtBottomProtection, properties.FlowWidthAtBottomProtection.Data); - Assert.AreSame(input.WidthFlowApertures, properties.WidthFlowApertures.Data); - Assert.AreSame(input.CriticalOvertoppingDischarge, properties.CriticalOvertoppingDischarge.Data); - Assert.AreSame(input.ForeshoreProfile, properties.ForeshoreProfile); - Assert.IsInstanceOf(properties.UseBreakWater); - Assert.IsInstanceOf(properties.UseForeshore); - Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); - Assert.AreSame(input.HydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); - Assert.AreSame(input.StormDuration, properties.StormDuration.Data); Assert.AreEqual(input.DeviationWaveDirection, properties.DeviationWaveDirection); Assert.AreEqual(1, properties.GetAvailableHydraulicBoundaryLocations().Count()); @@ -203,60 +168,43 @@ Assert.AreEqual(1, properties.GetAvailableStructures().Count()); CollectionAssert.AreEqual(failureMechanism.HeightStructures, properties.GetAvailableStructures()); - Assert.AreEqual(1, properties.GetAvailableForeshoreProfiles().Count()); - CollectionAssert.AreEqual(failureMechanism.ForeshoreProfiles, properties.GetAvailableForeshoreProfiles()); mockRepository.VerifyAll(); } [Test] public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() { // Setup + const int numberOfChangedProperties = 1; var observerMock = mockRepository.StrictMock(); - const int numberOfChangedProperties = 6; + var assessmentSectionStub = mockRepository.Stub(); + observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties); - var hydraulicBoundaryLocation = CreateValidHydraulicBoundaryLocation(); - var assessmentSectionMock = mockRepository.Stub(); + mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var input = calculation.InputParameters; - input.Attach(observerMock); var inputContext = new HeightStructuresInputContext(input, calculation, failureMechanism, - assessmentSectionMock); - + assessmentSectionStub); var properties = new HeightStructuresInputContextProperties { Data = inputContext }; + input.Attach(observerMock); + var random = new Random(100); - double newStructureNormalOrientation = random.NextDouble(); - HeightStructure newHeightStructure = new TestHeightStructure(); - ForeshoreProfile newForeshoreProfile = CreateValidForeshoreProfile(); double newDeviationWaveDirection = random.NextDouble(); // Call - properties.Structure = newHeightStructure; - properties.StructureNormalOrientation = (RoundedDouble) newStructureNormalOrientation; - properties.FailureProbabilityStructureWithErosion = "1e-2"; - properties.HydraulicBoundaryLocation = hydraulicBoundaryLocation; - properties.ForeshoreProfile = newForeshoreProfile; properties.DeviationWaveDirection = (RoundedDouble) newDeviationWaveDirection; // Assert - Assert.AreSame(newHeightStructure, properties.Structure); - Assert.AreEqual(newStructureNormalOrientation, properties.StructureNormalOrientation, - properties.StructureNormalOrientation.GetAccuracy()); - Assert.AreEqual(0.01, input.FailureProbabilityStructureWithErosion); - Assert.AreEqual("1/100", properties.FailureProbabilityStructureWithErosion); - Assert.AreSame(hydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); - Assert.AreSame(newForeshoreProfile, properties.ForeshoreProfile); - Assert.AreEqual(newDeviationWaveDirection, properties.DeviationWaveDirection, - properties.DeviationWaveDirection.GetAccuracy()); + Assert.AreEqual(newDeviationWaveDirection, properties.DeviationWaveDirection, properties.DeviationWaveDirection.GetAccuracy()); mockRepository.VerifyAll(); } @@ -266,15 +214,15 @@ public void SetFailureProbabilityStructureWithErosion_InvalidValues_ThrowsArgumentException(double newValue) { // Setup - var assessmentSectionMock = mockRepository.Stub(); + var assessmentSectionStub = mockRepository.Stub(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var inputContext = new HeightStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, - assessmentSectionMock); + assessmentSectionStub); var properties = new HeightStructuresInputContextProperties { @@ -297,15 +245,15 @@ public void SetFailureProbabilityStructureWithErosion_ValuesUnableToParse_ThrowsArgumentException(string newValue) { // Setup - var assessmentSectionMock = mockRepository.Stub(); + var assessmentSectionStub = mockRepository.Stub(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var inputContext = new HeightStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, - assessmentSectionMock); + assessmentSectionStub); var properties = new HeightStructuresInputContextProperties { @@ -326,15 +274,15 @@ public void SetFailureProbabilityStructureWithErosion_NullValue_ThrowsArgumentNullException() { // Setup - var assessmentSectionMock = mockRepository.Stub(); + var assessmentSectionStub = mockRepository.Stub(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var inputContext = new HeightStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, - assessmentSectionMock); + assessmentSectionStub); var properties = new HeightStructuresInputContextProperties { @@ -355,15 +303,15 @@ public void PropertyAttributes_ReturnExpectedValues() { // Setup - var assessmentSectionMock = mockRepository.Stub(); + var assessmentSectionStub = mockRepository.Stub(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var inputContext = new HeightStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, - assessmentSectionMock); + assessmentSectionStub); // Call var properties = new HeightStructuresInputContextProperties @@ -489,12 +437,12 @@ mockRepository.VerifyAll(); } - private static ForeshoreProfile CreateValidForeshoreProfile() + private static ForeshoreProfile CreateForeshoreProfile() { return new ForeshoreProfile(new Point2D(0, 0), Enumerable.Empty(), new BreakWater(BreakWaterType.Caisson, 0), new ForeshoreProfile.ConstructionProperties()); } - private static HydraulicBoundaryLocation CreateValidHydraulicBoundaryLocation() + private static HydraulicBoundaryLocation CreateHydraulicBoundaryLocation() { return new HydraulicBoundaryLocation(0, "name", 0.0, 1.1); }