public void ScenariosView_ImportFailureMechanismSections_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            using (var form = new Form())
            {
                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);

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

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

                // Precondition
                CollectionAssert.IsEmpty(listBox.Items);

                // Call
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);
                assessmentSection.ClosingStructures.NotifyObservers();

                // Assert
                CollectionAssert.AreEqual(assessmentSection.ClosingStructures.Sections, listBox.Items);
            }
        }
Esempio n. 2
0
        public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnTrue()
        {
            // Setup
            var relatedFailureMechanism = new ClosingStructuresFailureMechanism();

            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[]
            {
                relatedFailureMechanism
            });
            mocks.ReplayAll();

            using (var view = new ClosingStructuresScenariosView(relatedFailureMechanism.CalculationsGroup, relatedFailureMechanism))
            {
                // Precondition
                Assert.AreSame(view.Data, relatedFailureMechanism.CalculationsGroup);

                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
        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();
        }
Esempio n. 4
0
        private void ShowClosingStructuresScenariosView(ClosingStructuresFailureMechanism failureMechanism)
        {
            var scenariosView = new ClosingStructuresScenariosView(failureMechanism.CalculationsGroup, failureMechanism);

            testForm.Controls.Add(scenariosView);
            testForm.Show();
        }
Esempio n. 5
0
        public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnFalse()
        {
            using (var view = new ClosingStructuresScenariosView(new CalculationGroup(), new ClosingStructuresFailureMechanism()))
            {
                // Call
                bool closeForData = info.CloseForData(view, new ClosingStructuresFailureMechanism());

                // Assert
                Assert.IsFalse(closeForData);
            }
        }
Esempio n. 6
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var calculationGroup = new CalculationGroup();

            // Call
            using (var view = new ClosingStructuresScenariosView(calculationGroup, new ClosingStructuresFailureMechanism()))
            {
                // Assert
                Assert.IsInstanceOf <ScenariosView <StructuresCalculationScenario <ClosingStructuresInput>, ClosingStructuresInput, ClosingStructuresScenarioRow, ClosingStructuresFailureMechanism> >(view);
                Assert.AreSame(calculationGroup, view.Data);
            }
        }
Esempio n. 7
0
        public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnTrue()
        {
            // Setup
            var correspondingFailureMechanism = new ClosingStructuresFailureMechanism();

            using (var view = new ClosingStructuresScenariosView(correspondingFailureMechanism.CalculationsGroup, correspondingFailureMechanism))
            {
                // Call
                bool closeForData = info.CloseForData(view, correspondingFailureMechanism);

                // Assert
                Assert.IsTrue(closeForData);
            }
        }
Esempio n. 8
0
        private static bool CloseScenariosViewForData(ClosingStructuresScenariosView view, object dataToCloseFor)
        {
            var failureMechanism = dataToCloseFor as ClosingStructuresFailureMechanism;

            if (dataToCloseFor is IAssessmentSection assessmentSection)
            {
                failureMechanism = assessmentSection.GetFailureMechanisms()
                                   .OfType <ClosingStructuresFailureMechanism>()
                                   .FirstOrDefault();
            }

            if (dataToCloseFor is IFailureMechanismContext <ClosingStructuresFailureMechanism> failureMechanismContext)
            {
                failureMechanism = failureMechanismContext.WrappedData;
            }

            return(failureMechanism != null && ReferenceEquals(view.Data, failureMechanism.CalculationsGroup));
        }
Esempio n. 9
0
        public void CloseForData_AssessmentSectionRemovedWithoutClosingStructuresFailureMechanism_ReturnFalse()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]);
            mocks.ReplayAll();

            using (var view = new ClosingStructuresScenariosView(new CalculationGroup(), new ClosingStructuresFailureMechanism()))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Esempio n. 10
0
        public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new ClosingStructuresFailureMechanism();
            var context          = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSection);

            using (var view = new ClosingStructuresScenariosView(failureMechanism.CalculationsGroup, failureMechanism))
            {
                // Call
                bool closeForData = info.CloseForData(view, context);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
        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();
        }