Exemple #1
0
        /// <summary>
        /// Removes the <paramref name="structure"/> and clears all dependent data, either directly or indirectly.
        /// </summary>
        /// <param name="structure">The structure to be removed.</param>
        /// <param name="failureMechanism">The <see cref="ClosingStructuresFailureMechanism"/>
        /// to clear the data from.</param>
        /// <returns>All objects affected by the removal.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static IEnumerable <IObservable> RemoveStructure(ClosingStructure structure,
                                                                ClosingStructuresFailureMechanism failureMechanism)
        {
            if (structure == null)
            {
                throw new ArgumentNullException(nameof(structure));
            }

            if (failureMechanism == null)
            {
                throw new ArgumentNullException(nameof(failureMechanism));
            }

            IEnumerable <StructuresCalculation <ClosingStructuresInput> > calculations =
                failureMechanism.Calculations.Cast <StructuresCalculation <ClosingStructuresInput> >();

            StructuresCalculation <ClosingStructuresInput>[] calculationWithRemovedStructure = calculations
                                                                                               .Where(c => ReferenceEquals(c.InputParameters.Structure, structure))
                                                                                               .ToArray();

            List <IObservable> changedObservables = ClearStructureDependentData(calculationWithRemovedStructure);

            StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures;

            structures.Remove(structure);
            changedObservables.Add(structures);

            return(changedObservables);
        }
        public void SynchronizeStructureInput_ChangedStructure_ExpectedValues()
        {
            // Setup
            var differentStructure = new ClosingStructure(new ClosingStructure.ConstructionProperties
            {
                Id       = "Test id",
                Name     = "Test name",
                Location = new Point2D(-1, -1)
            });

            var input = new ClosingStructuresInput
            {
                Structure = new TestClosingStructure()
            };

            input.Structure.CopyProperties(differentStructure);

            // Precondition
            AssertClosingStructureInput(new TestClosingStructure(), input);

            // Call
            input.SynchronizeStructureInput();

            // Assert
            AssertClosingStructureInput(differentStructure, input);
        }
Exemple #3
0
        public void Import_MissingParametersAndDuplicateIrrelevantParameter_LogWarningAndContinueImportWithDefaultValues()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(testDataPath, nameof(ClosingStructuresImporter),
                                               "MissingAndDuplicateIrrelevantParameters", "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);

                var defaultStructure = new ClosingStructure(new ClosingStructure.ConstructionProperties
                {
                    Name     = "test",
                    Location = new Point2D(0, 0),
                    Id       = "id"
                });

                var readStructures = (IEnumerable <ClosingStructure>)i.Arguments[0];
                Assert.AreEqual(1, readStructures.Count());
                ClosingStructure importedStructure = readStructures.First();
                DistributionAssert.AreEqual(defaultStructure.StorageStructureArea, importedStructure.StorageStructureArea);
                DistributionAssert.AreEqual(defaultStructure.LevelCrestStructureNotClosing, importedStructure.LevelCrestStructureNotClosing);
                DistributionAssert.AreEqual(defaultStructure.AreaFlowApertures, importedStructure.AreaFlowApertures);
                Assert.AreEqual(defaultStructure.FailureProbabilityReparation, importedStructure.FailureProbabilityReparation);
            });
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var structuresImporter = new ClosingStructuresImporter(importTarget, referenceLine,
                                                                   filePath, messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = structuresImporter.Import();

            // Assert
            TestHelper.AssertLogMessages(call, msgs =>
            {
                string[] messages = msgs.ToArray();
                Assert.AreEqual(10, messages.Length);

                const string structure = "'Coupure Den Oever (90k1)' (KUNST1)";

                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT1' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[0]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT5' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[3]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT8' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[6]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT14' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[8]);
                // Don't care about the other messages.
            });
            Assert.IsTrue(importResult);
        }
Exemple #4
0
        public void Import_VarianceValuesNeedConversion_WarnUserAboutConversion()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(testDataPath, "StructuresVarianceValueConversion",
                                               "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);

                var closingStructures = (IEnumerable <ClosingStructure>)i.Arguments[0];
                Assert.AreEqual(1, closingStructures.Count());

                ClosingStructure structure = closingStructures.First();
                Assert.AreEqual(0.2, structure.StorageStructureArea.CoefficientOfVariation.Value);
                Assert.AreEqual(20, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value);
                Assert.AreEqual(50, structure.WidthFlowApertures.StandardDeviation.Value);
                Assert.AreEqual(2.2, structure.LevelCrestStructureNotClosing.StandardDeviation.Value);
                Assert.AreEqual(3.3, structure.InsideWaterLevel.StandardDeviation.Value);
                Assert.AreEqual(4.4, structure.ThresholdHeightOpenWeir.StandardDeviation.Value);
                Assert.AreEqual(5.5, structure.AreaFlowApertures.StandardDeviation.Value);
                Assert.AreEqual(0.1, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value);
                Assert.AreEqual(6.6, structure.FlowWidthAtBottomProtection.StandardDeviation.Value);
            });
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var importer = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                         messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            string[] expectedMessages =
            {
                "De variatie voor parameter 'KW_BETSLUIT1' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 10).",
                "De variatie voor parameter 'KW_BETSLUIT2' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 11).",
                "De variatie voor parameter 'KW_BETSLUIT4' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 13).",
                "De variatie voor parameter 'KW_BETSLUIT5' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 14).",
                "De variatie voor parameter 'KW_BETSLUIT6' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 15).",
                "De variatie voor parameter 'KW_BETSLUIT7' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 16).",
                "De variatie voor parameter 'KW_BETSLUIT8' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 17).",
                "De variatie voor parameter 'KW_BETSLUIT9' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 18).",
                "De variatie voor parameter 'KW_BETSLUIT10' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 19)."
            };
            TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages);
            Assert.IsTrue(importResult);
        }
        /// <summary>
        /// Creates a <see cref="ClosingStructureEntity"/> based on the information of the <see cref="ClosingStructure"/>.
        /// </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="ClosingStructureEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static ClosingStructureEntity Create(this ClosingStructure structure, PersistenceRegistry registry, int order)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (registry.Contains(structure))
            {
                return(registry.Get(structure));
            }

            var entity = new ClosingStructureEntity
            {
                Name = structure.Name.DeepClone(),
                Id   = structure.Id.DeepClone(),
                X    = structure.Location.X.ToNaNAsNull(),
                Y    = structure.Location.Y.ToNaNAsNull(),
                StructureNormalOrientation = structure.StructureNormalOrientation.ToNaNAsNull(),
                StorageStructureAreaMean   = structure.StorageStructureArea.Mean.ToNaNAsNull(),
                StorageStructureAreaCoefficientOfVariation   = structure.StorageStructureArea.CoefficientOfVariation.ToNaNAsNull(),
                AllowedLevelIncreaseStorageMean              = structure.AllowedLevelIncreaseStorage.Mean.ToNaNAsNull(),
                AllowedLevelIncreaseStorageStandardDeviation = structure.AllowedLevelIncreaseStorage.StandardDeviation.ToNaNAsNull(),
                WidthFlowAperturesMean = structure.WidthFlowApertures.Mean.ToNaNAsNull(),
                WidthFlowAperturesStandardDeviation            = structure.WidthFlowApertures.StandardDeviation.ToNaNAsNull(),
                LevelCrestStructureNotClosingMean              = structure.LevelCrestStructureNotClosing.Mean.ToNaNAsNull(),
                LevelCrestStructureNotClosingStandardDeviation = structure.LevelCrestStructureNotClosing.StandardDeviation.ToNaNAsNull(),
                InsideWaterLevelMean = structure.InsideWaterLevel.Mean.ToNaNAsNull(),
                InsideWaterLevelStandardDeviation        = structure.InsideWaterLevel.StandardDeviation.ToNaNAsNull(),
                ThresholdHeightOpenWeirMean              = structure.ThresholdHeightOpenWeir.Mean.ToNaNAsNull(),
                ThresholdHeightOpenWeirStandardDeviation = structure.ThresholdHeightOpenWeir.StandardDeviation.ToNaNAsNull(),
                AreaFlowAperturesMean = structure.AreaFlowApertures.Mean.ToNaNAsNull(),
                AreaFlowAperturesStandardDeviation = structure.AreaFlowApertures.StandardDeviation.ToNaNAsNull(),
                CriticalOvertoppingDischargeMean   = structure.CriticalOvertoppingDischarge.Mean.ToNaNAsNull(),
                CriticalOvertoppingDischargeCoefficientOfVariation = structure.CriticalOvertoppingDischarge.CoefficientOfVariation.ToNaNAsNull(),
                FlowWidthAtBottomProtectionMean = structure.FlowWidthAtBottomProtection.Mean.ToNaNAsNull(),
                FlowWidthAtBottomProtectionStandardDeviation = structure.FlowWidthAtBottomProtection.StandardDeviation.ToNaNAsNull(),
                ProbabilityOpenStructureBeforeFlooding       = structure.ProbabilityOpenStructureBeforeFlooding.ToNaNAsNull(),
                FailureProbabilityOpenStructure = structure.FailureProbabilityOpenStructure.ToNaNAsNull(),
                IdenticalApertures           = structure.IdenticalApertures,
                FailureProbabilityReparation = structure.FailureProbabilityReparation.ToNaNAsNull(),
                InflowModelType = Convert.ToByte(structure.InflowModelType),
                Order           = order
            };

            registry.Register(entity, structure);

            return(entity);
        }
        public void Read_EntityRegistered_ReturnRegisteredStructure()
        {
            // Setup
            var entity = new ClosingStructureEntity();
            ClosingStructure registeredStructure = new TestClosingStructure();
            var collector = new ReadConversionCollector();

            collector.Read(entity, registeredStructure);

            // Call
            ClosingStructure readStructure = entity.Read(collector);

            // Assert
            Assert.AreSame(registeredStructure, readStructure);
        }
        public void CopyProperties_FromStructureNull_ThrowsArgumentNullException()
        {
            // Setup
            var structure = new ClosingStructure(new ClosingStructure.ConstructionProperties
            {
                Name     = "aName",
                Id       = "anId",
                Location = new Point2D(0, 0)
            });

            // Call
            TestDelegate call = () => structure.CopyProperties(null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("fromStructure", paramName);
        }
        private static void AssertClosingStructureInput(ClosingStructure expectedClosingStructure, ClosingStructuresInput input)
        {
            if (expectedClosingStructure == null)
            {
                Assert.IsNull(input.Structure);
                var defaultInput = new ClosingStructuresInput();
                AssertAreEqual(defaultInput.StructureNormalOrientation, input.StructureNormalOrientation);

                DistributionAssert.AreEqual(defaultInput.LevelCrestStructureNotClosing, input.LevelCrestStructureNotClosing);
                DistributionAssert.AreEqual(defaultInput.FlowWidthAtBottomProtection, input.FlowWidthAtBottomProtection);
                DistributionAssert.AreEqual(defaultInput.CriticalOvertoppingDischarge, input.CriticalOvertoppingDischarge);
                DistributionAssert.AreEqual(defaultInput.WidthFlowApertures, input.WidthFlowApertures);
                DistributionAssert.AreEqual(defaultInput.StorageStructureArea, input.StorageStructureArea);
                DistributionAssert.AreEqual(defaultInput.AllowedLevelIncreaseStorage, input.AllowedLevelIncreaseStorage);
                Assert.AreEqual(defaultInput.InflowModelType, input.InflowModelType);
                DistributionAssert.AreEqual(defaultInput.AreaFlowApertures, input.AreaFlowApertures);
                Assert.AreEqual(defaultInput.FailureProbabilityOpenStructure, input.FailureProbabilityOpenStructure);
                Assert.AreEqual(defaultInput.FailureProbabilityReparation, input.FailureProbabilityReparation);
                Assert.AreEqual(defaultInput.IdenticalApertures, input.IdenticalApertures);
                DistributionAssert.AreEqual(defaultInput.InsideWaterLevel, input.InsideWaterLevel);
                Assert.AreEqual(defaultInput.ProbabilityOpenStructureBeforeFlooding, input.ProbabilityOpenStructureBeforeFlooding);
                DistributionAssert.AreEqual(defaultInput.ThresholdHeightOpenWeir, input.ThresholdHeightOpenWeir);
            }
            else
            {
                AssertAreEqual(expectedClosingStructure.StructureNormalOrientation, input.StructureNormalOrientation);

                DistributionAssert.AreEqual(expectedClosingStructure.LevelCrestStructureNotClosing, input.LevelCrestStructureNotClosing);
                DistributionAssert.AreEqual(expectedClosingStructure.FlowWidthAtBottomProtection, input.FlowWidthAtBottomProtection);
                DistributionAssert.AreEqual(expectedClosingStructure.CriticalOvertoppingDischarge, input.CriticalOvertoppingDischarge);
                DistributionAssert.AreEqual(expectedClosingStructure.WidthFlowApertures, input.WidthFlowApertures);
                DistributionAssert.AreEqual(expectedClosingStructure.StorageStructureArea, input.StorageStructureArea);
                DistributionAssert.AreEqual(expectedClosingStructure.AllowedLevelIncreaseStorage, input.AllowedLevelIncreaseStorage);
                Assert.AreEqual(expectedClosingStructure.InflowModelType, input.InflowModelType);
                DistributionAssert.AreEqual(expectedClosingStructure.AreaFlowApertures, input.AreaFlowApertures);
                Assert.AreEqual(expectedClosingStructure.FailureProbabilityOpenStructure, input.FailureProbabilityOpenStructure);
                Assert.AreEqual(expectedClosingStructure.FailureProbabilityReparation, input.FailureProbabilityReparation);
                Assert.AreEqual(expectedClosingStructure.IdenticalApertures, input.IdenticalApertures);
                DistributionAssert.AreEqual(expectedClosingStructure.InsideWaterLevel, input.InsideWaterLevel);
                Assert.AreEqual(expectedClosingStructure.ProbabilityOpenStructureBeforeFlooding, input.ProbabilityOpenStructureBeforeFlooding);
                DistributionAssert.AreEqual(expectedClosingStructure.ThresholdHeightOpenWeir, input.ThresholdHeightOpenWeir);
            }
        }
        public void Read_EntityNotReadBefore_RegisterEntity()
        {
            // Setup
            var entity = new ClosingStructureEntity
            {
                Name = "name",
                Id   = "id"
            };

            var collector = new ReadConversionCollector();

            // Precondition
            Assert.IsFalse(collector.Contains(entity));

            // Call
            ClosingStructure calculation = entity.Read(collector);

            // Assert
            Assert.IsTrue(collector.Contains(entity));
            Assert.AreSame(calculation, collector.Get(entity));
        }
        private static void AssertClosingStructures(ClosingStructure readStructure, ClosingStructure structure)
        {
            Assert.AreEqual(readStructure.Name, structure.Name);
            Assert.AreEqual(readStructure.Location, structure.Location);
            Assert.AreEqual(readStructure.StructureNormalOrientation, structure.StructureNormalOrientation);

            DistributionAssert.AreEqual(readStructure.AllowedLevelIncreaseStorage, structure.AllowedLevelIncreaseStorage);
            DistributionAssert.AreEqual(readStructure.AreaFlowApertures, structure.AreaFlowApertures);
            DistributionAssert.AreEqual(readStructure.CriticalOvertoppingDischarge, structure.CriticalOvertoppingDischarge);

            Assert.AreEqual(readStructure.FailureProbabilityOpenStructure, structure.FailureProbabilityOpenStructure);
            Assert.AreEqual(readStructure.FailureProbabilityReparation, structure.FailureProbabilityReparation);
            Assert.AreEqual(readStructure.IdenticalApertures, structure.IdenticalApertures);
            Assert.AreEqual(readStructure.InflowModelType, structure.InflowModelType);
            Assert.AreEqual(readStructure.ProbabilityOpenStructureBeforeFlooding, structure.ProbabilityOpenStructureBeforeFlooding);

            DistributionAssert.AreEqual(readStructure.FlowWidthAtBottomProtection, structure.FlowWidthAtBottomProtection);
            DistributionAssert.AreEqual(readStructure.InsideWaterLevel, structure.InsideWaterLevel);
            DistributionAssert.AreEqual(readStructure.LevelCrestStructureNotClosing, structure.LevelCrestStructureNotClosing);
            DistributionAssert.AreEqual(readStructure.StorageStructureArea, structure.StorageStructureArea);
            DistributionAssert.AreEqual(readStructure.ThresholdHeightOpenWeir, structure.ThresholdHeightOpenWeir);
            DistributionAssert.AreEqual(readStructure.WidthFlowApertures, structure.WidthFlowApertures);
        }
Exemple #11
0
        public void Create_NaNValue_ReturnEntityWithNullValue()
        {
            // Setup
            var structure = new ClosingStructure(new ClosingStructure.ConstructionProperties
            {
                Name     = "A",
                Id       = "B",
                Location = new Point2D(double.NaN, double.NaN),
                StructureNormalOrientation = RoundedDouble.NaN,
                StorageStructureArea       =
                {
                    Mean                   = RoundedDouble.NaN,
                    CoefficientOfVariation = RoundedDouble.NaN
                },
                AllowedLevelIncreaseStorage =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                WidthFlowApertures =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                LevelCrestStructureNotClosing =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                InsideWaterLevel =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                ThresholdHeightOpenWeir =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                AreaFlowApertures =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                CriticalOvertoppingDischarge =
                {
                    Mean                   = RoundedDouble.NaN,
                    CoefficientOfVariation = RoundedDouble.NaN
                },
                FlowWidthAtBottomProtection =
                {
                    Mean              = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN
                },
                ProbabilityOpenStructureBeforeFlooding = double.NaN,
                FailureProbabilityOpenStructure        = double.NaN,
                FailureProbabilityReparation           = double.NaN
            });
            var registry = new PersistenceRegistry();

            // Call
            ClosingStructureEntity entity = structure.Create(registry, 0);

            // Assert
            Assert.IsNull(entity.X);
            Assert.IsNull(entity.Y);
            Assert.IsNull(entity.StructureNormalOrientation);
            Assert.IsNull(entity.StorageStructureAreaMean);
            Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation);
            Assert.IsNull(entity.AllowedLevelIncreaseStorageMean);
            Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation);
            Assert.IsNull(entity.WidthFlowAperturesMean);
            Assert.IsNull(entity.WidthFlowAperturesStandardDeviation);
            Assert.IsNull(entity.LevelCrestStructureNotClosingMean);
            Assert.IsNull(entity.LevelCrestStructureNotClosingStandardDeviation);
            Assert.IsNull(entity.InsideWaterLevelMean);
            Assert.IsNull(entity.InsideWaterLevelStandardDeviation);
            Assert.IsNull(entity.ThresholdHeightOpenWeirMean);
            Assert.IsNull(entity.ThresholdHeightOpenWeirStandardDeviation);
            Assert.IsNull(entity.AreaFlowAperturesMean);
            Assert.IsNull(entity.AreaFlowAperturesStandardDeviation);
            Assert.IsNull(entity.CriticalOvertoppingDischargeMean);
            Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation);
            Assert.IsNull(entity.FlowWidthAtBottomProtectionMean);
            Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation);
            Assert.IsNull(entity.ProbabilityOpenStructureBeforeFlooding);
            Assert.IsNull(entity.FailureProbabilityOpenStructure);
            Assert.IsNull(entity.FailureProbabilityReparation);
        }
        /// <summary>
        /// Reads the <see cref="ClosingStructureEntity"/> and use the information to update a
        /// <see cref="ClosingStructure"/>.
        /// </summary>
        /// <param name="entity">The <see cref="ClosingStructureEntity"/> to create <see cref="ClosingStructure"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="ClosingStructure"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception>
        internal static ClosingStructure Read(this ClosingStructureEntity entity, ReadConversionCollector collector)
        {
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            if (collector.Contains(entity))
            {
                return(collector.Get(entity));
            }

            var structure = new ClosingStructure(new ClosingStructure.ConstructionProperties
            {
                Name     = entity.Name,
                Id       = entity.Id,
                Location = new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()),
                StructureNormalOrientation = (RoundedDouble)entity.StructureNormalOrientation.ToNullAsNaN(),
                StorageStructureArea       =
                {
                    Mean                   = (RoundedDouble)entity.StorageStructureAreaMean.ToNullAsNaN(),
                    CoefficientOfVariation = (RoundedDouble)entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN()
                },
                AllowedLevelIncreaseStorage =
                {
                    Mean              = (RoundedDouble)entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN()
                },
                WidthFlowApertures =
                {
                    Mean              = (RoundedDouble)entity.WidthFlowAperturesMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.WidthFlowAperturesStandardDeviation.ToNullAsNaN()
                },
                LevelCrestStructureNotClosing =
                {
                    Mean              = (RoundedDouble)entity.LevelCrestStructureNotClosingMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.LevelCrestStructureNotClosingStandardDeviation.ToNullAsNaN()
                },
                InsideWaterLevel =
                {
                    Mean              = (RoundedDouble)entity.InsideWaterLevelMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.InsideWaterLevelStandardDeviation.ToNullAsNaN()
                },
                ThresholdHeightOpenWeir =
                {
                    Mean              = (RoundedDouble)entity.ThresholdHeightOpenWeirMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.ThresholdHeightOpenWeirStandardDeviation.ToNullAsNaN()
                },
                AreaFlowApertures =
                {
                    Mean              = (RoundedDouble)entity.AreaFlowAperturesMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.AreaFlowAperturesStandardDeviation.ToNullAsNaN()
                },
                CriticalOvertoppingDischarge =
                {
                    Mean                   = (RoundedDouble)entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(),
                    CoefficientOfVariation = (RoundedDouble)entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN()
                },
                FlowWidthAtBottomProtection =
                {
                    Mean              = (RoundedDouble)entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN()
                },
                ProbabilityOpenStructureBeforeFlooding = entity.ProbabilityOpenStructureBeforeFlooding.ToNullAsNaN(),
                FailureProbabilityOpenStructure        = entity.FailureProbabilityOpenStructure.ToNullAsNaN(),
                IdenticalApertures           = entity.IdenticalApertures,
                FailureProbabilityReparation = entity.FailureProbabilityReparation.ToNullAsNaN(),
                InflowModelType = (ClosingStructureInflowModelType)entity.InflowModelType
            });

            collector.Read(entity, structure);

            return(structure);
        }
        public void Constructor_DefaultConstructionProperties_ExpectedValues()
        {
            // Setup
            var location = new Point2D(1.22, 2.333);

            // Call
            var structure = new ClosingStructure(
                new ClosingStructure.ConstructionProperties
            {
                Name     = "aName",
                Id       = "anId",
                Location = location
            });

            // Assert
            Assert.IsInstanceOf <StructureBase>(structure);
            Assert.AreEqual("aName", structure.Name);
            Assert.AreEqual("anId", structure.Id);
            Assert.AreEqual(location.X, structure.Location.X);
            Assert.AreEqual(location.Y, structure.Location.Y);

            Assert.AreEqual(2, structure.StructureNormalOrientation.NumberOfDecimalPlaces);
            Assert.IsNaN(structure.StructureNormalOrientation);

            VariationCoefficientLogNormalDistribution storageStructureArea = structure.StorageStructureArea;

            Assert.AreEqual(2, storageStructureArea.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(storageStructureArea.Mean);
            Assert.AreEqual(2, storageStructureArea.CoefficientOfVariation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.1, storageStructureArea.CoefficientOfVariation, storageStructureArea.CoefficientOfVariation.GetAccuracy());

            LogNormalDistribution allowedLevelIncreaseStorage = structure.AllowedLevelIncreaseStorage;

            Assert.AreEqual(2, allowedLevelIncreaseStorage.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(allowedLevelIncreaseStorage.Mean);
            Assert.AreEqual(2, allowedLevelIncreaseStorage.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.1, allowedLevelIncreaseStorage.StandardDeviation, allowedLevelIncreaseStorage.StandardDeviation.GetAccuracy());

            NormalDistribution widthFlowApertures = structure.WidthFlowApertures;

            Assert.AreEqual(2, widthFlowApertures.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(widthFlowApertures.Mean);
            Assert.AreEqual(2, widthFlowApertures.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.2, widthFlowApertures.StandardDeviation, widthFlowApertures.StandardDeviation.GetAccuracy());

            NormalDistribution levelCrestStructureNotClosing = structure.LevelCrestStructureNotClosing;

            Assert.AreEqual(2, levelCrestStructureNotClosing.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(levelCrestStructureNotClosing.Mean);
            Assert.AreEqual(2, levelCrestStructureNotClosing.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.05, levelCrestStructureNotClosing.StandardDeviation, levelCrestStructureNotClosing.StandardDeviation.GetAccuracy());

            NormalDistribution insideWaterLevel = structure.InsideWaterLevel;

            Assert.AreEqual(2, insideWaterLevel.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(insideWaterLevel.Mean);
            Assert.AreEqual(2, insideWaterLevel.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.1, insideWaterLevel.StandardDeviation, insideWaterLevel.StandardDeviation.GetAccuracy());

            NormalDistribution thresholdHeightOpenWeir = structure.ThresholdHeightOpenWeir;

            Assert.AreEqual(2, thresholdHeightOpenWeir.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(thresholdHeightOpenWeir.Mean);
            Assert.AreEqual(2, thresholdHeightOpenWeir.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.1, thresholdHeightOpenWeir.StandardDeviation, thresholdHeightOpenWeir.StandardDeviation.GetAccuracy());

            LogNormalDistribution areaFlowApertures = structure.AreaFlowApertures;

            Assert.AreEqual(2, areaFlowApertures.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(areaFlowApertures.Mean);
            Assert.AreEqual(2, areaFlowApertures.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.01, areaFlowApertures.StandardDeviation, areaFlowApertures.StandardDeviation.GetAccuracy());

            VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge = structure.CriticalOvertoppingDischarge;

            Assert.AreEqual(2, criticalOvertoppingDischarge.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(criticalOvertoppingDischarge.Mean);
            Assert.AreEqual(2, criticalOvertoppingDischarge.CoefficientOfVariation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.15, criticalOvertoppingDischarge.CoefficientOfVariation, criticalOvertoppingDischarge.CoefficientOfVariation.GetAccuracy());

            LogNormalDistribution flowWidthAtBottomProtection = structure.FlowWidthAtBottomProtection;

            Assert.AreEqual(2, flowWidthAtBottomProtection.Mean.NumberOfDecimalPlaces);
            Assert.IsNaN(flowWidthAtBottomProtection.Mean);
            Assert.AreEqual(2, flowWidthAtBottomProtection.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.05, flowWidthAtBottomProtection.StandardDeviation, flowWidthAtBottomProtection.StandardDeviation.GetAccuracy());

            Assert.AreEqual(1, structure.ProbabilityOpenStructureBeforeFlooding);
            Assert.AreEqual(1, structure.FailureProbabilityOpenStructure);
            Assert.AreEqual(1, structure.IdenticalApertures);
            Assert.AreEqual(1, structure.FailureProbabilityReparation);

            Assert.AreEqual(ClosingStructureInflowModelType.VerticalWall, structure.InflowModelType);
        }
        public void CopyProperties_FromStructure_UpdatesProperties()
        {
            // Setup
            var random    = new Random(123);
            var structure = new ClosingStructure(new ClosingStructure.ConstructionProperties
            {
                Name     = "aName",
                Id       = "anId",
                Location = new Point2D(0, 0)
            });

            var otherStructure = new ClosingStructure(new ClosingStructure.ConstructionProperties
            {
                Name     = "otherName",
                Id       = "otherId",
                Location = new Point2D(1, 1),
                StructureNormalOrientation  = random.NextRoundedDouble(),
                AllowedLevelIncreaseStorage =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                AreaFlowApertures =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                CriticalOvertoppingDischarge =
                {
                    Mean                   = random.NextRoundedDouble(),
                    CoefficientOfVariation = random.NextRoundedDouble()
                },
                FlowWidthAtBottomProtection =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                InsideWaterLevel =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                LevelCrestStructureNotClosing =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                StorageStructureArea =
                {
                    Mean                   = random.NextRoundedDouble(),
                    CoefficientOfVariation = random.NextRoundedDouble()
                },
                ThresholdHeightOpenWeir =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                WidthFlowApertures =
                {
                    Mean              = random.NextRoundedDouble(),
                    StandardDeviation = random.NextRoundedDouble()
                },
                FailureProbabilityOpenStructure = random.NextDouble(),
                FailureProbabilityReparation    = random.NextDouble(),
                InflowModelType    = ClosingStructureInflowModelType.FloodedCulvert,
                IdenticalApertures = random.Next(),
                ProbabilityOpenStructureBeforeFlooding = random.NextDouble()
            });

            // Call
            structure.CopyProperties(otherStructure);

            // Assert
            Assert.AreNotEqual(otherStructure.Id, structure.Id);
            Assert.AreEqual(otherStructure.Name, structure.Name);
            TestHelper.AssertAreEqualButNotSame(otherStructure.Location, structure.Location);
            Assert.AreEqual(otherStructure.StructureNormalOrientation, structure.StructureNormalOrientation);
            TestHelper.AssertAreEqualButNotSame(otherStructure.AllowedLevelIncreaseStorage, structure.AllowedLevelIncreaseStorage);
            TestHelper.AssertAreEqualButNotSame(otherStructure.AreaFlowApertures, structure.AreaFlowApertures);
            TestHelper.AssertAreEqualButNotSame(otherStructure.CriticalOvertoppingDischarge, structure.CriticalOvertoppingDischarge);
            Assert.AreEqual(otherStructure.FailureProbabilityOpenStructure, structure.FailureProbabilityOpenStructure);
            Assert.AreEqual(otherStructure.FailureProbabilityReparation, structure.FailureProbabilityReparation);
            Assert.AreEqual(otherStructure.IdenticalApertures, structure.IdenticalApertures);
            Assert.AreEqual(otherStructure.ProbabilityOpenStructureBeforeFlooding, structure.ProbabilityOpenStructureBeforeFlooding);
            TestHelper.AssertAreEqualButNotSame(otherStructure.FlowWidthAtBottomProtection, structure.FlowWidthAtBottomProtection);
            TestHelper.AssertAreEqualButNotSame(otherStructure.InsideWaterLevel, structure.InsideWaterLevel);
            TestHelper.AssertAreEqualButNotSame(otherStructure.LevelCrestStructureNotClosing, structure.LevelCrestStructureNotClosing);
            TestHelper.AssertAreEqualButNotSame(otherStructure.StorageStructureArea, structure.StorageStructureArea);
            TestHelper.AssertAreEqualButNotSame(otherStructure.ThresholdHeightOpenWeir, structure.ThresholdHeightOpenWeir);
            TestHelper.AssertAreEqualButNotSame(otherStructure.WidthFlowApertures, structure.WidthFlowApertures);
        }
        public void IsStructureInputSynchronized_StructureAndInputNotInSync_ReturnFalse(ClosingStructure modifiedStructure)
        {
            // Setup
            var structure = new TestClosingStructure();
            var input     = new ClosingStructuresInput
            {
                Structure = structure
            };

            structure.CopyProperties(modifiedStructure);

            // Call
            bool isStructureInputSynchronized = input.IsStructureInputSynchronized;

            // Assert
            Assert.IsFalse(isStructureInputSynchronized);
        }
 /// <summary>
 /// Obtains the <see cref="ClosingStructureEntity"/> which was registered for the
 /// given <paramref name="model"/>.
 /// </summary>
 /// <param name="model">The <see cref="ClosingStructure"/> for which a read operation has been registered.</param>
 /// <returns>The constructed <see cref="ClosingStructureEntity"/>.</returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is <c>null</c>.</exception>
 /// <exception cref="InvalidOperationException">Thrown when no create operation
 /// has been registered for <paramref name="model"/>.</exception>
 /// <remarks>Use <see cref="Contains(ClosingStructure)"/> to find out whether a
 /// create operation has been registered for <paramref name="model"/>.</remarks>
 internal ClosingStructureEntity Get(ClosingStructure model)
 {
     return(Get(closingStructures, model));
 }
 /// <summary>
 /// Checks whether a create operations has been registered for the given <paramref name="model"/>.
 /// </summary>
 /// <param name="model">The <see cref="ClosingStructure"/> to check for.</param>
 /// <returns><c>true</c> if the <see cref="model"/> was registered before, <c>false</c> otherwise.</returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is <c>null</c>.</exception>
 internal bool Contains(ClosingStructure model)
 {
     return(ContainsValue(closingStructures, model));
 }
 /// <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="ClosingStructureEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="ClosingStructure"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(ClosingStructureEntity entity, ClosingStructure model)
 {
     Register(closingStructures, entity, model);
 }
        public void Constructor_ValidData_ExpectedValues()
        {
            // Setup
            var location = new Point2D(1.22, 2.333);

            // Call
            var structure = new ClosingStructure(
                new ClosingStructure.ConstructionProperties
            {
                Name                 = "aName",
                Id                   = "anId",
                Location             = location,
                StorageStructureArea =
                {
                    Mean                   = (RoundedDouble)123.456,
                    CoefficientOfVariation = (RoundedDouble)0.123
                },
                AllowedLevelIncreaseStorage =
                {
                    Mean              = (RoundedDouble)234.567,
                    StandardDeviation = (RoundedDouble)0.234
                },
                StructureNormalOrientation = (RoundedDouble)345.678,
                WidthFlowApertures         =
                {
                    Mean              = (RoundedDouble)456.789,
                    StandardDeviation = (RoundedDouble)0.456
                },
                LevelCrestStructureNotClosing =
                {
                    Mean              = (RoundedDouble)567.890,
                    StandardDeviation = (RoundedDouble)0.567
                },
                InsideWaterLevel =
                {
                    Mean              = (RoundedDouble)678.901,
                    StandardDeviation = (RoundedDouble)0.678
                },
                ThresholdHeightOpenWeir =
                {
                    Mean              = (RoundedDouble)789.012,
                    StandardDeviation = (RoundedDouble)0.789
                },
                AreaFlowApertures =
                {
                    Mean              = (RoundedDouble)890.123,
                    StandardDeviation = (RoundedDouble)0.890
                },
                CriticalOvertoppingDischarge =
                {
                    Mean                   = (RoundedDouble)901.234,
                    CoefficientOfVariation = (RoundedDouble)0.901
                },
                FlowWidthAtBottomProtection =
                {
                    Mean              = (RoundedDouble)111.222,
                    StandardDeviation = (RoundedDouble)0.111
                },
                ProbabilityOpenStructureBeforeFlooding = 321.987,
                FailureProbabilityOpenStructure        = 654.321,
                IdenticalApertures           = 42,
                FailureProbabilityReparation = 987.654,
                InflowModelType = ClosingStructureInflowModelType.LowSill
            });

            // Assert
            Assert.IsInstanceOf <StructureBase>(structure);
            Assert.AreEqual("aName", structure.Name);
            Assert.AreEqual("anId", structure.Id);
            Assert.AreEqual(location.X, structure.Location.X);
            Assert.AreEqual(location.Y, structure.Location.Y);

            Assert.AreEqual(345.68, structure.StructureNormalOrientation, structure.StructureNormalOrientation.GetAccuracy());

            VariationCoefficientLogNormalDistribution storageStructureArea = structure.StorageStructureArea;

            Assert.AreEqual(2, storageStructureArea.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(123.46, storageStructureArea.Mean, storageStructureArea.Mean.GetAccuracy());
            Assert.AreEqual(2, storageStructureArea.CoefficientOfVariation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.12, storageStructureArea.CoefficientOfVariation, storageStructureArea.CoefficientOfVariation.GetAccuracy());

            LogNormalDistribution allowedLevelIncreaseStorage = structure.AllowedLevelIncreaseStorage;

            Assert.AreEqual(2, allowedLevelIncreaseStorage.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(234.57, allowedLevelIncreaseStorage.Mean, allowedLevelIncreaseStorage.Mean.GetAccuracy());
            Assert.AreEqual(2, allowedLevelIncreaseStorage.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.23, allowedLevelIncreaseStorage.StandardDeviation, allowedLevelIncreaseStorage.StandardDeviation.GetAccuracy());

            NormalDistribution widthFlowApertures = structure.WidthFlowApertures;

            Assert.AreEqual(2, widthFlowApertures.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(456.79, widthFlowApertures.Mean, widthFlowApertures.Mean.GetAccuracy());
            Assert.AreEqual(2, widthFlowApertures.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.46, widthFlowApertures.StandardDeviation, widthFlowApertures.StandardDeviation.GetAccuracy());

            NormalDistribution levelCrestStructureNotClosing = structure.LevelCrestStructureNotClosing;

            Assert.AreEqual(2, levelCrestStructureNotClosing.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(567.89, levelCrestStructureNotClosing.Mean, levelCrestStructureNotClosing.Mean.GetAccuracy());
            Assert.AreEqual(2, levelCrestStructureNotClosing.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.57, levelCrestStructureNotClosing.StandardDeviation, levelCrestStructureNotClosing.StandardDeviation.GetAccuracy());

            NormalDistribution insideWaterLevel = structure.InsideWaterLevel;

            Assert.AreEqual(2, insideWaterLevel.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(678.90, insideWaterLevel.Mean, insideWaterLevel.Mean.GetAccuracy());
            Assert.AreEqual(2, insideWaterLevel.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.68, insideWaterLevel.StandardDeviation, insideWaterLevel.StandardDeviation.GetAccuracy());

            NormalDistribution thresholdHeightOpenWeir = structure.ThresholdHeightOpenWeir;

            Assert.AreEqual(2, thresholdHeightOpenWeir.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(789.01, thresholdHeightOpenWeir.Mean, thresholdHeightOpenWeir.Mean.GetAccuracy());
            Assert.AreEqual(2, thresholdHeightOpenWeir.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.79, thresholdHeightOpenWeir.StandardDeviation, thresholdHeightOpenWeir.StandardDeviation.GetAccuracy());

            LogNormalDistribution areaFlowApertures = structure.AreaFlowApertures;

            Assert.AreEqual(2, areaFlowApertures.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(890.12, areaFlowApertures.Mean, areaFlowApertures.Mean.GetAccuracy());
            Assert.AreEqual(2, areaFlowApertures.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.89, areaFlowApertures.StandardDeviation, areaFlowApertures.StandardDeviation.GetAccuracy());

            VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge = structure.CriticalOvertoppingDischarge;

            Assert.AreEqual(2, criticalOvertoppingDischarge.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(901.23, criticalOvertoppingDischarge.Mean, criticalOvertoppingDischarge.Mean.GetAccuracy());
            Assert.AreEqual(2, criticalOvertoppingDischarge.CoefficientOfVariation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.90, criticalOvertoppingDischarge.CoefficientOfVariation, criticalOvertoppingDischarge.CoefficientOfVariation.GetAccuracy());

            LogNormalDistribution flowWidthAtBottomProtection = structure.FlowWidthAtBottomProtection;

            Assert.AreEqual(2, flowWidthAtBottomProtection.Mean.NumberOfDecimalPlaces);
            Assert.AreEqual(111.22, flowWidthAtBottomProtection.Mean, flowWidthAtBottomProtection.Mean.GetAccuracy());
            Assert.AreEqual(2, flowWidthAtBottomProtection.StandardDeviation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.11, flowWidthAtBottomProtection.StandardDeviation, flowWidthAtBottomProtection.StandardDeviation.GetAccuracy());

            Assert.AreEqual(321.987, structure.ProbabilityOpenStructureBeforeFlooding);
            Assert.AreEqual(654.321, structure.FailureProbabilityOpenStructure);
            Assert.AreEqual(42, structure.IdenticalApertures);
            Assert.AreEqual(987.654, structure.FailureProbabilityReparation);

            Assert.AreEqual(ClosingStructureInflowModelType.LowSill, structure.InflowModelType);
        }
        public void UpdateStructuresWithImportedData_SingleChange_UpdatesOnlySingleChange(ClosingStructure readStructure)
        {
            // Setup
            ClosingStructure structure = new TestClosingStructure();

            var failureMechanism = new ClosingStructuresFailureMechanism();
            StructureCollection <ClosingStructure> targetCollection = failureMechanism.ClosingStructures;

            targetCollection.AddRange(new[]
            {
                structure
            }, sourceFilePath);
            var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[]
            {
                readStructure
            },
                                                                                                  sourceFilePath);

            // Assert
            AssertClosingStructures(readStructure, structure);
            CollectionAssert.AreEqual(new IObservable[]
            {
                targetCollection,
                structure
            }, affectedObjects);
        }
        public void Read_ValidEntity_ReturnClosingStructure()
        {
            // Setup
            var entity = new ClosingStructureEntity
            {
                Name = "A",
                Id   = "B",
                X    = 1.1,
                Y    = 2.2,
                StructureNormalOrientation = 3.3,
                StorageStructureAreaMean   = 4.4,
                StorageStructureAreaCoefficientOfVariation   = 5.5,
                AllowedLevelIncreaseStorageMean              = 6.6,
                AllowedLevelIncreaseStorageStandardDeviation = 7.7,
                WidthFlowAperturesMean = 8.8,
                WidthFlowAperturesStandardDeviation            = 9.9,
                LevelCrestStructureNotClosingMean              = 10.10,
                LevelCrestStructureNotClosingStandardDeviation = 11.11,
                InsideWaterLevelMean = 12.12,
                InsideWaterLevelStandardDeviation        = 13.13,
                ThresholdHeightOpenWeirMean              = 14.14,
                ThresholdHeightOpenWeirStandardDeviation = 15.15,
                AreaFlowAperturesMean = 16.16,
                AreaFlowAperturesStandardDeviation = 17.17,
                CriticalOvertoppingDischargeMean   = 18.18,
                CriticalOvertoppingDischargeCoefficientOfVariation = 19.19,
                FlowWidthAtBottomProtectionMean = 20.20,
                FlowWidthAtBottomProtectionStandardDeviation = 21.21,
                ProbabilityOpenStructureBeforeFlooding       = 22.22,
                FailureProbabilityOpenStructure = 23.23,
                IdenticalApertures           = 24,
                FailureProbabilityReparation = 25.25,
                InflowModelType = Convert.ToByte(ClosingStructureInflowModelType.FloodedCulvert)
            };

            var collector = new ReadConversionCollector();

            // Call
            ClosingStructure 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.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);
            Assert.AreEqual(entity.WidthFlowAperturesMean, structure.WidthFlowApertures.Mean.Value);
            Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, structure.WidthFlowApertures.StandardDeviation.Value);
            Assert.AreEqual(entity.LevelCrestStructureNotClosingMean, structure.LevelCrestStructureNotClosing.Mean.Value);
            Assert.AreEqual(entity.LevelCrestStructureNotClosingStandardDeviation, structure.LevelCrestStructureNotClosing.StandardDeviation.Value);
            Assert.AreEqual(entity.InsideWaterLevelMean, structure.InsideWaterLevel.Mean.Value);
            Assert.AreEqual(entity.InsideWaterLevelStandardDeviation, structure.InsideWaterLevel.StandardDeviation.Value);
            Assert.AreEqual(entity.ThresholdHeightOpenWeirMean, structure.ThresholdHeightOpenWeir.Mean.Value);
            Assert.AreEqual(entity.ThresholdHeightOpenWeirStandardDeviation, structure.ThresholdHeightOpenWeir.StandardDeviation.Value);
            Assert.AreEqual(entity.AreaFlowAperturesMean, structure.AreaFlowApertures.Mean.Value);
            Assert.AreEqual(entity.AreaFlowAperturesStandardDeviation, structure.AreaFlowApertures.StandardDeviation.Value);
            Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, structure.CriticalOvertoppingDischarge.Mean.Value);
            Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value);
            Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, structure.FlowWidthAtBottomProtection.Mean.Value);
            Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation.Value);
            Assert.AreEqual(entity.ProbabilityOpenStructureBeforeFlooding, structure.ProbabilityOpenStructureBeforeFlooding);
            Assert.AreEqual(entity.FailureProbabilityOpenStructure, structure.FailureProbabilityOpenStructure);
            Assert.AreEqual(entity.IdenticalApertures, structure.IdenticalApertures);
            Assert.AreEqual(entity.FailureProbabilityReparation, structure.FailureProbabilityReparation);
            Assert.AreEqual((ClosingStructureInflowModelType)entity.InflowModelType, structure.InflowModelType);

            Assert.IsTrue(collector.Contains(entity));
        }
        public void UpdateStructuresWithImportedData_MultipleCalculationWithStructureOneWithRemovedStructure_OnlyUpdatesCalculationWithRemovedStructure()
        {
            // Setup
            const string removedId               = "affectedId";
            const string unaffectedId            = "unaffectedId";
            const string unaffectedStructureName = "unaffectedStructure";
            var          removedStructure        = new TestClosingStructure(removedId, "Old name");
            var          unaffectedStructure     = new TestClosingStructure(unaffectedId, unaffectedStructureName);

            var affectedCalculation = new TestClosingStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = removedStructure
                },
                Output = new TestStructuresOutput()
            };

            var unaffectedCalculation = new TestClosingStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = unaffectedStructure
                },
                Output = new TestStructuresOutput()
            };

            var failureMechanism = new ClosingStructuresFailureMechanism
            {
                CalculationsGroup =
                {
                    Children =
                    {
                        affectedCalculation,
                        unaffectedCalculation
                    }
                }
            };

            StructureCollection <ClosingStructure> targetDataCollection = failureMechanism.ClosingStructures;

            targetDataCollection.AddRange(new[]
            {
                removedStructure,
                unaffectedStructure
            }, sourceFilePath);

            var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism);

            ClosingStructure readUnaffectedStructure = new TestClosingStructure(unaffectedId, unaffectedStructureName);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[]
            {
                readUnaffectedStructure
            }, sourceFilePath);

            // Assert
            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.IsNull(affectedCalculation.InputParameters.Structure);

            Assert.IsTrue(unaffectedCalculation.HasOutput);
            ClosingStructure inputParametersUnaffectedStructure = unaffectedCalculation.InputParameters.Structure;

            Assert.AreSame(unaffectedStructure, inputParametersUnaffectedStructure);
            AssertClosingStructures(readUnaffectedStructure, inputParametersUnaffectedStructure);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                targetDataCollection
            }, affectedObjects);
        }
        public void Read_NullValues_ReturnClosingStructureWithNaN()
        {
            // Setup
            var entity = new ClosingStructureEntity
            {
                Name = "A",
                Id   = "B",
                X    = null,
                Y    = null,
                StructureNormalOrientation = null,
                StorageStructureAreaMean   = null,
                StorageStructureAreaCoefficientOfVariation   = null,
                AllowedLevelIncreaseStorageMean              = null,
                AllowedLevelIncreaseStorageStandardDeviation = null,
                WidthFlowAperturesMean = null,
                WidthFlowAperturesStandardDeviation            = null,
                LevelCrestStructureNotClosingMean              = null,
                LevelCrestStructureNotClosingStandardDeviation = null,
                InsideWaterLevelMean = null,
                InsideWaterLevelStandardDeviation        = null,
                ThresholdHeightOpenWeirMean              = null,
                ThresholdHeightOpenWeirStandardDeviation = null,
                AreaFlowAperturesMean = null,
                AreaFlowAperturesStandardDeviation = null,
                CriticalOvertoppingDischargeMean   = null,
                CriticalOvertoppingDischargeCoefficientOfVariation = null,
                FlowWidthAtBottomProtectionMean = null,
                FlowWidthAtBottomProtectionStandardDeviation = null,
                ProbabilityOpenStructureBeforeFlooding       = null,
                FailureProbabilityOpenStructure = null
            };

            var collector = new ReadConversionCollector();

            // Call
            ClosingStructure structure = entity.Read(collector);

            // Assert
            Assert.IsNaN(structure.Location.X);
            Assert.IsNaN(structure.Location.Y);
            Assert.IsNaN(structure.StructureNormalOrientation);

            Assert.IsNaN(structure.StorageStructureArea.Mean);
            Assert.IsNaN(structure.StorageStructureArea.CoefficientOfVariation);
            Assert.IsNaN(structure.AllowedLevelIncreaseStorage.Mean);
            Assert.IsNaN(structure.AllowedLevelIncreaseStorage.StandardDeviation);
            Assert.IsNaN(structure.WidthFlowApertures.Mean);
            Assert.IsNaN(structure.WidthFlowApertures.StandardDeviation);
            Assert.IsNaN(structure.LevelCrestStructureNotClosing.Mean);
            Assert.IsNaN(structure.LevelCrestStructureNotClosing.StandardDeviation);
            Assert.IsNaN(structure.InsideWaterLevel.Mean);
            Assert.IsNaN(structure.InsideWaterLevel.StandardDeviation);
            Assert.IsNaN(structure.ThresholdHeightOpenWeir.Mean);
            Assert.IsNaN(structure.ThresholdHeightOpenWeir.StandardDeviation);
            Assert.IsNaN(structure.AreaFlowApertures.Mean);
            Assert.IsNaN(structure.AreaFlowApertures.StandardDeviation);
            Assert.IsNaN(structure.CriticalOvertoppingDischarge.Mean);
            Assert.IsNaN(structure.CriticalOvertoppingDischarge.CoefficientOfVariation);
            Assert.IsNaN(structure.FlowWidthAtBottomProtection.Mean);
            Assert.IsNaN(structure.FlowWidthAtBottomProtection.StandardDeviation);
            Assert.IsNaN(structure.ProbabilityOpenStructureBeforeFlooding);
            Assert.IsNaN(structure.FailureProbabilityOpenStructure);
            Assert.IsNaN(structure.FailureProbabilityReparation);
        }