public void IsEnabled_FailureMechanismSectionsSourcePathSet_ReturnTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            string sourcePath = TestHelper.GetScratchPadPath();

            failureMechanism.SetSections(Enumerable.Empty <FailureMechanismSection>(), sourcePath);
            var context = new HeightStructuresFailureMechanismSectionsContext(failureMechanism, assessmentSection);

            using (var plugin = new HeightStructuresPlugin())
            {
                UpdateInfo importInfo = GetUpdateInfo(plugin);

                // Call
                bool isEnabled = importInfo.IsEnabled(context);

                // Assert
                Assert.IsTrue(isEnabled);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 2
0
        public void CalculationsView_FailureMechanismWithForeshoreProfiles_ForeshoreProfilesComboboxCorrectlyInitialized()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            ConfigureHydraulicBoundaryDatabase(assessmentSection);
            mocks.ReplayAll();

            HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism();

            // Call
            ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection);

            // Assert
            var dataGridView             = (DataGridView) new ControlTester("dataGridView").TheObject;
            var foreshoreProfileComboBox = (DataGridViewComboBoxColumn)dataGridView.Columns[foreshoreProfileColumnIndex];

            DataGridViewComboBoxCell.ObjectCollection foreshoreProfileComboBoxItems = foreshoreProfileComboBox.Items;
            Assert.AreEqual(3, foreshoreProfileComboBoxItems.Count);
            Assert.AreEqual("<selecteer>", foreshoreProfileComboBoxItems[0].ToString());
            Assert.AreEqual("Profiel 1", foreshoreProfileComboBoxItems[1].ToString());
            Assert.AreEqual("Profiel 2", foreshoreProfileComboBoxItems[2].ToString());
            mocks.VerifyAll();
        }
Ejemplo n.º 3
0
        public void CalculationsView_InvalidOvertoppingAndLevelIncreaseStorage_ShowsErrorTooltip(double newValue, int index)
        {
            // Setup
            var mocks = new MockRepository();
            var calculationObserver = mocks.StrictMock <IObserver>();
            var inputObserver       = mocks.StrictMock <IObserver>();
            var assessmentSection   = mocks.Stub <IAssessmentSection>();

            ConfigureHydraulicBoundaryDatabase(assessmentSection);
            mocks.ReplayAll();

            HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism();
            CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection);

            ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection);

            var calculation = (StructuresCalculationScenario <HeightStructuresInput>)calculationGroup.Children.First();

            calculation.Attach(calculationObserver);
            calculation.InputParameters.Attach(inputObserver);

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

            // Call
            dataGridView.Rows[0].Cells[index].Value = (RoundedDouble)newValue;

            // Assert
            Assert.AreEqual("Gemiddelde moet groter zijn dan 0.", dataGridView.Rows[0].ErrorText);
            mocks.VerifyAll(); // No observer notified
        }
        public void Create_WithHeightStructures_HeightStructureEntitiesCreated()
        {
            // Setup
            HeightStructure structure = new TestHeightStructure();

            var          failureMechanism = new HeightStructuresFailureMechanism();
            const string filePath         = "some/path/to/structures";

            failureMechanism.HeightStructures.AddRange(new[]
            {
                structure
            }, filePath);

            var persistenceRegistry = new PersistenceRegistry();

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry);

            // Assert
            Assert.AreEqual(1, entity.HeightStructureEntities.Count);
            Assert.IsTrue(persistenceRegistry.Contains(structure));

            HeightStructuresFailureMechanismMetaEntity metaEntity =
                entity.HeightStructuresFailureMechanismMetaEntities.Single();
            string metaEntityHeightStructureCollectionSourcePath = metaEntity.HeightStructureCollectionSourcePath;

            TestHelper.AssertAreEqualButNotSame(filePath, metaEntityHeightStructureCollectionSourcePath);
        }
        public void AssembleFailureMechanism_CalculatorThrowsException_ThrowsAssemblyException()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism
            {
                AssemblyResult =
                {
                    ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic
                }
            };

            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
                calculator.ThrowExceptionOnCalculate = true;

                // Call
                void Call() => HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);

                // Assert
                var       exception      = Assert.Throws <AssemblyException>(Call);
                Exception innerException = exception.InnerException;
                Assert.IsInstanceOf <FailureMechanismAssemblyCalculatorException>(innerException);
                Assert.AreEqual(innerException.Message, exception.Message);
            }
        }
        public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism();

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

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

            var view = new StructuresFailureMechanismResultView <HeightStructuresFailureMechanism, HeightStructuresInput>(
                failureMechanism.SectionResults, failureMechanism, assessmentSection,
                (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual));

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

            // Assert
            Assert.IsTrue(closeForData);
            mocks.VerifyAll();
        }
        private void ShowHeightStructuresScenariosView(HeightStructuresFailureMechanism failureMechanism)
        {
            var scenariosView = new HeightStructuresScenariosView(failureMechanism.CalculationsGroup, failureMechanism);

            testForm.Controls.Add(scenariosView);
            testForm.Show();
        }
Ejemplo n.º 8
0
        public void ChildNodeObjects_FailureMechanismInAssemblyFalse_ReturnChildDataNodes()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism
            {
                InAssembly = false
            };
            var context = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection);

            // Call
            object[] children = info.ChildNodeObjects(context).ToArray();

            // Assert
            Assert.AreEqual(1, children.Length);

            var comment = (Comment)children[0];

            Assert.AreSame(failureMechanism.NotInAssemblyComments, comment);

            mocks.VerifyAll();
        }
Ejemplo n.º 9
0
        public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveFailureMechanismDependentData()
        {
            // Setup
            HeightStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism();

            object[] expectedRemovedObjects = failureMechanism.Sections.OfType <object>()
                                              .Concat(failureMechanism.SectionResults)
                                              .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive())
                                              .Concat(failureMechanism.ForeshoreProfiles)
                                              .Concat(failureMechanism.HeightStructures)
                                              .ToArray();

            // Call
            ClearResults results = HeightStructuresDataSynchronizationService.ClearReferenceLineDependentData(failureMechanism);

            // Assert
            // Note: To make sure the clear is performed regardless of what is done with
            // the return result, no ToArray() should be called before these assertions:
            CollectionAssert.IsEmpty(failureMechanism.Sections);
            CollectionAssert.IsEmpty(failureMechanism.SectionResults);
            CollectionAssert.IsEmpty(failureMechanism.CalculationsGroup.Children);
            CollectionAssert.IsEmpty(failureMechanism.ForeshoreProfiles);
            CollectionAssert.IsEmpty(failureMechanism.HeightStructures);

            IObservable[] array = results.ChangedObjects.ToArray();
            Assert.AreEqual(5, array.Length);
            CollectionAssert.Contains(array, failureMechanism);
            CollectionAssert.Contains(array, failureMechanism.SectionResults);
            CollectionAssert.Contains(array, failureMechanism.CalculationsGroup);
            CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles);
            CollectionAssert.Contains(array, failureMechanism.HeightStructures);

            CollectionAssert.AreEquivalent(expectedRemovedObjects, results.RemovedObjects);
        }
Ejemplo n.º 10
0
        public void UpdateStructuresWithImportedData_SingleChange_UpdatesOnlySingleChange(HeightStructure readStructure)
        {
            // Setup
            HeightStructure structure = new TestHeightStructure();

            var failureMechanism = new HeightStructuresFailureMechanism();
            StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures;

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

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

            // Assert
            AssertHeightStructures(readStructure, structure);
            CollectionAssert.AreEqual(new IObservable[]
            {
                targetCollection,
                structure
            }, affectedObjects);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a new instance of <see cref="HeightStructuresInputContext"/>.
 /// </summary>
 /// <param name="wrappedData">The calculation input wrapped by the context object.</param>
 /// <param name="calculation">The height structures calculation containing the <see cref="HeightStructuresInput"/>.</param>
 /// <param name="failureMechanism">The failure mechanism which the context belongs to.</param>
 /// <param name="assessmentSection">The assessment section which the context belongs to.</param>
 /// <exception cref="ArgumentNullException">Thrown when any input argument is <c>null</c>.</exception>
 public HeightStructuresInputContext(HeightStructuresInput wrappedData,
                                     StructuresCalculation <HeightStructuresInput> calculation,
                                     HeightStructuresFailureMechanism failureMechanism,
                                     IAssessmentSection assessmentSection)
     : base(wrappedData, calculation, failureMechanism, assessmentSection)
 {
 }
Ejemplo n.º 12
0
        public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection()
        {
            // Setup
            var targetStructure = new TestHeightStructure("target id");

            var failureMechanism = new HeightStructuresFailureMechanism();
            StructureCollection <HeightStructure> structures = failureMechanism.HeightStructures;

            structures.AddRange(new[]
            {
                targetStructure
            }, sourceFilePath);

            var readStructure = new TestHeightStructure("read id");

            TestHeightStructure[] importedStructures =
            {
                readStructure
            };

            var strategy = new HeightStructureUpdateDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures,
                                                                                                  sourceFilePath);

            // Assert
            CollectionAssert.AreEqual(importedStructures, structures);
            Assert.AreSame(readStructure, structures[0]);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                structures
            }, affectedObjects);
        }
Ejemplo n.º 13
0
        public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.HeightStructures.AddRange(new[]
            {
                new TestHeightStructure("id", "Original")
            }, sourceFilePath);

            var importedStructure = new TestHeightStructure("Different id", "Imported");

            var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);

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

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                failureMechanism.HeightStructures
            }, affectedObjects);

            TestHeightStructure[] expected =
            {
                importedStructure
            };
            CollectionAssert.AreEqual(expected, failureMechanism.HeightStructures);
        }
Ejemplo n.º 14
0
        public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure()
        {
            // Setup
            var importedStructures = new[]
            {
                new TestHeightStructure()
            };

            var failureMechanism = new HeightStructuresFailureMechanism();
            var strategy         = new HeightStructureReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures,
                                                                                                  sourceFilePath);

            // Assert
            StructureCollection <HeightStructure> actualCollection = failureMechanism.HeightStructures;

            CollectionAssert.AreEqual(importedStructures, actualCollection);
            CollectionAssert.AreEqual(new[]
            {
                actualCollection
            }, affectedObjects);
            Assert.AreEqual(sourceFilePath, actualCollection.SourcePath);
        }
 public DerivedHeightStructuresCalculationGroupContext(CalculationGroup calculationsGroup,
                                                       CalculationGroup parent,
                                                       HeightStructuresFailureMechanism failureMechanism,
                                                       IAssessmentSection assessmentSection)
     : base(calculationsGroup, parent, failureMechanism, assessmentSection)
 {
 }
        public void Constructor_WithOrWithoutStructure_CorrectReadOnlyForStructureDependentProperties(bool hasStructure)
        {
            // Setup
            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();
            var calculation      = new StructuresCalculation <HeightStructuresInput>();
            var inputContext     = new HeightStructuresInputContext(calculation.InputParameters,
                                                                    calculation,
                                                                    failureMechanism,
                                                                    assessmentSection);

            if (hasStructure)
            {
                calculation.InputParameters.Structure = new TestHeightStructure();
            }

            // Call
            var properties = new HeightStructuresInputContextProperties(inputContext, handler);

            // Assert
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
            bool expectedReadOnly = !hasStructure;

            PropertyDescriptor failureProbabilityStructureWithErosionProperty = dynamicProperties[failureProbabilityStructureWithErosionPropertyIndex];

            Assert.AreEqual(expectedReadOnly, failureProbabilityStructureWithErosionProperty.IsReadOnly);

            DistributionPropertiesTestHelper.AssertPropertiesAreReadOnly(properties.LevelCrestStructure, expectedReadOnly, expectedReadOnly);

            mockRepository.VerifyAll();
        }
        public void ParameteredConstructor_ExpectedValues(bool hasParent)
        {
            // Setup
            var mockRepository    = new MockRepository();
            var assessmentSection = mockRepository.Stub <IAssessmentSection>();

            mockRepository.ReplayAll();

            var calculationGroup = new CalculationGroup();
            var failureMechanism = new HeightStructuresFailureMechanism();

            CalculationGroup parent = hasParent ? new CalculationGroup() : null;

            // Call
            var groupContext = new HeightStructuresCalculationGroupContext(calculationGroup, parent, failureMechanism, assessmentSection);

            // Assert
            Assert.IsInstanceOf <FailureMechanismItemContextBase <CalculationGroup, HeightStructuresFailureMechanism> >(groupContext);
            Assert.IsInstanceOf <ICalculationContext <CalculationGroup, HeightStructuresFailureMechanism> >(groupContext);
            Assert.AreSame(calculationGroup, groupContext.WrappedData);
            Assert.AreSame(parent, groupContext.Parent);
            Assert.AreSame(failureMechanism, groupContext.FailureMechanism);
            Assert.AreSame(assessmentSection, groupContext.AssessmentSection);
            Assert.AreSame(failureMechanism.ForeshoreProfiles, groupContext.AvailableForeshoreProfiles);
            Assert.AreSame(failureMechanism.HeightStructures, groupContext.AvailableStructures);
            mockRepository.VerifyAll();
        }
        public void GetAvailableStructures_SetInputContextInstanceWithStructures_ReturnStructures()
        {
            // Setup
            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.HeightStructures.AddRange(new[]
            {
                new TestHeightStructure()
            }, "some folder");
            var calculation  = new StructuresCalculation <HeightStructuresInput>();
            var inputContext = new HeightStructuresInputContext(calculation.InputParameters,
                                                                calculation,
                                                                failureMechanism,
                                                                assessmentSection);
            var properties = new HeightStructuresInputContextProperties(inputContext, handler);

            // Call
            IEnumerable <HeightStructure> availableStructures = properties.GetAvailableStructures();

            // Assert
            Assert.AreSame(failureMechanism.HeightStructures, availableStructures);
            mockRepository.VerifyAll();
        }
        public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue()
        {
            // Setup
            var failureMechanism  = new HeightStructuresFailureMechanism();
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[]
            {
                failureMechanism
            });
            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
            {
                Locations =
                {
                    new HydraulicBoundaryLocation(1, "Location 1", 1.1, 2.2),
                    new HydraulicBoundaryLocation(2, "Location 2", 3.3, 4.4)
                }
            });
            mocks.ReplayAll();

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

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
        public void SetShouldIllustrationPointsBeCalculated_ValueChanged_UpdateDataAndNotifyObservers()
        {
            // Setup
            var  random     = new Random(21);
            bool newBoolean = random.NextBoolean();

            var observer = mockRepository.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());

            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            var calculation      = new StructuresCalculation <HeightStructuresInput>();
            var failureMechanism = new HeightStructuresFailureMechanism();
            var inputContext     = new HeightStructuresInputContext(calculation.InputParameters,
                                                                    calculation,
                                                                    failureMechanism,
                                                                    assessmentSection);

            inputContext.Attach(observer);

            var properties = new HeightStructuresInputContextProperties(inputContext, handler);

            // Call
            properties.ShouldIllustrationPointsBeCalculated = newBoolean;

            // Assert
            Assert.AreEqual(newBoolean, calculation.InputParameters.ShouldIllustrationPointsBeCalculated);
            mockRepository.VerifyAll();
        }
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism
            {
                InAssemblyInputComments =
                {
                    Body = "Some input text"
                },
                InAssemblyOutputComments =
                {
                    Body = "Some output text"
                },
                NotInAssemblyComments =
                {
                    Body = "Really not in assembly"
                },
                CalculationsInputComments =
                {
                    Body = "Some calculation text"
                }
            };

            var registry = new PersistenceRegistry();

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(registry);

            // Assert
            TestHelper.AssertAreEqualButNotSame(failureMechanism.InAssemblyInputComments.Body, entity.InAssemblyInputComments);
            TestHelper.AssertAreEqualButNotSame(failureMechanism.InAssemblyOutputComments.Body, entity.InAssemblyOutputComments);
            TestHelper.AssertAreEqualButNotSame(failureMechanism.NotInAssemblyComments.Body, entity.NotInAssemblyComments);
            TestHelper.AssertAreEqualButNotSame(failureMechanism.CalculationsInputComments.Body, entity.CalculationsInputComments);
        }
        private void SetPropertyAndVerifyNotificationsAndOutput(Action <HeightStructuresInputContextProperties> setProperty)
        {
            // Setup
            var observable = mockRepository.StrictMock <IObservable>();

            observable.Expect(o => o.NotifyObservers());
            mockRepository.ReplayAll();

            var failureMechanism        = new HeightStructuresFailureMechanism();
            var calculation             = new StructuresCalculation <HeightStructuresInput>();
            HeightStructuresInput input = calculation.InputParameters;

            input.ForeshoreProfile = new TestForeshoreProfile();
            input.Structure        = new TestHeightStructure();

            var customHandler = new SetPropertyValueAfterConfirmationParameterTester(new[]
            {
                observable
            });

            var inputContext = new HeightStructuresInputContext(input,
                                                                calculation,
                                                                failureMechanism,
                                                                assessmentSection);
            var properties = new HeightStructuresInputContextProperties(inputContext, customHandler);

            // Call
            setProperty(properties);

            // Assert
            Assert.IsFalse(calculation.HasOutput);

            mockRepository.VerifyAll();
        }
        public void AssembleFailureMechanism_CalculatorRan_ReturnsExpectedOutput()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism
            {
                AssemblyResult =
                {
                    ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic
                }
            };

            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;

                // Call
                FailureMechanismAssemblyResultWrapper result = HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);

                // Assert
                Assert.AreSame(calculator.AssemblyResultOutput, result);
            }
        }
Ejemplo n.º 24
0
        private FailureMechanismAssemblyResultRow CreateHeightStructuresFailureMechanismAssemblyResultRow()
        {
            HeightStructuresFailureMechanism heightStructures = AssessmentSection.HeightStructures;

            return(FailureMechanismAssemblyResultRowFactory.CreateRow(
                       heightStructures, () => HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(heightStructures, AssessmentSection)));
        }
        public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism
            {
                AssemblyResult =
                {
                    ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic
                }
            };

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, "APath");

            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;

                // Call
                HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);

                // Assert
                Assert.AreEqual(failureMechanism.GeneralInput.N, failureMechanismAssemblyCalculator.FailureMechanismN);
                Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput.AssemblyResult, failureMechanismAssemblyCalculator.SectionAssemblyResultsInput.Single());
                Assert.AreEqual(failureMechanism.GeneralInput.ApplyLengthEffectInSection, failureMechanismAssemblyCalculator.ApplyLengthEffect);
            }
        }
Ejemplo n.º 26
0
        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);
                HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                var view = new HeightStructuresScenariosView(assessmentSection.HeightStructures.CalculationsGroup, assessmentSection.HeightStructures);
                form.Controls.Add(view);
                form.Show();

                var structuresImporter = new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures,
                                                                      assessmentSection.ReferenceLine, filePath, messageProvider,
                                                                      new HeightStructureReplaceDataStrategy(failureMechanism));
                structuresImporter.Import();

                foreach (HeightStructure structure in assessmentSection.HeightStructures.HeightStructures)
                {
                    assessmentSection.HeightStructures.CalculationsGroup.Children.Add(new StructuresCalculationScenario <HeightStructuresInput>
                    {
                        Name            = NamingHelper.GetUniqueName(assessmentSection.HeightStructures.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(13);

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

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

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

            mocks.VerifyAll();
        }
Ejemplo n.º 27
0
        public void CalculationsView_Always_BreakWaterTypeComboboxCorrectlyInitialized()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            ConfigureHydraulicBoundaryDatabase(assessmentSection);
            mocks.ReplayAll();

            HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism();

            // Call
            ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection);

            // Assert
            var dataGridView           = (DataGridView) new ControlTester("dataGridView").TheObject;
            var breakWaterTypeComboBox = (DataGridViewComboBoxColumn)dataGridView.Columns[breakWaterTypeColumnIndex];

            DataGridViewComboBoxCell.ObjectCollection breakWaterTypeComboBoxItems = breakWaterTypeComboBox.Items;
            Assert.AreEqual(3, breakWaterTypeComboBoxItems.Count);
            Assert.AreEqual("Muur", breakWaterTypeComboBoxItems[0].ToString());
            Assert.AreEqual("Caisson", breakWaterTypeComboBoxItems[1].ToString());
            Assert.AreEqual("Havendam", breakWaterTypeComboBoxItems[2].ToString());
            mocks.VerifyAll();
        }
Ejemplo n.º 28
0
        public void ScenariosView_ImportFailureMechanismSections_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            using (var form = new Form())
            {
                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);

                var view = new HeightStructuresScenariosView(assessmentSection.HeightStructures.CalculationsGroup, assessmentSection.HeightStructures);
                form.Controls.Add(view);
                form.Show();

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

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

                // Call
                HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);
                assessmentSection.HeightStructures.NotifyObservers();

                // Assert
                CollectionAssert.AreEqual(assessmentSection.HeightStructures.Sections, listBox.Items);
            }
        }
Ejemplo n.º 29
0
        public void Selection_Always_ReturnsTheSelectedRowObject(int selectedRow)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            ConfigureHydraulicBoundaryDatabase(assessmentSection);
            mocks.ReplayAll();

            HeightStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism();
            CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection);

            HeightStructuresCalculationsView view = ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection);

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

            dataGridView.CurrentCell = dataGridView.Rows[selectedRow].Cells[0];

            // Call
            object selection = view.Selection;

            // Assert
            Assert.IsInstanceOf <HeightStructuresInputContext>(selection);
            var dataRow = (HeightStructuresCalculationRow)dataGridView.Rows[selectedRow].DataBoundItem;

            Assert.AreSame(dataRow.Calculation, ((HeightStructuresInputContext)selection).Calculation);
            mocks.VerifyAll();
        }
        public void CurrentPath_FailureMechanismSectionsSourcePathSet_ReturnsExpectedPath()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            string sourcePath = TestHelper.GetScratchPadPath();

            failureMechanism.SetSections(Enumerable.Empty <FailureMechanismSection>(), sourcePath);
            var context = new HeightStructuresFailureMechanismSectionsContext(failureMechanism, assessmentSection);

            using (var plugin = new HeightStructuresPlugin())
            {
                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                // Call
                string currentFilePath = updateInfo.CurrentPath(context);

                // Assert
                Assert.AreEqual(sourcePath, currentFilePath);
                mocks.VerifyAll();
            }
        }