Ejemplo n.º 1
0
            private static IEnumerable <TestCaseData> GetUnequalTestCases()
            {
                foreach (ChangePropertyData <HeightStructure.ConstructionProperties> changeSingleDataProperty in ChangeSingleDataProperties())
                {
                    HeightStructure.ConstructionProperties differentConstructionProperties = CreateConstructionProperties();
                    changeSingleDataProperty.ActionToChangeProperty(differentConstructionProperties);

                    yield return(new TestCaseData(new HeightStructure(differentConstructionProperties))
                                 .SetName(changeSingleDataProperty.PropertyName));
                }
            }
        /// <summary>
        /// Returns a collection of modified <see cref="HeightStructure"/> entities, which all differ
        /// except for their id, name and location.
        /// </summary>
        /// <param name="targetName">The name of the target to test while using the test case source.</param>
        /// <param name="testResultDescription">A description of the result of the test while using the test case source.</param>
        /// <returns>The collection of test case data.</returns>
        /// <example>
        /// <code>
        /// [TestCaseSource(
        ///     typeof(HeightStructurePermutationHelper),
        ///     nameof(HeightStructurePermutationHelper.DifferentHeightStructuresWithSameIdNameAndLocation),
        ///     new object[]
        ///     {
        ///         "TargetMethodName",
        ///         "TestResult"
        ///     })]
        /// </code>
        /// </example>
        public static IEnumerable <TestCaseData> DifferentHeightStructuresWithSameIdNameAndLocation(string targetName, string testResultDescription)
        {
            var random = new Random(532);

            yield return(new TestCaseData(new TestHeightStructure
            {
                AllowedLevelIncreaseStorage =
                {
                    Mean = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentAllowedLevelIncreaseStorageMean_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                AllowedLevelIncreaseStorage =
                {
                    StandardDeviation = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentAllowedLevelIncreaseStorageStandardDeviation_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                CriticalOvertoppingDischarge =
                {
                    Mean = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentCriticalOvertoppingDischargeMean_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                CriticalOvertoppingDischarge =
                {
                    CoefficientOfVariation = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentCriticalOvertoppingDischargeCoefficientOfVariation_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                FlowWidthAtBottomProtection =
                {
                    Mean = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentFlowWidthAtBottomProtectionMean_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                FlowWidthAtBottomProtection =
                {
                    StandardDeviation = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentFlowWidthAtBottomProtectionStandardDeviation_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                LevelCrestStructure =
                {
                    Mean = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentLevelCrestStructureMean_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                LevelCrestStructure =
                {
                    StandardDeviation = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentLevelCrestStructureStandardDeviation_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                StorageStructureArea =
                {
                    Mean = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentStorageStructureAreaMean_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                StorageStructureArea =
                {
                    CoefficientOfVariation = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentStorageStructureAreaCoefficientOfVariation_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                WidthFlowApertures =
                {
                    Mean = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentWidthFlowAperturesMean_{testResultDescription}"));

            yield return(new TestCaseData(new TestHeightStructure
            {
                WidthFlowApertures =
                {
                    StandardDeviation = random.NextRoundedDouble()
                }
            }).SetName($"{targetName}_DifferentWidthFlowAperturesStandardDeviation_{testResultDescription}"));

            HeightStructure.ConstructionProperties differentFailureProbabilityStructureWithErosionConstructionProperties = CreateTestHeightStructureConstructionProperties();
            differentFailureProbabilityStructureWithErosionConstructionProperties.FailureProbabilityStructureWithErosion = random.NextDouble();
            yield return(new TestCaseData(new HeightStructure(differentFailureProbabilityStructureWithErosionConstructionProperties))
                         .SetName($"{targetName}_DifferentFailureProbabilityStructureWithErosion_{testResultDescription}"));

            HeightStructure.ConstructionProperties differentStructureNormalOrientationConstructionProperties = CreateTestHeightStructureConstructionProperties();
            differentStructureNormalOrientationConstructionProperties.StructureNormalOrientation = random.NextRoundedDouble();
            yield return(new TestCaseData(new HeightStructure(differentStructureNormalOrientationConstructionProperties))
                         .SetName($"{targetName}_DifferentStructureNormalOrientation_{testResultDescription}"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="HeightStructure"/> based on the <paramref name="structureLocation"/>
        /// and property values defined by <paramref name="structureParameterRows"/>.
        /// </summary>
        /// <param name="structureLocation">The representation of the structure.</param>
        /// <param name="structureParameterRows">The parameters of the structure.</param>
        /// <returns>A <see cref="HeightStructure"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="structureParameterRows"/>
        /// contains an element with <see cref="StructuresParameterRow.ParameterId"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="structureParameterRows"/>
        /// contains a parameter definition with a duplicate name.</exception>
        private HeightStructure CreateHeightStructure(StructureLocation structureLocation,
                                                      IEnumerable <StructuresParameterRow> structureParameterRows)
        {
            Dictionary <string, StructuresParameterRow> rowData = structureParameterRows.ToDictionary(
                row => row.ParameterId, row => row, StringComparer.OrdinalIgnoreCase);

            string structureName          = structureLocation.Name;
            string structureId            = structureLocation.Id;
            var    constructionProperties = new HeightStructure.ConstructionProperties
            {
                Name     = structureName,
                Id       = structureId,
                Location = structureLocation.Point
            };

            TrySetConstructionProperty((rows, key) => constructionProperties.StructureNormalOrientation = (RoundedDouble)rows[key].NumericalValue,
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword1,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) =>
            {
                constructionProperties.LevelCrestStructure.Mean = (RoundedDouble)rows[key].NumericalValue;
                constructionProperties.LevelCrestStructure.StandardDeviation = GetStandardDeviation(rows[key], structureName);
            },
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword2,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) =>
            {
                constructionProperties.FlowWidthAtBottomProtection.Mean = (RoundedDouble)rows[key].NumericalValue;
                constructionProperties.FlowWidthAtBottomProtection.StandardDeviation = GetStandardDeviation(rows[key], structureName);
            },
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword3,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) =>
            {
                constructionProperties.CriticalOvertoppingDischarge.Mean = (RoundedDouble)rows[key].NumericalValue;
                constructionProperties.CriticalOvertoppingDischarge.CoefficientOfVariation = GetCoefficientOfVariation(rows[key], structureName);
            },
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword4,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) =>
            {
                constructionProperties.WidthFlowApertures.Mean = (RoundedDouble)rows[key].NumericalValue;
                constructionProperties.WidthFlowApertures.StandardDeviation = GetStandardDeviation(rows[key], structureName);
            },
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword5,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) => constructionProperties.FailureProbabilityStructureWithErosion = rows[key].NumericalValue,
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword6,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) =>
            {
                constructionProperties.StorageStructureArea.Mean = (RoundedDouble)rows[key].NumericalValue;
                constructionProperties.StorageStructureArea.CoefficientOfVariation = GetCoefficientOfVariation(rows[key], structureName);
            },
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword7,
                                       structureName,
                                       structureId);

            TrySetConstructionProperty((rows, key) =>
            {
                constructionProperties.AllowedLevelIncreaseStorage.Mean = (RoundedDouble)rows[key].NumericalValue;
                constructionProperties.AllowedLevelIncreaseStorage.StandardDeviation = GetStandardDeviation(rows[key], structureName);
            },
                                       rowData,
                                       StructureFilesKeywords.HeightStructureParameterKeyword8,
                                       structureName,
                                       structureId);

            return(new HeightStructure(constructionProperties));
        }