// 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 Application.Ringtoets.Storage.TestUtil; using Core.Common.Base; using Core.Common.Base.Data; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.HydraRing.Data; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Data.TestUtil; using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; using Ringtoets.StabilityPointStructures.Forms.PropertyClasses; namespace Ringtoets.StabilityPointStructures.Forms.Test.PropertyClasses { [TestFixture] public class StabilityPointStructuresInputContextPropertiesTest { private MockRepository mockRepository; [SetUp] public void SetUp() { mockRepository = new MockRepository(); } [Test] public void Constructor_ExpectedValues() { // Call var properties = new StabilityPointStructuresInputContextProperties(); // Assert Assert.IsInstanceOf, StabilityPointStructuresFailureMechanism>>(properties); Assert.IsNull(properties.Data); } [Test] public void Data_SetNewInputContextInstance_ReturnCorrectPropertyValues() { // Setup var assessmentSectionStub = mockRepository.Stub(); mockRepository.ReplayAll(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var properties = new StabilityPointStructuresInputContextProperties(); var inputContext = new StabilityPointStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSectionStub); // Call properties.Data = inputContext; // Assert StabilityPointStructuresInput input = calculation.InputParameters; var expectedFailureProbabilityRepairClosure = ProbabilityFormattingHelper.Format(input.FailureProbabilityRepairClosure); var expectedProbabilityCollisionSecondaryStructure = ProbabilityFormattingHelper.Format(input.ProbabilityCollisionSecondaryStructure); Assert.AreEqual(input.VolumicWeightWater, properties.VolumicWeightWater); Assert.AreSame(input.InsideWaterLevelFailureConstruction, properties.InsideWaterLevelFailureConstruction.Data); Assert.AreSame(input.InsideWaterLevel, properties.InsideWaterLevel.Data); Assert.AreSame(input.DrainCoefficient, properties.DrainCoefficient.Data); Assert.AreEqual(input.FactorStormDurationOpenStructure, properties.FactorStormDurationOpenStructure); Assert.AreSame(input.FlowVelocityStructureClosable, properties.FlowVelocityStructureClosable.Data); Assert.AreEqual(input.InflowModelType, properties.InflowModelType); Assert.AreEqual(input.LoadSchematizationType, properties.LoadSchematizationType); Assert.AreSame(input.LevelCrestStructure, properties.LevelCrestStructure.Data); Assert.AreSame(input.ThresholdHeightOpenWeir, properties.ThresholdHeightOpenWeir.Data); Assert.AreSame(input.AreaFlowApertures, properties.AreaFlowApertures.Data); Assert.AreSame(input.ConstructiveStrengthLinearLoadModel, properties.ConstructiveStrengthLinearLoadModel.Data); Assert.AreSame(input.ConstructiveStrengthQuadraticLoadModel, properties.ConstructiveStrengthQuadraticLoadModel.Data); Assert.AreSame(input.StabilityLinearLoadModel, properties.StabilityLinearLoadModel.Data); Assert.AreSame(input.StabilityQuadraticLoadModel, properties.StabilityQuadraticLoadModel.Data); Assert.AreEqual(expectedFailureProbabilityRepairClosure, properties.FailureProbabilityRepairClosure); Assert.AreSame(input.FailureCollisionEnergy, properties.FailureCollisionEnergy.Data); Assert.AreSame(input.ShipMass, properties.ShipMass.Data); Assert.AreSame(input.ShipVelocity, properties.ShipVelocity.Data); Assert.AreEqual(input.LevellingCount, properties.LevellingCount); Assert.AreEqual(expectedProbabilityCollisionSecondaryStructure, properties.ProbabilityCollisionSecondaryStructure); Assert.AreSame(input.BankWidth, properties.BankWidth.Data); Assert.AreEqual(input.EvaluationLevel, properties.EvaluationLevel); Assert.AreEqual(input.VerticalDistance, properties.VerticalDistance); mockRepository.VerifyAll(); } [Test] public void Data_SetNewInputContextInstanceWithData_ReturnCorrectPropertyValues() { // Setup var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { Locations = { new HydraulicBoundaryLocation(0, "", 0, 0) } }; var assessmentSectionStub = mockRepository.Stub(); assessmentSectionStub.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; mockRepository.ReplayAll(); var failureMechanism = new StabilityPointStructuresFailureMechanism { ForeshoreProfiles = { new TestForeshoreProfile() }, StabilityPointStructures = { new TestStabilityPointStructure() } }; var calculation = new StructuresCalculation { InputParameters = { Structure = new TestStabilityPointStructure(), HydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "name", 0.0, 1.1), ForeshoreProfile = new TestForeshoreProfile() } }; var inputContext = new StabilityPointStructuresInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSectionStub); var properties = new StabilityPointStructuresInputContextProperties(); // Call properties.Data = inputContext; // Assert StabilityPointStructuresInput input = calculation.InputParameters; var expectedFailureProbabilityRepairClosure = ProbabilityFormattingHelper.Format(input.FailureProbabilityRepairClosure); var expectedProbabilityCollisionSecondaryStructure = ProbabilityFormattingHelper.Format(input.ProbabilityCollisionSecondaryStructure); Assert.AreEqual(input.VolumicWeightWater, properties.VolumicWeightWater); Assert.AreSame(input.InsideWaterLevelFailureConstruction, properties.InsideWaterLevelFailureConstruction.Data); Assert.AreSame(input.InsideWaterLevel, properties.InsideWaterLevel.Data); Assert.AreSame(input.DrainCoefficient, properties.DrainCoefficient.Data); Assert.AreEqual(input.FactorStormDurationOpenStructure, properties.FactorStormDurationOpenStructure); Assert.AreSame(input.FlowVelocityStructureClosable, properties.FlowVelocityStructureClosable.Data); Assert.AreEqual(input.InflowModelType, properties.InflowModelType); Assert.AreEqual(input.LoadSchematizationType, properties.LoadSchematizationType); Assert.AreSame(input.LevelCrestStructure, properties.LevelCrestStructure.Data); Assert.AreSame(input.ThresholdHeightOpenWeir, properties.ThresholdHeightOpenWeir.Data); Assert.AreSame(input.AreaFlowApertures, properties.AreaFlowApertures.Data); Assert.AreSame(input.ConstructiveStrengthLinearLoadModel, properties.ConstructiveStrengthLinearLoadModel.Data); Assert.AreSame(input.ConstructiveStrengthQuadraticLoadModel, properties.ConstructiveStrengthQuadraticLoadModel.Data); Assert.AreSame(input.StabilityLinearLoadModel, properties.StabilityLinearLoadModel.Data); Assert.AreSame(input.StabilityQuadraticLoadModel, properties.StabilityQuadraticLoadModel.Data); Assert.AreEqual(expectedFailureProbabilityRepairClosure, properties.FailureProbabilityRepairClosure); Assert.AreSame(input.FailureCollisionEnergy, properties.FailureCollisionEnergy.Data); Assert.AreSame(input.ShipMass, properties.ShipMass.Data); Assert.AreSame(input.ShipVelocity, properties.ShipVelocity.Data); Assert.AreEqual(input.LevellingCount, properties.LevellingCount); Assert.AreEqual(expectedProbabilityCollisionSecondaryStructure, properties.ProbabilityCollisionSecondaryStructure); Assert.AreSame(input.BankWidth, properties.BankWidth.Data); Assert.AreEqual(input.EvaluationLevel, properties.EvaluationLevel); Assert.AreEqual(input.VerticalDistance, properties.VerticalDistance); var availableForeshoreProfiles = properties.GetAvailableForeshoreProfiles().ToArray(); Assert.AreEqual(1, availableForeshoreProfiles.Length); CollectionAssert.AreEqual(failureMechanism.ForeshoreProfiles, availableForeshoreProfiles); var availableStructures = properties.GetAvailableStructures().ToArray(); Assert.AreEqual(1, availableStructures.Length); CollectionAssert.AreEqual(failureMechanism.StabilityPointStructures, availableStructures); mockRepository.VerifyAll(); } [Test] public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() { // Setup const int numberOfChangedProperties = 9; var observerMock = mockRepository.StrictMock(); var assessmentSectionStub = mockRepository.Stub(); observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties); mockRepository.ReplayAll(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var calculation = new StructuresCalculation(); var input = calculation.InputParameters; var inputContext = new StabilityPointStructuresInputContext(input, calculation, failureMechanism, assessmentSectionStub); var properties = new StabilityPointStructuresInputContextProperties { Data = inputContext }; input.Attach(observerMock); var random = new Random(100); double newVolumicWeightWater = random.NextDouble(); double newFactorStormDurationOpenStructure = random.NextDouble(); var newInflowModelType = StabilityPointStructureInflowModelType.FloodedCulvert; var newLoadSchematizationType = LoadSchematizationType.Quadratic; var newLevellingCount = 2; double newEvaluationLevel = random.NextDouble(); double newVerticalDistance = random.NextDouble(); // Call properties.VolumicWeightWater = (RoundedDouble) newVolumicWeightWater; properties.FactorStormDurationOpenStructure = (RoundedDouble) newFactorStormDurationOpenStructure; properties.InflowModelType = newInflowModelType; properties.LoadSchematizationType = newLoadSchematizationType; properties.FailureProbabilityRepairClosure = "1e-2"; properties.LevellingCount = newLevellingCount; properties.ProbabilityCollisionSecondaryStructure = "1e-3"; properties.EvaluationLevel = (RoundedDouble) newEvaluationLevel; properties.VerticalDistance = (RoundedDouble) newVerticalDistance; // Assert var expectedFailureProbabilityRepairClosure = ProbabilityFormattingHelper.Format(0.01); var expectedProbabilityCollisionSecondaryStructure = ProbabilityFormattingHelper.Format(0.001); Assert.AreEqual(newVolumicWeightWater, properties.VolumicWeightWater, properties.VolumicWeightWater.GetAccuracy()); Assert.AreEqual(newFactorStormDurationOpenStructure, properties.FactorStormDurationOpenStructure, properties.FactorStormDurationOpenStructure.GetAccuracy()); Assert.AreEqual(newInflowModelType, properties.InflowModelType); Assert.AreEqual(newLoadSchematizationType, properties.LoadSchematizationType); Assert.AreEqual(expectedFailureProbabilityRepairClosure, properties.FailureProbabilityRepairClosure); Assert.AreEqual(newLevellingCount, properties.LevellingCount); Assert.AreEqual(expectedProbabilityCollisionSecondaryStructure, properties.ProbabilityCollisionSecondaryStructure); Assert.AreEqual(newEvaluationLevel, properties.EvaluationLevel, properties.EvaluationLevel.GetAccuracy()); Assert.AreEqual(newVerticalDistance, properties.VerticalDistance, properties.VerticalDistance.GetAccuracy()); mockRepository.VerifyAll(); } } }