public void GivenAssessmentSectionWithPipingFailureMechanismReplaced_WhenOldPipingScenarioConfigurationsPerFailureMechanismSectionNotified_ThenAssessmentSectionResultObserverNotNotified() { // Given AssessmentSection assessmentSection = CreateAssessmentSection(); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); mocks.ReplayAll(); PipingFailureMechanism oldFailureMechanism = assessmentSection.Piping; FailureMechanismTestHelper.SetSections(oldFailureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1") }); assessmentSection.Piping = new PipingFailureMechanism(); assessmentSection.NotifyObservers(); resultObserver.Attach(observer); // When oldFailureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().NotifyObservers(); // Then mocks.VerifyAll(); } }
private static ClosingStructuresFailureMechanism ConfigureFailureMechanism() { var failureMechanism = new ClosingStructuresFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); failureMechanism.ForeshoreProfiles.AddRange(new List <ForeshoreProfile> { new TestForeshoreProfile("Profiel 1", "1"), new TestForeshoreProfile("Profiel 2", "2") }, string.Empty); failureMechanism.ClosingStructures.AddRange(new List <ClosingStructure> { new TestClosingStructure(new Point2D(0.0, 0.0), "Structure 1"), new TestClosingStructure(new Point2D(5.0, 0.0), "Structure 2") }, string.Empty); return(failureMechanism); }
public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenPipingScenarioConfigurationsPerFailureMechanismSectionNotified_ThenAttachedObserverNotified() { // Given AssessmentSection assessmentSection = CreateAssessmentSection(); assessmentSection.Piping = new PipingFailureMechanism(); FailureMechanismTestHelper.SetSections(assessmentSection.Piping, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1") }); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); resultObserver.Attach(observer); // When assessmentSection.Piping.ScenarioConfigurationsPerFailureMechanismSection.First().NotifyObservers(); // Then mocks.VerifyAll(); } }
private void ShowFullyConfiguredScenariosView(CalculationGroup calculationGroup, TestCalculatableFailureMechanism failureMechanism) { FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); calculationGroup.Children.AddRange(new[] { new TestCalculationScenario { Name = "Calculation 1" }, new TestCalculationScenario { Name = "Calculation 2", IsRelevant = false } }); ShowScenariosView(calculationGroup, failureMechanism); }
public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndSectionsUpdated_ThenDataGridViewUpdated() { // Given var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { CreateFailureMechanismSection("a") }); using (FailureMechanismSectionsView view = ShowFailureMechanismSectionsView(failureMechanism.Sections, failureMechanism)) { DataGridViewControl sectionsDataGridViewControl = GetSectionsDataGridViewControl(view); // Precondition AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), sectionsDataGridViewControl); // When FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection() }); failureMechanism.NotifyObservers(); // Then AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), sectionsDataGridViewControl); } }
public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndSectionsNotUpdated_ThenDataGridViewNotUpdated() { // Given var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { CreateFailureMechanismSection("a") }); using (FailureMechanismSectionsView view = ShowFailureMechanismSectionsView(failureMechanism.Sections, failureMechanism)) { DataGridView sectionsDataGridView = GetSectionsDataGridView(view); var invalidated = false; sectionsDataGridView.Invalidated += (s, e) => { invalidated = true; }; // When failureMechanism.NotifyObservers(); // Then Assert.IsFalse(invalidated); } }
public void FailureMechanismResultsView_AllDataSet_PassesInputToPerformAssemblyFunc() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var failureMechanism = new TestNonAdoptableWithProfileProbabilityFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); NonAdoptableWithProfileProbabilityFailureMechanismSectionResult functionInput = null; Func <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult, FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = sr => { functionInput = sr; return(FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()); }; // Call using (ShowFailureMechanismResultsView(failureMechanism, performAssemblyFunc)) { // Assert Assert.AreSame(functionInput, failureMechanism.SectionResults.Single()); } }
private static GrassCoverErosionInwardsFailureMechanism ConfigureFailureMechanism() { var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); failureMechanism.DikeProfiles.AddRange(new List <DikeProfile> { DikeProfileTestFactory.CreateDikeProfile("1", "Profiel 1", new Point2D(0.0, 0.0)), DikeProfileTestFactory.CreateDikeProfile("2", "Profiel 2", new Point2D(5.0, 0.0)) }, string.Empty); return(failureMechanism); }
/// <summary> /// Imports <see cref="FailureMechanismSection"/> data for a given enumeration of <see cref="IFailureMechanism{T}"/>. /// </summary> /// <param name="assessmentSection">The <see cref="AssessmentSection"/> that contains the <see cref="IFailureMechanism{T}"/> instances.</param> /// <param name="targetFailureMechanisms">The <see cref="IFailureMechanism{T}"/> instances to import on.</param> /// <remarks> /// <para>This will import the same 283 failure mechanism sections on all failure mechanisms.</para> /// <para>Does not import using <see cref="FileImportActivity"/>.</para> /// </remarks> public static void ImportFailureMechanismSections(AssessmentSection assessmentSection, IEnumerable <IFailureMechanism <FailureMechanismSectionResult> > targetFailureMechanisms) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "traject_6-3_vakken.shp", "traject_6-3_vakken.dbf", "traject_6-3_vakken.prj", "traject_6-3_vakken.shx")) { IFailureMechanism <FailureMechanismSectionResult>[] failureMechanisms = targetFailureMechanisms.ToArray(); for (var i = 0; i < failureMechanisms.Length; i++) { IFailureMechanism <FailureMechanismSectionResult> failureMechanism = failureMechanisms[i]; if (i == 0) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3_vakken.shp"); var importer = new FailureMechanismSectionsImporter( failureMechanism, assessmentSection.ReferenceLine, filePath, new FailureMechanismSectionReplaceStrategy(failureMechanism), new ImportMessageProvider()); importer.Import(); } else { // Copy same FailureMechanismSection instances to other failure mechanisms FailureMechanismTestHelper.SetSections(failureMechanism, failureMechanisms[0].Sections.Select(DeepCloneSection).ToArray()); } } } }
public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); var failureMechanism = new TestNonAdoptableFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism)) { DataGridView dataGridView = GetDataGridView(); // Assert DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(1, rows.Count); DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(columnCount, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(true, cells[isRelevantIndex].Value); Assert.AreEqual(NonAdoptableInitialFailureMechanismResultType.Manual, cells[initialFailureMechanismResultTypeIndex].Value); Assert.AreEqual("-", cells[initialFailureMechanismResultSectionProbabilityIndex].FormattedValue); Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value); Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue); Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue); Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue); } }
public void GivenFailureMechanismResultObserverWithAttachedObserver_WhenFailureMechanismSectionResultNotifiesObservers_ThenAttachedObserverNotified() { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection() }); using (var resultObserver = new FailureMechanismResultObserver <TestFailureMechanism, FailureMechanismSectionResult>( failureMechanism)) { resultObserver.Attach(observer); // When failureMechanism.SectionResults.Single().NotifyObservers(); } // Then mocks.VerifyAll(); }
public void FailureMechanismResultsView_AllDataSet_SetsCorrectInputOnCalculator() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); var assessmentSection = new AssessmentSectionStub(); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism, assessmentSection)) { // Assert var testFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = testFactory.LastCreatedFailureMechanismAssemblyCalculator; double expectedN = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length); Assert.AreEqual(expectedN, calculator.FailureMechanismN); } }
public void FailureMechanismResultsView_AllDataSet_SetsCorrectInputOnCalculator() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); var assessmentSection = new AssessmentSectionStub(); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism, assessmentSection)) { // Assert var testFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = testFactory.LastCreatedFailureMechanismAssemblyCalculator; Assert.AreEqual(failureMechanism.GeneralInput.N, calculator.FailureMechanismN); } }
public void ClearAllSections_WithSectionResults_SectionResultsCleared() { // Setup var failureMechanism = new PipingFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(2, 1) }), FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(2, 1) }) }); // Precondition Assert.AreEqual(2, failureMechanism.SectionResults.Count()); Assert.AreEqual(2, failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.Count()); // Call failureMechanism.ClearAllSections(); // Assert CollectionAssert.IsEmpty(failureMechanism.SectionResults); CollectionAssert.IsEmpty(failureMechanism.ScenarioConfigurationsPerFailureMechanismSection); }
public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeButNothingRelevantChanged_ThenDataGridViewNotUpdated() { // Given var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { CreateFailureMechanismSection("a", 0.0, 0.0, 1.0, 1.0) }); ProbabilityAssessmentInput probabilityAssessmentInput = CreateProbabilityAssessmentInput(); using (FailureMechanismSectionsProbabilityAssessmentView view = ShowFailureMechanismSectionsProbabilityAssessmentView(failureMechanism.Sections, failureMechanism, probabilityAssessmentInput)) { DataGridView sectionsDataGridView = GetSectionsDataGridView(view); var invalidated = false; sectionsDataGridView.Invalidated += (s, e) => { invalidated = true; }; // When failureMechanism.NotifyObservers(); // Then Assert.IsFalse(invalidated); } }
public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndSectionsUpdated_ThenDataGridViewUpdated() { // Given var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { CreateFailureMechanismSection("a", 0.0, 0.0, 1.0, 1.0) }); ProbabilityAssessmentInput probabilityAssessmentInput = CreateProbabilityAssessmentInput(); using (FailureMechanismSectionsProbabilityAssessmentView view = ShowFailureMechanismSectionsProbabilityAssessmentView(failureMechanism.Sections, failureMechanism, probabilityAssessmentInput)) { DataGridViewControl sectionsDataGridViewControl = GetSectionsDataGridViewControl(view); // Precondition AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), probabilityAssessmentInput, sectionsDataGridViewControl); // When FailureMechanismTestHelper.SetSections(failureMechanism, new[] { CreateFailureMechanismSection("a", 1.0, 1.0, 2.0, 2.0) }); failureMechanism.NotifyObservers(); // Then AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), probabilityAssessmentInput, sectionsDataGridViewControl); } }
private static MacroStabilityInwardsFailureMechanism ConfigureSimpleFailureMechanism() { var surfaceLine1 = new MacroStabilityInwardsSurfaceLine("Surface line 1") { ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) }; surfaceLine1.SetGeometry(new[] { new Point3D(0.0, 5.0, 0.0), new Point3D(0.0, 0.0, 1.0), new Point3D(0.0, -5.0, 0.0) }); var surfaceLine2 = new MacroStabilityInwardsSurfaceLine("Surface line 2") { ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) }; surfaceLine2.SetGeometry(new[] { new Point3D(5.0, 5.0, 0.0), new Point3D(5.0, 0.0, 1.0), new Point3D(5.0, -5.0, 0.0) }); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); const string sourcePath = "path"; failureMechanism.SurfaceLines.AddRange(new[] { surfaceLine1, surfaceLine2 }, sourcePath); failureMechanism.StochasticSoilModels.AddRange(new[] { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }) }, sourcePath); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); return(failureMechanism); }
public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup var assessmentSection = new AssessmentSectionStub { ReferenceLine = new ReferenceLine() }; assessmentSection.ReferenceLine.SetGeometry(new[] { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); var geometryPoints = new[] { new Point2D(0.0, 0.0), new Point2D(2.0, 0.0), new Point2D(4.0, 4.0), new Point2D(6.0, 4.0) }; var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation() }); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("A", geometryPoints.Take(2)), new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)), new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2)) }); // Call DuneErosionFailureMechanismView view = CreateView(failureMechanism, assessmentSection); IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl; // Assert MapDataCollection mapData = map.Data; Assert.IsInstanceOf <MapDataCollection>(mapData); List <MapData> mapDataList = mapData.Collection.ToList(); Assert.AreEqual(2, mapDataList.Count); MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); AssertDuneLocationsMapData(failureMechanism, mapDataList[duneLocationsIndex]); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameIdRemoved_UpdatesCalculationInput() { // Setup const string sameId = "id"; var originalMatchingPoint = new Point2D(0, 0); ClosingStructure removedStructure = new TestClosingStructure(originalMatchingPoint, sameId); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = removedStructure } }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.ClosingStructures.AddRange(new[] { removedStructure }, sourceFilePath); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { originalMatchingPoint, new Point2D(10, 10) }) }); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <ClosingStructure>(), sourceFilePath); // Assert CollectionAssert.AreEqual(new IObservable[] { failureMechanism.ClosingStructures, calculation.InputParameters }, affectedObjects); }
public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized( PipingScenarioConfigurationType scenarioConfigurationType, PipingScenarioConfigurationPerFailureMechanismSectionType scenarioConfigurationPerFailureMechanismSectionType, string probability) { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); var failureMechanism = new PipingFailureMechanism { ScenarioConfigurationType = scenarioConfigurationType }; FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().ScenarioConfigurationType = scenarioConfigurationPerFailureMechanismSectionType; failureMechanism.CalculationsGroup.Children.Add( SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section)); failureMechanism.CalculationsGroup.Children.Add( ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section)); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism)) { DataGridView dataGridView = GetDataGridView(); // Assert DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(1, rows.Count); DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(columnCount, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(true, cells[isRelevantIndex].Value); Assert.AreEqual(AdoptableInitialFailureMechanismResultType.Adopt, cells[initialFailureMechanismResultTypeIndex].Value); Assert.AreEqual(probability, cells[initialFailureMechanismResultProfileProbabilityIndex].FormattedValue); Assert.AreEqual(probability, cells[initialFailureMechanismResultSectionProbabilityIndex].FormattedValue); Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value); Assert.AreEqual(ProbabilityRefinementType.Section, cells[probabilityRefinementTypeIndex].Value); Assert.AreEqual("<afgeleid>", cells[refinedProfileProbabilityIndex].FormattedValue); Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue); Assert.AreEqual("1/100", cells[profileProbabilityIndex].FormattedValue); Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue); Assert.AreEqual("10,00", cells[sectionNIndex].FormattedValue); Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue); } }
public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism { GeneralInput = { ApplyLengthEffectInSection = true } }; FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); failureMechanism.CalculationsGroup.Children.Add(GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateGrassCoverErosionInwardsCalculationScenario(section)); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism)) { DataGridView dataGridView = GetDataGridView(); // Assert DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(1, rows.Count); double probability = failureMechanism.SectionResults.First().GetInitialFailureMechanismResultProbability( failureMechanism.Calculations.OfType <GrassCoverErosionInwardsCalculationScenario>()); DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(columnCount, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(true, cells[isRelevantIndex].Value); Assert.AreEqual(AdoptableInitialFailureMechanismResultType.Adopt, cells[initialFailureMechanismResultTypeIndex].Value); Assert.AreEqual(probability, cells[initialFailureMechanismResultProfileProbabilityIndex].Value); Assert.AreEqual(probability, cells[initialFailureMechanismResultSectionProbabilityIndex].Value); Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value); Assert.AreEqual(ProbabilityRefinementType.Section, cells[probabilityRefinementTypeIndex].Value); Assert.AreEqual("<afgeleid>", cells[refinedProfileProbabilityIndex].FormattedValue); Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue); Assert.AreEqual("1/100", cells[profileProbabilityIndex].FormattedValue); Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue); Assert.AreEqual("10,00", cells[sectionNIndex].FormattedValue); Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue); } }
public void GivenStructuresFailureMechanismResultView_WhenNestedCalculationInputNotifiesObservers_ThenDataGridViewUpdatedAndAssemblyPerformed() { // Given var failureMechanism = new TestStructuresFailureMechanism(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); var calculationScenario = new TestStructuresCalculationScenario { InputParameters = { Structure = new TestStructure(section.StartPoint) } }; var calculationGroup = new CalculationGroup(); calculationGroup.Children.Add(calculationScenario); failureMechanism.CalculationsGroup.Children.Add(calculationGroup); int nrOfCalls = 0; Func <TestStructuresFailureMechanism, IAssessmentSection, FailureMechanismAssemblyResultWrapper> performFailureMechanismAssemblyFunc = (fm, ass) => { nrOfCalls++; return(new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.BOI1A1)); }; using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism, performFailureMechanismAssemblyFunc)) { var rowsChanged = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Rows.CollectionChanged += (sender, args) => rowsChanged = true; // Precondition Assert.AreEqual(1, nrOfCalls); Assert.IsFalse(rowsChanged); // When calculationScenario.InputParameters.NotifyObservers(); // Then Assert.AreEqual(2, nrOfCalls); Assert.IsTrue(rowsChanged); } }
public void GivenGrassCoverErosionInwardsFailureMechanismResultView_WhenApplyLengthEffectChangedAndFailureMechanismObserversNotified_ThenDataGridViewUpdated( bool useLengthEffect) { var failureMechanism = new GrassCoverErosionInwardsFailureMechanism { GeneralInput = { ApplyLengthEffectInSection = !useLengthEffect } }; FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); GrassCoverErosionInwardsCalculationScenario calculationScenario = GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateGrassCoverErosionInwardsCalculationScenario(section); failureMechanism.CalculationsGroup.Children.Add(calculationScenario); using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism)) { var rowsChanged = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Rows.CollectionChanged += (sender, args) => rowsChanged = true; // Precondition Assert.IsFalse(rowsChanged); Assert.AreEqual(!useLengthEffect, dataGridView.Columns[initialFailureMechanismResultProfileProbabilityIndex].Visible); Assert.AreEqual(!useLengthEffect, dataGridView.Columns[probabilityRefinementTypeIndex].Visible); Assert.AreEqual(!useLengthEffect, dataGridView.Columns[refinedProfileProbabilityIndex].Visible); Assert.AreEqual(!useLengthEffect, dataGridView.Columns[profileProbabilityIndex].Visible); Assert.AreEqual(!useLengthEffect, dataGridView.Columns[sectionNIndex].Visible); // When failureMechanism.GeneralInput.ApplyLengthEffectInSection = useLengthEffect; failureMechanism.NotifyObservers(); // Then Assert.IsTrue(rowsChanged); Assert.AreEqual(useLengthEffect, dataGridView.Columns[initialFailureMechanismResultProfileProbabilityIndex].Visible); Assert.AreEqual(useLengthEffect, dataGridView.Columns[probabilityRefinementTypeIndex].Visible); Assert.AreEqual(useLengthEffect, dataGridView.Columns[refinedProfileProbabilityIndex].Visible); Assert.AreEqual(useLengthEffect, dataGridView.Columns[profileProbabilityIndex].Visible); Assert.AreEqual(useLengthEffect, dataGridView.Columns[sectionNIndex].Visible); } }
public void GivenMacroStabilityInwardsFailureMechanismResultView_WhenNestedCalculationInputNotifiesObservers_ThenDataGridViewUpdatedAndAssemblyPerformed() { // Given var failureMechanism = new MacroStabilityInwardsFailureMechanism(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section); var calculationGroup = new CalculationGroup(); calculationGroup.Children.Add(calculationScenario); failureMechanism.CalculationsGroup.Children.Add(calculationGroup); using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism)) { var testFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub failureMechanismSectionAssemblyCalculator = testFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; failureMechanismSectionAssemblyCalculator.FailureMechanismSectionAssemblyResultOutput = new FailureMechanismSectionAssemblyResultWrapper( new FailureMechanismSectionAssemblyResult(1, 1, 1, FailureMechanismSectionAssemblyGroup.III), AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1); FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = testFactory.LastCreatedFailureMechanismAssemblyCalculator; IEnumerable <FailureMechanismSectionAssemblyResult> initialCalculatorInput = failureMechanismAssemblyCalculator.SectionAssemblyResultsInput .ToArray(); var rowsChanged = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Rows.CollectionChanged += (sender, args) => rowsChanged = true; // Precondition Assert.IsFalse(rowsChanged); // When calculationScenario.InputParameters.NotifyObservers(); // Then Assert.IsTrue(rowsChanged); IEnumerable <FailureMechanismSectionAssemblyResult> updatedCalculatorInput = failureMechanismAssemblyCalculator.SectionAssemblyResultsInput .ToArray(); CollectionAssert.AreNotEqual(initialCalculatorInput, updatedCalculatorInput); } }
public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); var failureMechanism = new TestStructuresFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); failureMechanism.CalculationsGroup.Children.Add(new TestStructuresCalculationScenario { InputParameters = { Structure = new TestStructure(section.StartPoint) } }); // Call using (new AssemblyToolCalculatorFactoryConfig()) using (ShowFailureMechanismResultsView(failureMechanism)) { DataGridView dataGridView = GetDataGridView(); // Assert DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(1, rows.Count); double probability = failureMechanism.SectionResults.First().GetInitialFailureMechanismResultProbability( failureMechanism.Calculations.OfType <TestStructuresCalculationScenario>()); DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(columnCount, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(true, cells[isRelevantIndex].Value); Assert.AreEqual(AdoptableInitialFailureMechanismResultType.Adopt, cells[initialFailureMechanismResultTypeIndex].Value); Assert.AreEqual(probability, cells[initialFailureMechanismResultSectionProbabilityIndex].Value); Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value); Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue); Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue); Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue); } }
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); }
private void ShowFullyConfiguredHeightStructuresScenariosView() { var structure1 = new TestHeightStructure(new Point2D(0.0, 0.0)); var structure2 = new TestHeightStructure(new Point2D(5.0, 0.0)); var failureMechanism = new HeightStructuresFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); failureMechanism.CalculationsGroup.Children.AddRange(new[] { new StructuresCalculationScenario <HeightStructuresInput> { Name = "Calculation 1", InputParameters = { Structure = structure1 } }, new StructuresCalculationScenario <HeightStructuresInput> { Name = "Calculation 2", InputParameters = { Structure = structure2 }, Output = new TestStructuresOutput(0.2) } }); ShowHeightStructuresScenariosView(failureMechanism); }
private void ShowFullyConfiguredGrassCoverErosionInwardsScenariosView() { DikeProfile dikeProfile1 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0)); DikeProfile dikeProfile2 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(5.0, 0.0)); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); failureMechanism.CalculationsGroup.Children.AddRange(new[] { new GrassCoverErosionInwardsCalculationScenario { Name = "Calculation 1", InputParameters = { DikeProfile = dikeProfile1 } }, new GrassCoverErosionInwardsCalculationScenario { Name = "Calculation 2", InputParameters = { DikeProfile = dikeProfile2 }, Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(0.2), null, null) } }); ShowGrassCoverErosionInwardsScenariosView(failureMechanism); }
public void SetSections_WithSection_SetsSectionResults() { // Setup var failureMechanism = new PipingFailureMechanism(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); // Call FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); // Assert Assert.AreEqual(1, failureMechanism.Sections.Count()); Assert.AreEqual(1, failureMechanism.SectionResults.Count()); Assert.AreSame(section, failureMechanism.SectionResults.First().Section); Assert.AreEqual(1, failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.Count()); Assert.AreSame(section, failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().Section); }
public void CalculationsView_ChangingStructures_ButtonCorrectState() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); var failureMechanism = new ClosingStructuresFailureMechanism(); ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); // Precondition var button = (Button) new ControlTester("generateButton").TheObject; Assert.IsFalse(button.Enabled); var section = new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section }); failureMechanism.ClosingStructures.AddRange(new List <ClosingStructure> { new TestClosingStructure(new Point2D(0.0, 0.0), "Structure 1"), new TestClosingStructure(new Point2D(0.0, 0.0), "Structure 2") }, string.Empty); // Call failureMechanism.ClosingStructures.NotifyObservers(); // Assert Assert.IsTrue(button.Enabled); mocks.VerifyAll(); }