private static void SetInputParameters(StabilityStoneCoverWaveConditionsCalculationEntity entity, StabilityStoneCoverWaveConditionsInput calculationInput, PersistenceRegistry registry) { if (calculationInput.HydraulicBoundaryLocation != null) { entity.HydraulicLocationEntity = calculationInput.HydraulicBoundaryLocation.Create(registry, 0); } if (calculationInput.ForeshoreProfile != null) { entity.ForeshoreProfileEntity = calculationInput.ForeshoreProfile.Create(registry, 0); } if (calculationInput.CalculationsTargetProbability != null) { entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntity = calculationInput.CalculationsTargetProbability.Create(HydraulicBoundaryLocationCalculationType.WaterLevel, 0, registry); } entity.Orientation = calculationInput.Orientation.ToNaNAsNull(); entity.UseBreakWater = Convert.ToByte(calculationInput.UseBreakWater); entity.BreakWaterType = Convert.ToByte(calculationInput.BreakWater.Type); entity.BreakWaterHeight = calculationInput.BreakWater.Height.ToNaNAsNull(); entity.UseForeshore = Convert.ToByte(calculationInput.UseForeshore); entity.UpperBoundaryRevetment = calculationInput.UpperBoundaryRevetment.ToNaNAsNull(); entity.LowerBoundaryRevetment = calculationInput.LowerBoundaryRevetment.ToNaNAsNull(); entity.UpperBoundaryWaterLevels = calculationInput.UpperBoundaryWaterLevels.ToNaNAsNull(); entity.LowerBoundaryWaterLevels = calculationInput.LowerBoundaryWaterLevels.ToNaNAsNull(); entity.StepSize = Convert.ToByte(calculationInput.StepSize); entity.CalculationType = Convert.ToByte(calculationInput.CalculationType); entity.WaterLevelType = Convert.ToByte(calculationInput.WaterLevelType); }
public void AddCalculationsFromLocations_MultipleCalculationsEmptyCalculationBase_ReturnsUniquelyNamedCalculationsWithCorrectInputSet( NormativeProbabilityType normativeProbabilityType, WaveConditionsInputWaterLevelType expectedWaveConditionsInputWaterLevelType) { // Setup const string name = "name"; var locations = new[] { new HydraulicBoundaryLocation(1, name, 1, 1), new HydraulicBoundaryLocation(2, name, 2, 2) }; var calculationBases = new List <ICalculationBase>(); // Call StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases, normativeProbabilityType); // Assert Assert.AreEqual(2, calculationBases.Count); var firstCalculation = (StabilityStoneCoverWaveConditionsCalculation)calculationBases.First(); Assert.AreEqual(name, firstCalculation.Name); StabilityStoneCoverWaveConditionsInput firstCalculationInput = firstCalculation.InputParameters; Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation); Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, firstCalculationInput.WaterLevelType); var secondCalculation = (StabilityStoneCoverWaveConditionsCalculation)calculationBases.ElementAt(1); Assert.AreEqual($"{name} (1)", secondCalculation.Name); StabilityStoneCoverWaveConditionsInput secondCalculationInput = secondCalculation.InputParameters; Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation); Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, secondCalculationInput.WaterLevelType); }
public void Read_EntityWithNullValues_ReturnCalculationWithNaNValues() { // Setup var entity = new StabilityStoneCoverWaveConditionsCalculationEntity(); var collector = new ReadConversionCollector(); // Call StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); // Assert Assert.IsNull(calculation.Name); Assert.IsNull(calculation.Comments.Body); StabilityStoneCoverWaveConditionsInput calculationInput = calculation.InputParameters; Assert.IsNaN(calculationInput.BreakWater.Height); Assert.IsNaN(calculationInput.Orientation); Assert.IsNaN(calculationInput.UpperBoundaryRevetment); Assert.IsNaN(calculationInput.LowerBoundaryRevetment); Assert.IsNaN(calculationInput.UpperBoundaryWaterLevels); Assert.IsNaN(calculationInput.LowerBoundaryWaterLevels); Assert.IsNull(calculationInput.HydraulicBoundaryLocation); Assert.IsNull(calculationInput.ForeshoreProfile); Assert.IsNull(calculation.Output); }
public void Constructor_ExpectedValues() { // Call var input = new StabilityStoneCoverWaveConditionsInput(); // Assert Assert.IsInstanceOf <WaveConditionsInput>(input); Assert.AreEqual(StabilityStoneCoverWaveConditionsCalculationType.Both, input.CalculationType); }
/// <summary> /// Creates a new instance of <see cref="StabilityStoneCoverWaveConditionsOutputContext"/>. /// </summary> /// <param name="wrappedData">The wrapped data.</param> /// <param name="input">The input belonging to the wrapped data.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public StabilityStoneCoverWaveConditionsOutputContext(StabilityStoneCoverWaveConditionsOutput wrappedData, StabilityStoneCoverWaveConditionsInput input) : base(wrappedData) { if (input == null) { throw new ArgumentNullException(nameof(input)); } Input = input; }
public void Constructor_CalculationTypeBlocksOrColumns_PropertiesHaveExpectedAttributesValues(StabilityStoneCoverWaveConditionsCalculationType calculationType) { // Setup var blocksOutput = new[] { new TestWaveConditionsOutput() }; var columnsOutput = new[] { new TestWaveConditionsOutput() }; StabilityStoneCoverWaveConditionsOutput stabilityStoneCoverWaveConditionsOutput = StabilityStoneCoverWaveConditionsOutputTestFactory.Create( columnsOutput, blocksOutput); var input = new StabilityStoneCoverWaveConditionsInput { CalculationType = calculationType }; // Call var properties = new StabilityStoneCoverWaveConditionsOutputProperties( stabilityStoneCoverWaveConditionsOutput, input); // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(1, dynamicProperties.Count); const string resultCategory = "Resultaat"; string revetmentType = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Blocks) { revetmentType = "blokken"; } if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Columns) { revetmentType = "zuilen"; } PropertyDescriptor outputProperty = dynamicProperties[0]; Assert.IsInstanceOf <ExpandableArrayConverter>(outputProperty.Converter); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(outputProperty, resultCategory, $"Hydraulische belastingen voor {revetmentType}", $"Berekende hydraulische belastingen voor {revetmentType}.", true); }
public void Clone_AllPropertiesSet_ReturnNewInstanceWithCopiedValues() { // Setup var original = new StabilityStoneCoverWaveConditionsInput(); WaveConditionsTestDataGenerator.SetRandomDataToWaveConditionsInput(original); original.CalculationType = StabilityStoneCoverWaveConditionsCalculationType.Blocks; // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, StabilityStoneCoverCloneAssert.AreClones); }
public void Constructor_ExpectedValues() { // Setup StabilityStoneCoverWaveConditionsOutput output = StabilityStoneCoverWaveConditionsOutputTestFactory.Create(); var input = new StabilityStoneCoverWaveConditionsInput(); // Call var context = new StabilityStoneCoverWaveConditionsOutputContext(output, input); // Assert Assert.IsInstanceOf <ObservableWrappedObjectContextBase <StabilityStoneCoverWaveConditionsOutput> >(context); Assert.AreSame(output, context.WrappedData); Assert.AreSame(input, context.Input); }
public void Create_CalculationWithPropertiesSet_ReturnCalculationEntity() { // Setup var random = new Random(21); int order = random.Next(); var calculation = new StabilityStoneCoverWaveConditionsCalculation { InputParameters = { Orientation = random.NextRoundedDouble(0, 360), UseBreakWater = random.NextBoolean(), UseForeshore = random.NextBoolean(), UpperBoundaryRevetment = (RoundedDouble)6.10, LowerBoundaryRevetment = (RoundedDouble)3.58, UpperBoundaryWaterLevels = (RoundedDouble)5.88, LowerBoundaryWaterLevels = (RoundedDouble)3.40, StepSize = random.NextEnumValue <WaveConditionsInputStepSize>(), WaterLevelType = random.NextEnumValue <WaveConditionsInputWaterLevelType>(), CalculationType = random.NextEnumValue <StabilityStoneCoverWaveConditionsCalculationType>() } }; var registry = new PersistenceRegistry(); // Call StabilityStoneCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, order); // Assert StabilityStoneCoverWaveConditionsInput input = calculation.InputParameters; Assert.AreEqual(input.Orientation, entity.Orientation, input.Orientation.GetAccuracy()); Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); Assert.AreEqual(input.UpperBoundaryRevetment, entity.UpperBoundaryRevetment, input.UpperBoundaryRevetment.GetAccuracy()); Assert.AreEqual(input.LowerBoundaryRevetment, entity.LowerBoundaryRevetment, input.LowerBoundaryRevetment.GetAccuracy()); Assert.AreEqual(input.UpperBoundaryWaterLevels, entity.UpperBoundaryWaterLevels, input.UpperBoundaryWaterLevels.GetAccuracy()); Assert.AreEqual(input.LowerBoundaryWaterLevels, entity.LowerBoundaryWaterLevels, input.LowerBoundaryWaterLevels.GetAccuracy()); Assert.AreEqual(Convert.ToByte(input.StepSize), entity.StepSize); Assert.AreEqual(Convert.ToByte(input.CalculationType), entity.CalculationType); Assert.AreEqual(Convert.ToByte(input.WaterLevelType), entity.WaterLevelType); Assert.AreEqual(order, entity.Order); Assert.IsNull(entity.CalculationGroupEntity); CollectionAssert.IsEmpty(entity.StabilityStoneCoverWaveConditionsOutputEntities); Assert.IsNull(entity.ForeshoreProfileEntity); Assert.IsNull(entity.HydraulicLocationEntity); Assert.IsNull(entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntity); }
public void Clone_NotAllPropertiesSet_ReturnNewInstanceWithCopiedValues() { // Setup var original = new StabilityStoneCoverWaveConditionsInput(); WaveConditionsTestDataGenerator.SetRandomDataToWaveConditionsInput(original); original.ForeshoreProfile = null; original.HydraulicBoundaryLocation = null; // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, StabilityStoneCoverCloneAssert.AreClones); }
/// <summary> /// Creates a new instance of <see cref="StabilityStoneCoverWaveConditionsOutputProperties"/>. /// </summary> /// <param name="output">The data to show.</param> /// <param name="input">The input to use.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public StabilityStoneCoverWaveConditionsOutputProperties( StabilityStoneCoverWaveConditionsOutput output, StabilityStoneCoverWaveConditionsInput input) { if (output == null) { throw new ArgumentNullException(nameof(output)); } if (input == null) { throw new ArgumentNullException(nameof(input)); } this.input = input; Data = output; }
public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility( StabilityStoneCoverWaveConditionsCalculationType calculationType, bool blocksVisible, bool columnsVisible) { // Setup StabilityStoneCoverWaveConditionsOutput output = StabilityStoneCoverWaveConditionsOutputTestFactory.Create(); var input = new StabilityStoneCoverWaveConditionsInput { CalculationType = calculationType }; var properties = new StabilityStoneCoverWaveConditionsOutputProperties(output, input); // Call & Assert Assert.AreEqual(blocksVisible, properties.DynamicVisibleValidationMethod(nameof(properties.Blocks))); Assert.AreEqual(columnsVisible, properties.DynamicVisibleValidationMethod(nameof(properties.Columns))); Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); }
private static void ReadCalculationInputs(StabilityStoneCoverWaveConditionsInput inputParameters, StabilityStoneCoverWaveConditionsCalculationEntity entity, ReadConversionCollector collector) { inputParameters.ForeshoreProfile = GetDikeProfileValue(entity.ForeshoreProfileEntity, collector); inputParameters.HydraulicBoundaryLocation = GetHydraulicBoundaryLocationValue(entity.HydraulicLocationEntity, collector); inputParameters.CalculationsTargetProbability = GetHydraulicBoundaryLocationCalculationsForTargetProbabilityValue( entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntity, collector); inputParameters.Orientation = (RoundedDouble)entity.Orientation.ToNullAsNaN(); inputParameters.UseForeshore = Convert.ToBoolean(entity.UseForeshore); inputParameters.UseBreakWater = Convert.ToBoolean(entity.UseBreakWater); inputParameters.BreakWater.Height = (RoundedDouble)entity.BreakWaterHeight.ToNullAsNaN(); inputParameters.BreakWater.Type = (BreakWaterType)entity.BreakWaterType; inputParameters.UpperBoundaryRevetment = (RoundedDouble)entity.UpperBoundaryRevetment.ToNullAsNaN(); inputParameters.LowerBoundaryRevetment = (RoundedDouble)entity.LowerBoundaryRevetment.ToNullAsNaN(); inputParameters.UpperBoundaryWaterLevels = (RoundedDouble)entity.UpperBoundaryWaterLevels.ToNullAsNaN(); inputParameters.LowerBoundaryWaterLevels = (RoundedDouble)entity.LowerBoundaryWaterLevels.ToNullAsNaN(); inputParameters.StepSize = (WaveConditionsInputStepSize)entity.StepSize; inputParameters.CalculationType = (StabilityStoneCoverWaveConditionsCalculationType)entity.CalculationType; inputParameters.WaterLevelType = (WaveConditionsInputWaterLevelType)entity.WaterLevelType; }
/// <summary> /// Performs a wave conditions calculation for the stability of stone revetment failure mechanism based on the supplied /// <see cref="StabilityStoneCoverWaveConditionsCalculation"/> and sets /// <see cref="StabilityStoneCoverWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="StabilityStoneCoverWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="StabilityStoneCoverWaveConditionsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/> /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> public void Calculate(StabilityStoneCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralStabilityStoneCoverWaveConditionsInput generalWaveConditionsInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalWaveConditionsInput == null) { throw new ArgumentNullException(nameof(generalWaveConditionsInput)); } StabilityStoneCoverWaveConditionsInput calculationInput = calculation.InputParameters; StabilityStoneCoverWaveConditionsCalculationType calculationType = calculationInput.CalculationType; if (!Enum.IsDefined(typeof(StabilityStoneCoverWaveConditionsCalculationType), calculationType)) { throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, typeof(StabilityStoneCoverWaveConditionsCalculationType)); } CalculationServiceHelper.LogCalculationBegin(); double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection); int waterLevelCount = calculationInput.GetWaterLevels(assessmentLevel).Count(); TotalWaterLevelCalculations = calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both ? waterLevelCount * 2 : waterLevelCount; try { IEnumerable <WaveConditionsOutput> blocksOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Blocks) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Blocks_DisplayName; blocksOutputs = CalculateBlocks(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralBlocksWaveConditionsInput, targetProbability); } if (Canceled) { return; } IEnumerable <WaveConditionsOutput> columnsOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Columns) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Columns_DisplayName; columnsOutputs = CalculateColumns(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralColumnsWaveConditionsInput, targetProbability); } if (!Canceled) { calculation.Output = CreateOutput(calculationType, blocksOutputs, columnsOutputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/> /// are clones. /// </summary> /// <param name="original">The original object.</param> /// <param name="clone">The cloned object.</param> /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and /// <paramref name="clone"/> are not clones.</exception> public static void AreClones(StabilityStoneCoverWaveConditionsInput original, StabilityStoneCoverWaveConditionsInput clone) { Assert.AreEqual(original.CalculationType, clone.CalculationType); WaveConditionsCloneAssert.AreClones(original, clone); }
public void Read_ValidEntity_ReturnCalculation() { // Setup const string name = "Calculation Name"; const string comments = "Calculation Comment"; var random = new Random(21); double orientation = random.NextDouble(); bool useBreakWater = random.NextBoolean(); var breakWaterType = random.NextEnumValue <BreakWaterType>(); double breakWaterHeight = random.NextDouble(); bool useForeshore = random.NextBoolean(); const double lowerBoundaryRevetment = 3.58; const double upperBoundaryRevetment = 6.10; const double lowerBoundaryWaterLevels = 3.40; const double upperBoundaryWaterLevels = 5.88; var stepSize = random.NextEnumValue <WaveConditionsInputStepSize>(); var calculationType = random.NextEnumValue <StabilityStoneCoverWaveConditionsCalculationType>(); var waterLevelType = random.NextEnumValue <WaveConditionsInputWaterLevelType>(); var entity = new StabilityStoneCoverWaveConditionsCalculationEntity { Name = name, Comments = comments, UseBreakWater = Convert.ToByte(useBreakWater), BreakWaterType = Convert.ToByte(breakWaterType), BreakWaterHeight = breakWaterHeight, UseForeshore = Convert.ToByte(useForeshore), Orientation = orientation, UpperBoundaryRevetment = upperBoundaryRevetment, LowerBoundaryRevetment = lowerBoundaryRevetment, UpperBoundaryWaterLevels = upperBoundaryWaterLevels, LowerBoundaryWaterLevels = lowerBoundaryWaterLevels, StepSize = Convert.ToByte(stepSize), CalculationType = Convert.ToByte(calculationType), WaterLevelType = Convert.ToByte(waterLevelType) }; var collector = new ReadConversionCollector(); // Call StabilityStoneCoverWaveConditionsCalculation calculation = entity.Read(collector); // Assert Assert.AreEqual(name, calculation.Name); Assert.AreEqual(comments, calculation.Comments.Body); StabilityStoneCoverWaveConditionsInput calculationInput = calculation.InputParameters; Assert.AreEqual(useBreakWater, calculationInput.UseBreakWater); Assert.AreEqual(breakWaterType, calculationInput.BreakWater.Type); RoundedDoubleTestHelper.AssertRoundedDouble(breakWaterHeight, calculationInput.BreakWater.Height); Assert.AreEqual(useForeshore, calculationInput.UseForeshore); RoundedDoubleTestHelper.AssertRoundedDouble(orientation, calculationInput.Orientation); RoundedDoubleTestHelper.AssertRoundedDouble(upperBoundaryRevetment, calculationInput.UpperBoundaryRevetment); RoundedDoubleTestHelper.AssertRoundedDouble(lowerBoundaryRevetment, calculationInput.LowerBoundaryRevetment); RoundedDoubleTestHelper.AssertRoundedDouble(upperBoundaryWaterLevels, calculationInput.UpperBoundaryWaterLevels); RoundedDoubleTestHelper.AssertRoundedDouble(lowerBoundaryWaterLevels, calculationInput.LowerBoundaryWaterLevels); Assert.AreEqual(stepSize, calculationInput.StepSize); Assert.AreEqual(calculationType, calculationInput.CalculationType); Assert.AreEqual(waterLevelType, calculationInput.WaterLevelType); Assert.IsNull(calculationInput.HydraulicBoundaryLocation); Assert.IsNull(calculationInput.ForeshoreProfile); Assert.IsNull(calculationInput.CalculationsTargetProbability); Assert.IsNull(calculation.Output); }