public void SetPropertyValueAfterConfirmation_ConfirmationRequiredAndGivenExceptionInSetValue_ExceptionBubbled()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            var testFailureMechanism = new TestCalculatableFailureMechanism(
                new[]
            {
                CalculationTestDataFactory.CreateCalculationWithOutput()
            });

            var changeHandler     = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();
            var expectedException = new Exception();

            // Call
            void Call() =>
            changeHandler.SetPropertyValueAfterConfirmation(testFailureMechanism, 3, (f, v) =>
            {
                throw expectedException;
            });

            // Assert
            var exception = Assert.Throws <Exception>(Call);

            Assert.AreSame(expectedException, exception);
        }
        public void ShouldCloseMethod_ViewNotCorrespondingToRemovedAssessmentSectionAndFailureMechanism_ReturnsFalse()
        {
            // Setup
            var otherFailureMechanism = new TestCalculatableFailureMechanism();

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

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[]
            {
                failureMechanism
            });
            assessmentSection.Stub(asm => asm.SpecificFailureMechanisms).Return(new ObservableList <SpecificFailureMechanism>());
            mocks.ReplayAll();

            using (IView view = GetView(otherFailureMechanism))
            {
                // Call
                bool closeForData = ShouldCloseMethod(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Esempio n. 3
0
        public void GivenScenariosView_WhenFailureMechanismNotifiesObserver_ThenDataGridViewUpdated()
        {
            // Given
            var failureMechanism = new TestCalculatableFailureMechanism();

            ShowFullyConfiguredScenariosView(new CalculationGroup(), failureMechanism);

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

            TestScenarioRow[] sectionResultRows = dataGridView.Rows.Cast <DataGridViewRow>()
                                                  .Select(r => r.DataBoundItem)
                                                  .Cast <TestScenarioRow>()
                                                  .ToArray();

            // When
            failureMechanism.NotifyObservers();

            // Then
            TestScenarioRow[] updatedRows = dataGridView.Rows.Cast <DataGridViewRow>()
                                            .Select(r => r.DataBoundItem)
                                            .Cast <TestScenarioRow>()
                                            .ToArray();

            CollectionAssert.AreNotEquivalent(sectionResultRows, updatedRows);
        }
Esempio n. 4
0
        private void ShowScenariosView(CalculationGroup calculationGroup, TestCalculatableFailureMechanism failureMechanism)
        {
            var scenariosView = new TestScenariosView(calculationGroup, failureMechanism);

            testForm.Controls.Add(scenariosView);
            testForm.Show();
        }
Esempio n. 5
0
        public void GivenFailureMechanismResultObserverWithCalculationAndAttachedObserver_WhenCalculationInputNotifiesObservers_ThenAttachedObserverNotified()
        {
            // Given
            var failureMechanism = new TestCalculatableFailureMechanism();
            var calculation      = new TestCalculationWithInput();

            failureMechanism.CalculationsGroup.Children.Add(calculation);

            using (var resultObserver = new CalculatableFailureMechanismResultObserver <TestCalculatableFailureMechanism,
                                                                                        FailureMechanismSectionResult, TestCalculationWithInput>(failureMechanism))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                calculation.InputParameters.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
Esempio n. 6
0
 public DerivedTestStructuresCalculationScenarioContext(StructuresCalculationScenario <TestStructuresInput> calculation,
                                                        CalculationGroup parent,
                                                        TestCalculatableFailureMechanism failureMechanism,
                                                        IAssessmentSection assessmentSection)
     : base(calculation, parent, failureMechanism, assessmentSection)
 {
 }
        public void SetPropertyValueAfterConfirmation_ConfirmationRequiredButNotGiven_SetValueNotCalledNoAffectedObjectsReturned()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickCancel();
            };

            ICalculation calculationWithOutput    = CalculationTestDataFactory.CreateCalculationWithOutput();
            ICalculation calculationWithoutOutput = CalculationTestDataFactory.CreateCalculationWithoutOutput();

            var testFailureMechanism = new TestCalculatableFailureMechanism(
                new[]
            {
                calculationWithOutput,
                calculationWithoutOutput
            });
            var propertySet = 0;

            var changeHandler = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();

            // Call
            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
                testFailureMechanism,
                3,
                (f, v) => propertySet++);

            // Assert
            Assert.AreEqual(0, propertySet);
            CollectionAssert.IsEmpty(affectedObjects);
            Assert.IsTrue(calculationWithOutput.HasOutput);
        }
Esempio n. 8
0
        public void GivenScenariosView_WhenSelectingDifferentItemInSectionsListBox_ThenDataGridViewUpdated()
        {
            // Given
            var failureMechanism = new TestCalculatableFailureMechanism();

            ShowFullyConfiguredScenariosView(new CalculationGroup(), failureMechanism);

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

            // Precondition
            Assert.AreSame(failureMechanism.Sections.First(), listBox.SelectedItem);

            TestScenarioRow[] sectionResultRows = dataGridView.Rows.Cast <DataGridViewRow>()
                                                  .Select(r => r.DataBoundItem)
                                                  .Cast <TestScenarioRow>()
                                                  .ToArray();

            // When
            listBox.SelectedItem = failureMechanism.Sections.Last();

            // Then
            TestScenarioRow[] updatedRows = dataGridView.Rows.Cast <DataGridViewRow>()
                                            .Select(r => r.DataBoundItem)
                                            .Cast <TestScenarioRow>()
                                            .ToArray();

            CollectionAssert.AreNotEquivalent(sectionResultRows, updatedRows);
        }
Esempio n. 9
0
        public void RequireConfirmation_FailureMechanismWithCalculationWithOutput_ReturnTrue()
        {
            // Setup
            var mockRepository = new MockRepository();
            var inquiryHandler = mockRepository.StrictMock <IInquiryHelper>();

            var calculation = mockRepository.StrictMock <ICalculation>();

            calculation.Expect(calc => calc.HasOutput).Return(true);
            mockRepository.ReplayAll();

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                calculation
            });

            var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, inquiryHandler);

            // Call
            bool requireConfirmation = handler.RequireConfirmation();

            // Assert
            Assert.IsTrue(requireConfirmation);
            mockRepository.VerifyAll();
        }
Esempio n. 10
0
        public void AssembleSection_CalculatorThrowsException_ThrowsAssemblyException()
        {
            // Setup
            var failureMechanism            = new TestCalculatableFailureMechanism();
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableFailureMechanismSectionResult(section);

            var assessmentSection = new AssessmentSectionStub();

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

                // Call
                void Call() => StructuresFailureMechanismAssemblyFactory.AssembleSection <TestStructuresInput>(
                    sectionResult, failureMechanism, assessmentSection);

                // Assert
                var       exception      = Assert.Throws <AssemblyException>(Call);
                Exception innerException = exception.InnerException;
                Assert.IsInstanceOf <FailureMechanismSectionAssemblyCalculatorException>(innerException);
                Assert.AreEqual(innerException.Message, exception.Message);
            }
        }
Esempio n. 11
0
        public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithOutputAndProfile_UpdatesCalculationWithUpdatedProfile()
        {
            // Setup
            var affectedProfile = new TestForeshoreProfile("Name", "Updated ID");
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);
            ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile);

            const string unaffectedProfileId   = "Unaffected ID";
            const string unaffectedProfileName = "Name";
            var          unaffectedProfile     = new TestForeshoreProfile(unaffectedProfileName, unaffectedProfileId);
            TestCalculationWithForeshoreProfile unaffectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(unaffectedProfile);

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile,
                unaffectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation,
                unaffectedCalculation
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                new TestForeshoreProfile(unaffectedProfileName,
                                         unaffectedProfileId),
                profileToUpdateFrom
            },
                                                                 sourceFilePath);

            // Assert
            Assert.IsTrue(unaffectedCalculation.HasOutput);
            Assert.AreSame(unaffectedProfile,
                           unaffectedCalculation.InputParameters.ForeshoreProfile);

            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.AreSame(affectedProfile, affectedCalculation.InputParameters.ForeshoreProfile);

            CollectionAssert.AreEquivalent(originalForeshoreProfiles, foreshoreProfiles);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
Esempio n. 12
0
 public TestCalculationsViewWithColumnStateDefinitions(CalculationGroup calculationGroup,
                                                       TestCalculatableFailureMechanism failureMechanism,
                                                       IAssessmentSection assessmentSection,
                                                       bool initialReadOnlyState)
     : base(calculationGroup, failureMechanism, assessmentSection)
 {
     this.initialReadOnlyState = initialReadOnlyState;
 }
Esempio n. 13
0
        public void UpdateForeshoreProfilesWithImportedData_CalculationWithOutputAndForeshoreProfileUpdatedWithProfileWithoutGeometry_UpdatesCalculation()
        {
            // Setup
            const string          id       = "profile ID";
            IEnumerable <Point2D> geometry = new[]
            {
                new Point2D(1, 2),
                new Point2D(3, 4)
            };

            var affectedProfile = new TestForeshoreProfile(id, geometry);
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);

            affectedCalculation.InputParameters.UseForeshore = true;

            var profileToUpdateFrom = new TestForeshoreProfile(id, Enumerable.Empty <Point2D>());

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

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

            // Assert
            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.IsFalse(affectedCalculation.InputParameters.UseForeshore);
            AssertForeshoreProfile(affectedProfile, profileToUpdateFrom);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
        public void SetPropertyValueAfterConfirmation_IfConfirmationRequiredThenGiven_SetValueCalledAffectedObjectsReturned(ChangePropertyTestCase testCase)
        {
            // Setup
            bool dialogBoxWillBeShown = testCase.ExpectedAffectedCalculations.Any();

            var title   = "";
            var message = "";

            if (dialogBoxWillBeShown)
            {
                DialogBoxHandler = (name, wnd) =>
                {
                    var tester = new MessageBoxTester(wnd);
                    title   = tester.Title;
                    message = tester.Text;

                    tester.ClickOk();
                };
            }

            var testFailureMechanism = new TestCalculatableFailureMechanism(testCase.Calculations);
            var propertySet          = 0;

            var changeHandler = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();

            // Precondition
            Assert.IsTrue(testCase.ExpectedAffectedCalculations.All(c => c.HasOutput));

            // Call
            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
                testFailureMechanism,
                3,
                (f, v) => propertySet++);

            // Assert
            if (dialogBoxWillBeShown)
            {
                Assert.AreEqual("Bevestigen", title);
                string expectedMessage = "Als u deze parameter wijzigt, zal de uitvoer van alle berekeningen in dit faalmechanisme verwijderd worden."
                                         + Environment.NewLine + Environment.NewLine +
                                         "Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedMessage, message);
            }

            Assert.AreEqual(1, propertySet);
            var expectedAffectedObjects = new List <IObservable>(testCase.ExpectedAffectedCalculations)
            {
                testFailureMechanism
            };

            CollectionAssert.AreEqual(expectedAffectedObjects, affectedObjects);
            Assert.IsTrue(testCase.Calculations.All(c => !c.HasOutput));
        }
Esempio n. 15
0
        public void GivenMapLayerWithFailureMechanismSectionAssemblyResults_WhenChangingNestedCalculationScenarioInputDataAndObserversNotified_ThenMapDataUpdated()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            var random = new Random(21);
            var calculationScenario = new TestCalculationScenario();
            var failureMechanism    = new TestCalculatableFailureMechanism(new[]
            {
                calculationScenario
            });

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var nestedCalculationScenario = new TestCalculationScenario();
            var nestedCalculationGroup    = new CalculationGroup();

            nestedCalculationGroup.Children.Add(nestedCalculationScenario);
            failureMechanism.CalculationsGroup.Children.Add(nestedCalculationGroup);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            using (var mapLayer = new CalculatableFailureMechanismSectionResultsMapLayer <TestCalculatableFailureMechanism, TestFailureMechanismSectionResult, TestCalculationInput>(
                       failureMechanism, result => assemblyResult))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);

                // When
                assemblyResult = new FailureMechanismSectionAssemblyResult(
                    random.NextDouble(), random.NextDouble(), random.NextDouble(),
                    random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

                nestedCalculationScenario.InputParameters.HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
                nestedCalculationScenario.InputParameters.NotifyObservers();

                // Then
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
Esempio n. 16
0
        public void UpdateForeshoreProfilesWithImportedData_CalculationsWithForeshoreProfilesAndOutput_CalculationUpdatedAndReturnsAffectedData()
        {
            // Setup
            var foreshoreProfile = new TestForeshoreProfile();
            TestCalculationWithForeshoreProfile calculationWithForeshoreProfileAndOutput =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(foreshoreProfile);
            TestCalculationWithForeshoreProfile calculationWithForeshoreProfile =
                TestCalculationWithForeshoreProfile.CreateCalculationWithoutOutput(foreshoreProfile);
            TestCalculationWithForeshoreProfile calculationWithoutForeshoreProfile =
                TestCalculationWithForeshoreProfile.CreateDefaultCalculation();

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                calculationWithForeshoreProfileAndOutput,
                calculationWithForeshoreProfile,
                calculationWithoutForeshoreProfile
            });

            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                foreshoreProfile
            }, sourceFilePath);

            TestCalculationWithForeshoreProfile[] calculationsWithForeshoreProfile =
            {
                calculationWithForeshoreProfileAndOutput,
                calculationWithForeshoreProfile
            };

            var strategy = new ForeshoreProfileReplaceDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(),
                                                                                                         sourceFilePath);

            // Assert
            CollectionAssert.IsEmpty(foreshoreProfiles);
            Assert.IsFalse(calculationWithForeshoreProfileAndOutput.HasOutput);
            Assert.IsTrue(calculationsWithForeshoreProfile.All(calc => calc.InputParameters.ForeshoreProfile == null));

            IEnumerable <IObservable> expectedAffectedObjects =
                calculationsWithForeshoreProfile.Select(calc => calc.InputParameters)
                .Concat(new IObservable[]
            {
                foreshoreProfiles,
                calculationWithForeshoreProfileAndOutput
            });

            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
        }
        public void ShouldCloseMethod_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue()
        {
            // Setup
            var failureMechanism = new TestCalculatableFailureMechanism();

            using (IView view = GetView(failureMechanism))
            {
                // Call
                bool closeForData = ShouldCloseMethod(view, failureMechanism);

                // Assert
                Assert.IsTrue(closeForData);
            }
        }
Esempio n. 18
0
        public void AssembleSection_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableFailureMechanismSectionResult(section);

            var failureMechanism = new TestCalculatableFailureMechanism();

            // Call
            void Call() => StructuresFailureMechanismAssemblyFactory.AssembleSection <TestStructuresInput>(sectionResult, failureMechanism, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
Esempio n. 19
0
        public void GivenScenariosView_WhenFailureMechanismNotifiesObserver_ThenSectionsListBoxCorrectlyUpdated()
        {
            // Given
            var failureMechanism = new TestCalculatableFailureMechanism();

            ShowScenariosView(new CalculationGroup(), failureMechanism);

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

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

            // When
            var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(5.0, 0.0)
            });
            var failureMechanismSection2 = new FailureMechanismSection("Section 2", new[]
            {
                new Point2D(5.0, 0.0),
                new Point2D(10.0, 0.0)
            });
            var failureMechanismSection3 = new FailureMechanismSection("Section 3", new[]
            {
                new Point2D(10.0, 0.0),
                new Point2D(15.0, 0.0)
            });

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                failureMechanismSection1,
                failureMechanismSection2,
                failureMechanismSection3
            });
            failureMechanism.NotifyObservers();

            // Then
            Assert.AreEqual(3, listBox.Items.Count);
            Assert.AreSame(failureMechanismSection1, listBox.Items[0]);
            Assert.AreSame(failureMechanismSection2, listBox.Items[1]);
            Assert.AreSame(failureMechanismSection3, listBox.Items[2]);
            Assert.AreSame(failureMechanismSection1, listBox.SelectedItem);
        }
Esempio n. 20
0
        public void RequireConfirmation_FailureMechanismWithoutCalculations_ReturnsFalse()
        {
            // Setup
            var mockRepository = new MockRepository();
            var inquiryHandler = mockRepository.StrictMock <IInquiryHelper>();

            mockRepository.ReplayAll();

            var failureMechanism = new TestCalculatableFailureMechanism(Enumerable.Empty <ICalculation>());

            var handler = new FailureMechanismCalculationChangeHandler(failureMechanism, string.Empty, inquiryHandler);

            // Call
            bool requireConfirmation = handler.RequireConfirmation();

            // Assert
            Assert.IsFalse(requireConfirmation);
            mockRepository.VerifyAll();
        }
        public void SetPropertyValueAfterConfirmation_ConfirmationNotRequiredExceptionInSetValue_ExceptionBubbled()
        {
            // Setup
            var testFailureMechanism = new TestCalculatableFailureMechanism();
            var changeHandler        = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();
            var expectedException    = new Exception();

            // Call
            void Call() =>
            changeHandler.SetPropertyValueAfterConfirmation(testFailureMechanism, 3, (f, v) =>
            {
                throw expectedException;
            });

            // Assert
            var exception = Assert.Throws <Exception>(Call);

            Assert.AreSame(expectedException, exception);
        }
Esempio n. 22
0
        public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithSameReference_OnlyReturnsDistinctCalculations()
        {
            // Setup
            var affectedProfile = new TestForeshoreProfile("Name", "Updated ID");
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);
            ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile);

            TestCalculationWithForeshoreProfile calculationSameReference = affectedCalculation;

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation,
                calculationSameReference
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

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

            // Assert
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
Esempio n. 23
0
        public void AssembleSection_SectionResultNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new TestCalculatableFailureMechanism();

            // Call
            void Call() => StructuresFailureMechanismAssemblyFactory.AssembleSection <TestStructuresInput>(null, failureMechanism, assessmentSection);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("sectionResult", exception.ParamName);

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

            mockRepository.ReplayAll();

            var calculation      = new TestStructuresCalculationScenario();
            var failureMechanism = new TestCalculatableFailureMechanism();

            // Call
            void Call() => new TestStructuresCalculationScenarioContext(calculation, null, failureMechanism, assessmentSection);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("parent", exception.ParamName);
            mockRepository.VerifyAll();
        }
        public void ShouldCloseMethod_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse()
        {
            // Setup
            var otherFailureMechanism = new TestCalculatableFailureMechanism();

            var mocks            = new MockRepository();
            var failureMechanism = mocks.Stub <IFailureMechanism>();

            mocks.ReplayAll();

            using (IView view = GetView(otherFailureMechanism))
            {
                // Call
                bool closeForData = ShouldCloseMethod(view, failureMechanism);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Esempio n. 26
0
        public void Constructor_ListBoxCorrectlyInitialized()
        {
            // Setup
            var failureMechanism         = new TestCalculatableFailureMechanism();
            var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(5.0, 0.0)
            });
            var failureMechanismSection2 = new FailureMechanismSection("Section 2", new[]
            {
                new Point2D(5.0, 0.0),
                new Point2D(10.0, 0.0)
            });
            var failureMechanismSection3 = new FailureMechanismSection("Section 3", new[]
            {
                new Point2D(10.0, 0.0),
                new Point2D(15.0, 0.0)
            });

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                failureMechanismSection1,
                failureMechanismSection2,
                failureMechanismSection3
            });

            // Call
            ShowScenariosView(new CalculationGroup(), failureMechanism);

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

            Assert.AreEqual(nameof(FailureMechanismSection.Name), listBox.DisplayMember);
            Assert.AreEqual(3, listBox.Items.Count);
            Assert.AreSame(failureMechanismSection1, listBox.Items[0]);
            Assert.AreSame(failureMechanismSection2, listBox.Items[1]);
            Assert.AreSame(failureMechanismSection3, listBox.Items[2]);
            Assert.AreSame(failureMechanismSection1, listBox.SelectedItem);
        }
Esempio n. 27
0
        public void AssembleSection_CalculatorRan_ReturnsExpectedOutput()
        {
            // Setup
            var failureMechanism            = new TestCalculatableFailureMechanism();
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableFailureMechanismSectionResult(section);

            var assessmentSection = new AssessmentSectionStub();

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

                // Call
                FailureMechanismSectionAssemblyResultWrapper result = StructuresFailureMechanismAssemblyFactory.AssembleSection <TestStructuresInput>(
                    sectionResult, failureMechanism, assessmentSection);

                // Assert
                Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput, result);
            }
        }
Esempio n. 28
0
        public void AssembleSection_WithInput_SetsInputOnCalculator()
        {
            // Setup
            var random = new Random(21);

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableFailureMechanismSectionResult(section)
            {
                IsRelevant = random.NextBoolean(),
                InitialFailureMechanismResultType = AdoptableInitialFailureMechanismResultType.Manual,
                FurtherAnalysisType       = random.NextEnumValue <FailureMechanismSectionResultFurtherAnalysisType>(),
                RefinedSectionProbability = random.NextDouble()
            };

            var failureMechanism  = new TestCalculatableFailureMechanism();
            var assessmentSection = new AssessmentSectionStub();

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

                // Call
                StructuresFailureMechanismAssemblyFactory.AssembleSection <TestStructuresInput>(sectionResult, failureMechanism, assessmentSection);

                // Assert
                FailureMechanismSectionAssemblyInput calculatorInput = calculator.FailureMechanismSectionAssemblyInput;
                FailureMechanismContribution         failureMechanismContribution = assessmentSection.FailureMechanismContribution;
                Assert.AreEqual(failureMechanismContribution.SignalFloodingProbability, calculatorInput.SignalFloodingProbability);
                Assert.AreEqual(failureMechanismContribution.MaximumAllowableFloodingProbability, calculatorInput.MaximumAllowableFloodingProbability);

                Assert.AreEqual(sectionResult.IsRelevant, calculatorInput.IsRelevant);
                Assert.IsTrue(calculatorInput.HasProbabilitySpecified);

                Assert.AreEqual(sectionResult.ManualInitialFailureMechanismResultSectionProbability, calculatorInput.InitialSectionProbability);
                Assert.AreEqual(sectionResult.FurtherAnalysisType, calculatorInput.FurtherAnalysisType);
                Assert.AreEqual(sectionResult.RefinedSectionProbability, calculatorInput.RefinedSectionProbability);
            }
        }
Esempio n. 29
0
        public void Validate_InputInvalidAccordingToValidationRule_LogErrorAndReturnFalse()
        {
            // Setup
            var failureMechanism = new TestCalculatableFailureMechanism();

            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(
                failureMechanism, mocks, validHydraulicBoundaryDatabaseFilePath);

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    Structure                 = new TestStructure(),
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                    IsValid                   = false
                }
            };

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                Assert.AreEqual("Error message", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
Esempio n. 30
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var random           = new Random(21);
            var failureMechanism = new TestCalculatableFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            // Call
            using (var mapLayer = new CalculatableFailureMechanismSectionResultsMapLayer <TestCalculatableFailureMechanism, TestFailureMechanismSectionResult, TestCalculationInput>(
                       failureMechanism, result => assemblyResult))
            {
                // Assert
                Assert.IsInstanceOf <NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult> >(mapLayer);
            }
        }