Exemplo n.º 1
0
        private static bool ExportCalculationsForTargetProbability(
            Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double> calculationsForTargetProbability,
            HydraulicBoundaryLocationCalculationsType calculationsType,
            ICollection <string> exportedCalculationFileNames,
            string folderPath)
        {
            IEnumerable <HydraulicBoundaryLocationCalculation> calculations = calculationsForTargetProbability.Item1;
            double targetProbability = calculationsForTargetProbability.Item2;

            string exportType = calculationsType == HydraulicBoundaryLocationCalculationsType.WaterLevel
                                    ? Resources.WaterLevels_DisplayName
                                    : Resources.WaveHeights_DisplayName;

            string uniqueName = NamingHelper.GetUniqueName(
                exportedCalculationFileNames, $"{exportType}_{ReturnPeriodFormattingHelper.FormatFromProbability(targetProbability)}",
                c => c);

            exportedCalculationFileNames.Add(uniqueName);

            string tempFilePath = Path.Combine(folderPath, $"{uniqueName}.{RiskeerCommonIOResources.Shape_file_filter_Extension}");

            var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter(
                calculations, tempFilePath, calculationsType);

            return(exporter.Export());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="StrictContextMenuItem"/> which is bound to the action of duplicating a calculation item.
        /// </summary>
        /// <typeparam name="TCalculationItem">The type of the calculation item.</typeparam>
        /// <typeparam name="TCalculationItemContext">The type of the calculation item context.</typeparam>
        /// <param name="calculationItem">The calculation item to duplicate.</param>
        /// <param name="calculationItemContext">The calculation item context belonging to the calculation item.</param>
        /// <exception cref="ArgumentException">Thrown when the parent calculation group of
        /// <paramref name="calculationItem"/> equals <c>null</c>.</exception>
        /// <returns>The created <see cref="StrictContextMenuItem"/>.</returns>
        public static StrictContextMenuItem CreateDuplicateCalculationItem <TCalculationItem, TCalculationItemContext>(
            TCalculationItem calculationItem,
            TCalculationItemContext calculationItemContext)
            where TCalculationItemContext : ICalculationContext <TCalculationItem, ICalculatableFailureMechanism>
            where TCalculationItem : ICalculationBase
        {
            if (calculationItemContext.Parent == null)
            {
                throw new ArgumentException($"{nameof(calculationItemContext.Parent)} should be set.");
            }

            return(new StrictContextMenuItem(
                       Resources.Duplicate,
                       Resources.Duplicate_ToolTip,
                       Resources.CopyHS,
                       (o, args) =>
            {
                CalculationGroup parent = calculationItemContext.Parent;
                List <ICalculationBase> currentChildren = parent.Children;
                int calculationItemIndex = currentChildren.IndexOf(calculationItem);

                var copy = (TCalculationItem)calculationItem.Clone();
                copy.Name = NamingHelper.GetUniqueName(currentChildren,
                                                       string.Format(Resources.RiskeerContextMenuItemFactory_CreateDuplicateCalculationItem_Copy_of_item_with_name_0, calculationItem.Name),
                                                       c => c.Name);

                currentChildren.Insert(calculationItemIndex + 1, copy);
                parent.NotifyObservers();
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="existingFileName">The name of the file wich may include the path</param>
        /// <returns></returns>
        public static string GetUniqueFileName(string existingFileName)
        {
            if (existingFileName == null)
            {
                throw new ArgumentNullException("existingFileName");
            }

            var directory = Path.GetDirectoryName(existingFileName).Replace(Path.GetFileName(existingFileName), "");

            directory = string.IsNullOrEmpty(directory) ? "." : directory;

            // Declare a function to strip a file name which leaves out the extension
            Func <string, string> getFileNameWithoutExtension = Path.GetFileNameWithoutExtension;

            var searchString = string.Format("{0}*.*", getFileNameWithoutExtension(existingFileName));

            // get all items with the same name
            var items = Directory.GetFiles(directory, searchString);

            // make a list of INameable items where the Name property will get the name of the file
            var namedItems =
                items.Select(f => new FileName {
                Name = getFileNameWithoutExtension(f)
            });

            var newName = getFileNameWithoutExtension(existingFileName);

            if (namedItems.Any())
            {
                newName = NamingHelper.GetUniqueName(string.Format("{0} ({{0}})", newName), namedItems, typeof(INameable));
            }

            return(newName + Path.GetExtension(existingFileName));
        }
        /// <summary>
        /// Configures calculations and adds them to the calculation group.
        /// </summary>
        /// <param name="calculationGroup">The calculation group.</param>
        /// <param name="structures">The collection of structures.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static void GenerateCalculations <TStructureBase, TInputBase>(CalculationGroup calculationGroup, IEnumerable <TStructureBase> structures)
            where TStructureBase : StructureBase
            where TInputBase : StructuresInputBase <TStructureBase>, new()
        {
            if (calculationGroup == null)
            {
                throw new ArgumentNullException(nameof(calculationGroup));
            }

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

            foreach (TStructureBase structure in structures)
            {
                var calculation = new StructuresCalculationScenario <TInputBase>
                {
                    Name            = NamingHelper.GetUniqueName(calculationGroup.Children, structure.Name, c => c.Name),
                    InputParameters =
                    {
                        Structure = structure
                    }
                };
                calculationGroup.Children.Add(calculation);
            }
        }
        public void ScenariosView_ChangeStructureOfCalculation_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            var mocks           = new MockRepository();
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            using (var form = new Form())
            {
                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                var view = new ClosingStructuresScenariosView(assessmentSection.ClosingStructures.CalculationsGroup, assessmentSection.ClosingStructures);
                form.Controls.Add(view);
                form.Show();

                var structuresImporter = new ClosingStructuresImporter(assessmentSection.ClosingStructures.ClosingStructures,
                                                                       assessmentSection.ReferenceLine, filePath, messageProvider,
                                                                       new ClosingStructureReplaceDataStrategy(failureMechanism));
                structuresImporter.Import();

                foreach (ClosingStructure structure in assessmentSection.ClosingStructures.ClosingStructures)
                {
                    assessmentSection.ClosingStructures.CalculationsGroup.Children.Add(new StructuresCalculationScenario <ClosingStructuresInput>
                    {
                        Name            = NamingHelper.GetUniqueName(assessmentSection.ClosingStructures.CalculationsGroup.Children, structure.Name + " Calculation", c => c.Name),
                        InputParameters =
                        {
                            Structure = structure
                        }
                    });
                }

                var listBox      = (ListBox) new ControlTester("listBox").TheObject;
                var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

                listBox.SelectedItem = failureMechanism.Sections.ElementAt(32);

                // Precondition
                DataGridViewRowCollection rows = dataGridView.Rows;
                Assert.AreEqual(1, rows.Count);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue);

                // Call
                CalculationGroup calculationsGroup = assessmentSection.ClosingStructures.CalculationsGroup;
                ((StructuresCalculation <ClosingStructuresInput>)calculationsGroup.Children[1]).InputParameters.Structure =
                    ((StructuresCalculation <ClosingStructuresInput>)calculationsGroup.Children[0]).InputParameters.Structure;
                calculationsGroup.NotifyObservers();

                // Assert
                Assert.AreEqual(2, rows.Count);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue);
                Assert.AreEqual("Tweede kunstwerk sluiting 6-3 Calculation", rows[1].Cells[nameColumnIndex].FormattedValue);
            }

            mocks.VerifyAll();
        }
        /// <summary>
        /// Adds target probability related meta data to the given <paramref name="feature"/>.
        /// </summary>
        /// <param name="feature">The feature to add the meta data to.</param>
        /// <param name="targetProbabilities">The collection of target probabilities to add.</param>
        /// <param name="displayNameFormat">The display name format of the meta data.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="FormatException">Thrown when <paramref name="displayNameFormat"/> is invalid;
        /// or the index of a format item is not zero.</exception>
        public static void AddTargetProbabilityMetaData(MapFeature feature, IEnumerable <Tuple <double, RoundedDouble> > targetProbabilities, string displayNameFormat)
        {
            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }

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

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

            var addedMetaDataItems = new List <string>();

            foreach (Tuple <double, RoundedDouble> calculationOutputForTargetProbability in targetProbabilities)
            {
                string uniqueName = NamingHelper.GetUniqueName(
                    addedMetaDataItems, string.Format(displayNameFormat, ProbabilityFormattingHelper.Format(calculationOutputForTargetProbability.Item1)),
                    v => v);

                feature.MetaData[uniqueName] = calculationOutputForTargetProbability.Item2.ToString();
                addedMetaDataItems.Add(uniqueName);
            }
        }
        /// <summary>
        /// Configures calculations and adds them to the calculation group.
        /// </summary>
        /// <param name="calculationGroup">The calculation group.</param>
        /// <param name="dikeProfiles">The collection of dike profiles.</param>
        /// <param name="failureMechanismContribution">The <see cref="FailureMechanismContribution"/>
        /// used to get the default target probability.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static void GenerateCalculations(CalculationGroup calculationGroup, IEnumerable <DikeProfile> dikeProfiles,
                                                FailureMechanismContribution failureMechanismContribution)
        {
            if (calculationGroup == null)
            {
                throw new ArgumentNullException(nameof(calculationGroup));
            }

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

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

            foreach (DikeProfile profile in dikeProfiles)
            {
                var calculation = new GrassCoverErosionInwardsCalculationScenario
                {
                    Name            = NamingHelper.GetUniqueName(calculationGroup.Children, profile.Name, c => c.Name),
                    InputParameters =
                    {
                        DikeProfile                      = profile,
                        DikeHeightTargetProbability      = failureMechanismContribution.NormativeProbability,
                        OvertoppingRateTargetProbability = failureMechanismContribution.NormativeProbability
                    }
                };
                calculationGroup.Children.Add(calculation);
            }
        }
Exemplo n.º 8
0
        public void GetUniqueName()
        {
            var methods = typeof(MyClassN).GetMethods().Where(p => p.Name == "MethodA").ToArray();

            Assert.AreEqual("MethodA", NamingHelper.GetUniqueName(methods[0]));
            Assert.AreEqual("MethodA_1", NamingHelper.GetUniqueName(methods[1]));
            Assert.AreEqual("MethodA_2", NamingHelper.GetUniqueName(methods[2]));
            Assert.AreEqual("MethodA_3", NamingHelper.GetUniqueName(methods[3]));
        }
Exemplo n.º 9
0
        private static void CreateCalculationGroup(CalculationGroup calculationGroup)
        {
            calculationGroup.Children.Add(new CalculationGroup
            {
                Name = NamingHelper.GetUniqueName(calculationGroup.Children, RiskeerCommonDataResources.CalculationGroup_DefaultName, c => c.Name)
            });

            calculationGroup.NotifyObservers();
        }
Exemplo n.º 10
0
        private static void AddCalculation(ClosingStructuresCalculationGroupContext context)
        {
            var calculation = new StructuresCalculationScenario <ClosingStructuresInput>
            {
                Name = NamingHelper.GetUniqueName(context.WrappedData.Children, RiskeerCommonDataResources.Calculation_DefaultName, c => c.Name)
            };

            context.WrappedData.Children.Add(calculation);
            context.WrappedData.NotifyObservers();
        }
Exemplo n.º 11
0
        public void GetUniqueName_EmptyCollection_ReturnNameBase()
        {
            // Setup
            const string nameBase = "The basic name";

            IEnumerable <ObjectWithName> existingObjects = Enumerable.Empty <ObjectWithName>();

            // Call
            string name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);

            // Assert
            Assert.AreEqual(nameBase, name);
        }
Exemplo n.º 12
0
        private static void AssertMetaData(IEnumerable <HydraulicBoundaryLocationCalculation> calculations, HydraulicBoundaryLocation hydraulicBoundaryLocation,
                                           MapFeature mapFeature, double targetProbability, string displayName, List <string> presentedMetaDataItems)
        {
            string uniqueName = NamingHelper.GetUniqueName(
                presentedMetaDataItems, string.Format(displayName, ProbabilityFormattingHelper.Format(targetProbability)),
                v => v);

            MapFeaturesMetaDataTestHelper.AssertMetaData(
                GetExpectedResult(calculations, hydraulicBoundaryLocation),
                mapFeature, uniqueName);

            presentedMetaDataItems.Add(uniqueName);
        }
        private bool ExportCalculationGroup(CalculationGroup nestedGroup, string currentFolderPath, List <string> exportedGroups)
        {
            string uniqueGroupName = NamingHelper.GetUniqueName(exportedGroups, nestedGroup.Name, group => group);

            bool exportSucceeded = ExportCalculationItemsRecursively(nestedGroup, Path.Combine(currentFolderPath, uniqueGroupName));

            if (!exportSucceeded)
            {
                return(false);
            }

            exportedGroups.Add(uniqueGroupName);
            return(true);
        }
Exemplo n.º 14
0
        private static void AddWaveConditionsCalculation(WaveImpactAsphaltCoverCalculationGroupContext nodeData)
        {
            var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation
            {
                Name = NamingHelper.GetUniqueName(nodeData.WrappedData.Children,
                                                  RiskeerCommonDataResources.Calculation_DefaultName,
                                                  c => c.Name)
            };

            WaveConditionsInputHelper.SetWaterLevelType(calculation.InputParameters,
                                                        nodeData.AssessmentSection.FailureMechanismContribution.NormativeProbabilityType);
            nodeData.WrappedData.Children.Add(calculation);
            nodeData.WrappedData.NotifyObservers();
        }
Exemplo n.º 15
0
        public void GetUniqueName()
        {
            var item1 = mocks.Stub <INameable>();
            var item2 = mocks.Stub <INameable>();
            var item3 = mocks.Stub <INameable>();

            item1.Name = "one (1)";
            item2.Name = "one";
            item3.Name = "INameable1";

            var namedItems = new List <INameable>(new[] { item1, item2, item3 });

            Assert.AreEqual("INameable2", NamingHelper.GetUniqueName(null, namedItems, typeof(INameable)));
            Assert.AreEqual("one (2)", NamingHelper.GetUniqueName("one ({0})", namedItems, typeof(INameable)));
        }
Exemplo n.º 16
0
        public void GetUniqueName_CollectionWithNamedObjectMatchingNameBase_ReturnNameBaseAppendedWithPostfixIncrement()
        {
            // Setup
            const string nameBase = "The basic name";

            var existingObjects = new[]
            {
                new ObjectWithName(nameBase)
            };

            // Call
            string name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);

            // Assert
            Assert.AreEqual(nameBase + " (1)", name);
        }
Exemplo n.º 17
0
        public void GetUniqueName_CollectionWithNamedObjectNotMatchingNameBase_ReturnNameBase()
        {
            // Setup
            const string nameBase = "The basic name";

            var existingObjects = new[]
            {
                new ObjectWithName("Something original!")
            };

            // Call
            string name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);

            // Assert
            Assert.AreEqual(nameBase, name);
        }
Exemplo n.º 18
0
        private static ICalculationBase CreateMacroStabilityInwardsCalculation(MacroStabilityInwardsSurfaceLine surfaceLine, MacroStabilityInwardsStochasticSoilModel stochasticSoilModel, MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile, IEnumerable <ICalculationBase> calculations)
        {
            string nameBase = $"{surfaceLine.Name} {stochasticSoilProfile}";
            string name     = NamingHelper.GetUniqueName(calculations, nameBase, c => c.Name);

            return(new MacroStabilityInwardsCalculationScenario
            {
                Name = name,
                InputParameters =
                {
                    SurfaceLine           = surfaceLine,
                    StochasticSoilModel   = stochasticSoilModel,
                    StochasticSoilProfile = stochasticSoilProfile
                },
                Contribution = (RoundedDouble)stochasticSoilProfile.Probability
            });
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a calculation and sets the <paramref name="hydraulicBoundaryLocation"/>
        /// and the water level type on its input.
        /// </summary>
        /// <param name="hydraulicBoundaryLocation">The <see cref="HydraulicBoundaryLocation"/> to set.</param>
        /// <param name="calculations">The list of calculations to base the calculation name from.</param>
        /// <param name="normativeProbabilityType">The <see cref="NormativeProbabilityType"/> to base the water level type input on.</param>
        /// <returns>An <see cref="ICalculationBase"/> representing a stability stone cover calculation.</returns>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="normativeProbabilityType"/> is an invalid value.</exception>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="normativeProbabilityType"/> is a valid value,
        /// but unsupported.</exception>
        private static ICalculationBase CreateStabilityStoneCoverWaveConditionsCalculation(
            HydraulicBoundaryLocation hydraulicBoundaryLocation,
            IEnumerable <ICalculationBase> calculations,
            NormativeProbabilityType normativeProbabilityType)
        {
            string nameBase    = hydraulicBoundaryLocation.Name;
            var    calculation = new StabilityStoneCoverWaveConditionsCalculation
            {
                Name            = NamingHelper.GetUniqueName(calculations, nameBase, c => c.Name),
                InputParameters =
                {
                    HydraulicBoundaryLocation = hydraulicBoundaryLocation
                }
            };

            WaveConditionsInputHelper.SetWaterLevelType(calculation.InputParameters, normativeProbabilityType);
            return(calculation);
        }
Exemplo n.º 20
0
        private static TCalculationScenario CreateCalculationScenario <TCalculationScenario>(
            PipingSurfaceLine surfaceLine, PipingStochasticSoilModel stochasticSoilModel, PipingStochasticSoilProfile stochasticSoilProfile,
            IEnumerable <ICalculationBase> calculations)
            where TCalculationScenario : IPipingCalculationScenario <PipingInput>, new()
        {
            var    nameBase = $"{surfaceLine.Name} {stochasticSoilProfile}";
            string name     = NamingHelper.GetUniqueName(calculations.OfType <TCalculationScenario>(), nameBase, c => c.Name);

            return(new TCalculationScenario
            {
                Name = name,
                InputParameters =
                {
                    SurfaceLine           = surfaceLine,
                    StochasticSoilModel   = stochasticSoilModel,
                    StochasticSoilProfile = stochasticSoilProfile
                },
                Contribution = (RoundedDouble)stochasticSoilProfile.Probability
            });
        }
        private bool ExportCalculation(MacroStabilityInwardsCalculation calculation, string currentFolderPath, List <string> exportedCalculations)
        {
            string uniqueName          = NamingHelper.GetUniqueName(exportedCalculations, ((ICalculationBase)calculation).Name, c => c);
            string calculationFilePath = GetCalculationFilePath(currentFolderPath, uniqueName);

            var exporter = new MacroStabilityInwardsCalculationExporter(calculation, generalInput, persistenceFactory, calculationFilePath, () => getNormativeAssessmentLevelFunc(calculation));

            bool exportSucceeded = exporter.Export();

            if (!exportSucceeded)
            {
                log.ErrorFormat("{0} {1}", string.Format(Resources.MacroStabilityInwardsCalculationGroupExporter_ExportCalculation_Unexpected_error_during_export_CalculationName_0, calculation.Name),
                                Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported);
                return(false);
            }

            exportedCalculations.Add(uniqueName);
            itemExported = true;
            return(true);
        }
Exemplo n.º 22
0
        private string GetInvocationTypeName()
        {
            MethodInfo     method         = methodDefinition.Method;
            TypeDefinition typeDefinition = methodDefinition.TypeDefinition;
            string         proxyPartName;

            if (typeDefinition.TypeDefinitionType == TypeDefinitionType.Mixin)
            {
                proxyPartName = ((MixinDefinition)typeDefinition).ProxyTypeDefinition.Name;
            }
            else
            {
                proxyPartName = typeDefinition.Name;
            }

            if (method.DeclaringType != methodDefinition.TypeDefinition.Type)
            {
                return($"{proxyPartName}_{method.DeclaringType.Name}_{NamingHelper.GetUniqueName(method)}_Invocation");
            }
            else
            {
                return($"{proxyPartName}_{NamingHelper.GetUniqueName(method)}_Invocation");
            }
        }
        public void ScenariosView_GenerateCalculations_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            var mocks           = new MockRepository();
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            using (var form = new Form())
            {
                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                CalculationGroup calculationsGroup = assessmentSection.ClosingStructures.CalculationsGroup;
                var view = new ClosingStructuresScenariosView(calculationsGroup, assessmentSection.ClosingStructures);

                form.Controls.Add(view);
                form.Show();

                var structuresImporter = new ClosingStructuresImporter(assessmentSection.ClosingStructures.ClosingStructures,
                                                                       assessmentSection.ReferenceLine, filePath, messageProvider,
                                                                       new ClosingStructureReplaceDataStrategy(failureMechanism));
                structuresImporter.Import();

                var listBox      = (ListBox) new ControlTester("listBox").TheObject;
                var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

                listBox.SelectedItem = failureMechanism.Sections.ElementAt(32);

                // Precondition
                DataGridViewRowCollection rows = dataGridView.Rows;
                CollectionAssert.IsEmpty(rows);

                // Call
                foreach (ClosingStructure structure in assessmentSection.ClosingStructures.ClosingStructures)
                {
                    calculationsGroup.Children.Add(new StructuresCalculationScenario <ClosingStructuresInput>
                    {
                        Name            = NamingHelper.GetUniqueName(((CalculationGroup)view.Data).Children, structure.Name, c => c.Name),
                        InputParameters =
                        {
                            Structure = structure
                        }
                    });
                }

                calculationsGroup.NotifyObservers();

                // Assert
                Assert.AreEqual(1, rows.Count);

                DataGridViewCellCollection cells = rows[0].Cells;
                Assert.AreEqual(4, cells.Count);
                Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue));
                Assert.AreEqual(new RoundedDouble(2, 100).ToString(), cells[contributionColumnIndex].FormattedValue);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3", cells[nameColumnIndex].FormattedValue);
                Assert.AreEqual("-", cells[failureProbabilityColumnIndex].FormattedValue);
            }

            mocks.VerifyAll();
        }
Exemplo n.º 24
0
 public void GetUniqueNameWithInvalidFilter()
 {
     NamingHelper.GetUniqueName("invalidfilter", new INameable[] { }, null);
 }
        public void ScenariosView_ChangeDikeProfileOfCalculation_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            using (var form = new Form())
            {
                var mocks           = new MockRepository();
                var messageProvider = mocks.Stub <IImporterMessageProvider>();
                mocks.ReplayAll();

                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);
                GrassCoverErosionInwardsFailureMechanism failureMechanism = assessmentSection.GrassCoverErosionInwards;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                var view = new GrassCoverErosionInwardsScenariosView(assessmentSection.GrassCoverErosionInwards.CalculationsGroup,
                                                                     assessmentSection.GrassCoverErosionInwards);
                form.Controls.Add(view);
                form.Show();

                var dikeProfilesImporter = new DikeProfilesImporter(assessmentSection.GrassCoverErosionInwards.DikeProfiles,
                                                                    assessmentSection.ReferenceLine, filePath,
                                                                    new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism),
                                                                    messageProvider);
                dikeProfilesImporter.Import();

                foreach (DikeProfile profile in assessmentSection.GrassCoverErosionInwards.DikeProfiles)
                {
                    assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculationScenario
                    {
                        Name            = NamingHelper.GetUniqueName(assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children, profile.Name + "Calculation", c => c.Name),
                        InputParameters =
                        {
                            DikeProfile = profile
                        }
                    });
                }

                var listBox      = (ListBox) new ControlTester("listBox").TheObject;
                var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

                listBox.SelectedItem = failureMechanism.Sections.ElementAt(13);

                // Precondition
                DataGridViewRowCollection rows = dataGridView.Rows;
                Assert.AreEqual(1, rows.Count);
                Assert.AreEqual("profiel63p1NaamCalculation", rows[0].Cells[nameColumnIndex].FormattedValue);

                // Call
                CalculationGroup calculationsGroup = assessmentSection.GrassCoverErosionInwards.CalculationsGroup;
                ((GrassCoverErosionInwardsCalculationScenario)calculationsGroup.Children[1]).InputParameters.DikeProfile =
                    ((GrassCoverErosionInwardsCalculationScenario)calculationsGroup.Children[0]).InputParameters.DikeProfile;
                calculationsGroup.NotifyObservers();

                // Assert
                Assert.AreEqual(2, rows.Count);
                Assert.AreEqual("profiel63p1NaamCalculation", rows[0].Cells[nameColumnIndex].FormattedValue);
                Assert.AreEqual("profiel63p2NaamCalculation", rows[1].Cells[nameColumnIndex].FormattedValue);

                mocks.VerifyAll();
            }
        }