/// <summary> /// Reads the <see cref="HeightStructureEntity"/> and use the information to update a /// <see cref="HeightStructure"/>. /// </summary> /// <param name="entity">The <see cref="HeightStructureEntity"/> to create <see cref="HeightStructure"/> for.</param> /// <param name="collector">The object keeping track of read operations.</param> /// <returns>A new <see cref="HeightStructure"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception> internal static HeightStructure Read(this HeightStructureEntity entity, ReadConversionCollector collector) { if (collector == null) { throw new ArgumentNullException(nameof(collector)); } if (collector.Contains(entity)) { return(collector.Get(entity)); } var structure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = entity.Name, Id = entity.Id, Location = new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()), StructureNormalOrientation = (RoundedDouble)entity.StructureNormalOrientation.ToNullAsNaN(), LevelCrestStructure = { Mean = (RoundedDouble)entity.LevelCrestStructureMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.LevelCrestStructureStandardDeviation.ToNullAsNaN() }, FlowWidthAtBottomProtection = { Mean = (RoundedDouble)entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN() }, CriticalOvertoppingDischarge = { Mean = (RoundedDouble)entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(), CoefficientOfVariation = (RoundedDouble)entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN() }, WidthFlowApertures = { Mean = (RoundedDouble)entity.WidthFlowAperturesMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.WidthFlowAperturesStandardDeviation.ToNullAsNaN() }, FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion.ToNullAsNaN(), StorageStructureArea = { Mean = (RoundedDouble)entity.StorageStructureAreaMean.ToNullAsNaN(), CoefficientOfVariation = (RoundedDouble)entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN() }, AllowedLevelIncreaseStorage = { Mean = (RoundedDouble)entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN() } }); collector.Read(entity, structure); return(structure); }
private static void AddEntitiesForHeightStructures( StructureCollection <HeightStructure> structures, FailureMechanismEntity entity, PersistenceRegistry registry) { for (var i = 0; i < structures.Count; i++) { HeightStructureEntity structureEntity = structures[i].Create(registry, i); entity.HeightStructureEntities.Add(structureEntity); } }
public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() { // Setup var entity = new HeightStructureEntity(); // Call TestDelegate call = () => entity.Read(null); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("collector", paramName); }
public void Read_ValidEntity_ReturnHeightStructure() { // Setup var entity = new HeightStructureEntity { Name = "A", Id = "B", X = 1.1, Y = 2.2, StructureNormalOrientation = 3.3, LevelCrestStructureMean = 4.4, LevelCrestStructureStandardDeviation = 5.5, FlowWidthAtBottomProtectionMean = 6.6, FlowWidthAtBottomProtectionStandardDeviation = 7.7, CriticalOvertoppingDischargeMean = 8.8, CriticalOvertoppingDischargeCoefficientOfVariation = 9.9, WidthFlowAperturesMean = 10.10, WidthFlowAperturesStandardDeviation = 11.11, FailureProbabilityStructureWithErosion = 12.12, StorageStructureAreaMean = 13.13, StorageStructureAreaCoefficientOfVariation = 14.14, AllowedLevelIncreaseStorageMean = 15.15, AllowedLevelIncreaseStorageStandardDeviation = 16.16 }; var collector = new ReadConversionCollector(); // Call HeightStructure structure = entity.Read(collector); // Assert Assert.AreEqual(entity.Name, structure.Name); Assert.AreEqual(entity.Id, structure.Id); Assert.AreEqual(entity.X, structure.Location.X); Assert.AreEqual(entity.Y, structure.Location.Y); Assert.AreEqual(entity.StructureNormalOrientation, structure.StructureNormalOrientation.Value); Assert.AreEqual(entity.LevelCrestStructureMean, structure.LevelCrestStructure.Mean.Value); Assert.AreEqual(entity.LevelCrestStructureStandardDeviation, structure.LevelCrestStructure.StandardDeviation.Value); Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, structure.FlowWidthAtBottomProtection.Mean.Value); Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, structure.CriticalOvertoppingDischarge.Mean.Value); Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.AreEqual(entity.WidthFlowAperturesMean, structure.WidthFlowApertures.Mean.Value); Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, structure.WidthFlowApertures.StandardDeviation.Value); Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); Assert.AreEqual(entity.StorageStructureAreaMean, structure.StorageStructureArea.Mean.Value); Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation.Value); Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, structure.AllowedLevelIncreaseStorage.Mean.Value); Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); }
public void Read_NullValues_ReturnHeightStructureWithNaN() { // Setup var entity = new HeightStructureEntity { Name = "A", Id = "B", X = null, Y = null, StructureNormalOrientation = null, LevelCrestStructureMean = null, LevelCrestStructureStandardDeviation = null, FlowWidthAtBottomProtectionMean = null, FlowWidthAtBottomProtectionStandardDeviation = null, CriticalOvertoppingDischargeMean = null, CriticalOvertoppingDischargeCoefficientOfVariation = null, WidthFlowAperturesMean = null, WidthFlowAperturesStandardDeviation = null, FailureProbabilityStructureWithErosion = null, StorageStructureAreaMean = null, StorageStructureAreaCoefficientOfVariation = null, AllowedLevelIncreaseStorageMean = null, AllowedLevelIncreaseStorageStandardDeviation = null }; var collector = new ReadConversionCollector(); // Call HeightStructure structure = entity.Read(collector); // Assert Assert.IsNaN(structure.Location.X); Assert.IsNaN(structure.Location.Y); Assert.IsNaN(structure.StructureNormalOrientation); Assert.IsNaN(structure.LevelCrestStructure.Mean.Value); Assert.IsNaN(structure.LevelCrestStructure.StandardDeviation.Value); Assert.IsNaN(structure.FlowWidthAtBottomProtection.Mean.Value); Assert.IsNaN(structure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.IsNaN(structure.CriticalOvertoppingDischarge.Mean.Value); Assert.IsNaN(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.IsNaN(structure.WidthFlowApertures.Mean.Value); Assert.IsNaN(structure.WidthFlowApertures.StandardDeviation.Value); Assert.IsNaN(structure.FailureProbabilityStructureWithErosion); Assert.IsNaN(structure.StorageStructureArea.Mean.Value); Assert.IsNaN(structure.StorageStructureArea.CoefficientOfVariation.Value); Assert.IsNaN(structure.AllowedLevelIncreaseStorage.Mean.Value); Assert.IsNaN(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); }
public void Read_EntityRegistered_ReturnRegisteredStructure() { // Setup var entity = new HeightStructureEntity(); HeightStructure registeredStructure = new TestHeightStructure(); var collector = new ReadConversionCollector(); collector.Read(entity, registeredStructure); // Call HeightStructure readStructure = entity.Read(collector); // Assert Assert.AreSame(registeredStructure, readStructure); }
public void Create_StructureAlreadyRegistered_ReturnRegisteredEntity() { // Setup var structure = new TestHeightStructure(); var registeredEntity = new HeightStructureEntity(); var registry = new PersistenceRegistry(); registry.Register(registeredEntity, structure); // Call HeightStructureEntity entity = structure.Create(registry, 0); // Assert Assert.AreSame(registeredEntity, entity); }
public void Read_EntityWithStructureEntity_ReturnCalculationWithStructure() { // Setup HeightStructure structure = new TestHeightStructure(); var structureEntity = new HeightStructureEntity(); var entity = new HeightStructuresCalculationEntity { HeightStructureEntity = structureEntity, ScenarioContribution = 0 }; var collector = new ReadConversionCollector(); collector.Read(structureEntity, structure); // Call StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector); // Assert Assert.AreSame(structure, calculation.InputParameters.Structure); }
public void Read_EntityNotReadBefore_RegisterEntity() { // Setup var entity = new HeightStructureEntity { Name = "name", Id = "id" }; var collector = new ReadConversionCollector(); // Precondition Assert.IsFalse(collector.Contains(entity)); // Call HeightStructure calculation = entity.Read(collector); // Assert Assert.IsTrue(collector.Contains(entity)); Assert.AreSame(calculation, collector.Get(entity)); }
/// <summary> /// Creates a <see cref="HeightStructureEntity"/> based on the information of the <see cref="HeightStructure"/>. /// </summary> /// <param name="structure">The structure to create a database entity for.</param> /// <param name="registry">The object keeping track of create operations.</param> /// <param name="order">The index at which <paramref name="structure"/> resides within its parent.</param> /// <returns>A new <see cref="HeightStructureEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception> internal static HeightStructureEntity Create(this HeightStructure structure, PersistenceRegistry registry, int order) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (registry.Contains(structure)) { return(registry.Get(structure)); } var entity = new HeightStructureEntity { Name = structure.Name.DeepClone(), Id = structure.Id.DeepClone(), X = structure.Location.X.ToNaNAsNull(), Y = structure.Location.Y.ToNaNAsNull(), StructureNormalOrientation = structure.StructureNormalOrientation.ToNaNAsNull(), AllowedLevelIncreaseStorageMean = structure.AllowedLevelIncreaseStorage.Mean.ToNaNAsNull(), AllowedLevelIncreaseStorageStandardDeviation = structure.AllowedLevelIncreaseStorage.StandardDeviation.ToNaNAsNull(), CriticalOvertoppingDischargeMean = structure.CriticalOvertoppingDischarge.Mean.ToNaNAsNull(), CriticalOvertoppingDischargeCoefficientOfVariation = structure.CriticalOvertoppingDischarge.CoefficientOfVariation.ToNaNAsNull(), FailureProbabilityStructureWithErosion = structure.FailureProbabilityStructureWithErosion.ToNaNAsNull(), FlowWidthAtBottomProtectionMean = structure.FlowWidthAtBottomProtection.Mean.ToNaNAsNull(), FlowWidthAtBottomProtectionStandardDeviation = structure.FlowWidthAtBottomProtection.StandardDeviation.ToNaNAsNull(), LevelCrestStructureMean = structure.LevelCrestStructure.Mean.ToNaNAsNull(), LevelCrestStructureStandardDeviation = structure.LevelCrestStructure.StandardDeviation.ToNaNAsNull(), StorageStructureAreaMean = structure.StorageStructureArea.Mean.ToNaNAsNull(), StorageStructureAreaCoefficientOfVariation = structure.StorageStructureArea.CoefficientOfVariation.ToNaNAsNull(), WidthFlowAperturesMean = structure.WidthFlowApertures.Mean.ToNaNAsNull(), WidthFlowAperturesStandardDeviation = structure.WidthFlowApertures.StandardDeviation.ToNaNAsNull(), Order = order }; registry.Register(entity, structure); return(entity); }
public void Create_ValidStructure_ReturnEntity() { // Setup HeightStructure structure = new TestHeightStructure(); var registry = new PersistenceRegistry(); const int order = 4; // Call HeightStructureEntity entity = structure.Create(registry, order); // Assert Assert.AreEqual(structure.Name, entity.Name); Assert.AreNotSame(structure.Name, entity.Name); Assert.AreEqual(structure.Id, entity.Id); Assert.AreNotSame(structure.Id, entity.Id); Assert.AreEqual(structure.Location.X, entity.X); Assert.AreEqual(structure.Location.Y, entity.Y); Assert.AreEqual(structure.StructureNormalOrientation.Value, entity.StructureNormalOrientation); Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); Assert.AreEqual(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); Assert.AreEqual(structure.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); Assert.AreEqual(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); Assert.AreEqual(structure.FailureProbabilityStructureWithErosion, entity.FailureProbabilityStructureWithErosion); Assert.AreEqual(structure.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); Assert.AreEqual(structure.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); Assert.AreEqual(structure.LevelCrestStructure.Mean.Value, entity.LevelCrestStructureMean); Assert.AreEqual(structure.LevelCrestStructure.StandardDeviation.Value, entity.LevelCrestStructureStandardDeviation); Assert.AreEqual(structure.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); Assert.AreEqual(structure.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); Assert.AreEqual(structure.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); Assert.AreEqual(structure.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); Assert.AreEqual(order, entity.Order); Assert.IsTrue(registry.Contains(structure)); }
/// <summary> /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/> /// that was constructed with the information. /// </summary> /// <param name="entity">The <see cref="HeightStructureEntity"/> to be registered.</param> /// <param name="model">The <see cref="HeightStructure"/> to be registered.</param> /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception> internal void Register(HeightStructureEntity entity, HeightStructure model) { Register(heightStructures, entity, model); }
public void Create_NaNValue_ReturnEntityWithNullValue() { // Setup var structure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = "A", Id = "B", Location = new Point2D(double.NaN, double.NaN), StructureNormalOrientation = RoundedDouble.NaN, AllowedLevelIncreaseStorage = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }, CriticalOvertoppingDischarge = { Mean = RoundedDouble.NaN, CoefficientOfVariation = RoundedDouble.NaN }, FailureProbabilityStructureWithErosion = double.NaN, FlowWidthAtBottomProtection = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }, LevelCrestStructure = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }, StorageStructureArea = { Mean = RoundedDouble.NaN, CoefficientOfVariation = RoundedDouble.NaN }, WidthFlowApertures = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN } }); var registry = new PersistenceRegistry(); // Call HeightStructureEntity entity = structure.Create(registry, 0); // Assert Assert.IsNull(entity.X); Assert.IsNull(entity.Y); Assert.IsNull(entity.StructureNormalOrientation); Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); Assert.IsNull(entity.CriticalOvertoppingDischargeMean); Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); Assert.IsNull(entity.FailureProbabilityStructureWithErosion); Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); Assert.IsNull(entity.LevelCrestStructureMean); Assert.IsNull(entity.LevelCrestStructureStandardDeviation); Assert.IsNull(entity.StorageStructureAreaMean); Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); Assert.IsNull(entity.WidthFlowAperturesMean); Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); }