public void Constructor_CalculationWithOutput_DataSetToChartControl() { // Setup MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); // Call using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var view = new MacroStabilityInwardsOutputView(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) using (var form = new Form()) { form.Controls.Add(view); form.Show(); MacroStabilityInwardsOutputChartControl chartControl = GetChartControl(form); // Assert Assert.AreSame(calculation, chartControl.Data); } }
public void UpdateModelWithImportedData_CalculationWithOutputAssignedRemovedSoilModelAndProfile_CalculationUpdatedAndCalculationAndInputReturned() { // Setup MacroStabilityInwardsStochasticSoilModel existingModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilModel = existingModel, StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(0) }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculation); MacroStabilityInwardsStochasticSoilModelCollection stochasticSoilModelCollection = failureMechanism.StochasticSoilModels; stochasticSoilModelCollection.AddRange(new[] { existingModel }, sourceFilePath); var strategy = new MacroStabilityInwardsStochasticSoilModelUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new List <MacroStabilityInwardsStochasticSoilModel>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.StochasticSoilModel); Assert.IsNull(calculation.InputParameters.StochasticSoilProfile); CollectionAssert.AreEquivalent(new IObservable[] { stochasticSoilModelCollection, calculation, calculation.InputParameters }, affectedObjects); }
public void ClearAllCalculationOutputWithoutManualAssessmentLevel_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedCalculations() { // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.AddRange(new[] { new MacroStabilityInwardsCalculationScenario(), new MacroStabilityInwardsCalculationScenario { InputParameters = { UseAssessmentLevelManualInput = true }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }, new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() } }); MacroStabilityInwardsCalculationScenario[] expectedAffectedCalculations = failureMechanism.Calculations .OfType <MacroStabilityInwardsCalculationScenario>() .Where(c => !c.InputParameters.UseAssessmentLevelManualInput && c.HasOutput) .ToArray(); // Call IEnumerable <IObservable> affectedItems = MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutputWithoutManualAssessmentLevel(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: Assert.IsTrue(failureMechanism.Calculations .OfType <MacroStabilityInwardsCalculationScenario>() .Where(c => !c.InputParameters.UseAssessmentLevelManualInput) .All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedCalculations, affectedItems); }
public void UpdateSurfaceLinesWithImportedData_CalculationWithOutputAndAssignedLineDeleted_ClearsCalculationOutput() { // Setup MacroStabilityInwardsSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); var calculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = surfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculation); MacroStabilityInwardsSurfaceLineCollection surfaceLineCollection = failureMechanism.SurfaceLines; surfaceLineCollection.AddRange(new[] { surfaceLine }, sourceFilePath); var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.SurfaceLine); CollectionAssert.AreEquivalent(new IObservable[] { surfaceLineCollection, calculation, calculation.InputParameters }, affectedObjects); }
public void GivenCalculationWithOutput_WhenOutputCleared_ThenChartDataUpdated() { // Given MacroStabilityInwardsSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { SurfaceLine = surfaceLine, StochasticSoilProfile = stochasticSoilProfile }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; using (var form = new Form()) using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var view = new MacroStabilityInwardsOutputView(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) { form.Controls.Add(view); form.Show(); MacroStabilityInwardsOutputChartControl chartControl = GetChartControl(form); // Precondition ChartDataCollection chartData = GetChartControl(chartControl).Data; MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData); // When calculation.ClearOutput(); calculation.NotifyObservers(); // Then MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyChartDataWithEmptySoilLayerAndWithWaternetChartData(chartData); } }
public void Constructor_Always_PropertiesHaveExpectedAttributesValues() { MacroStabilityInwardsOutput output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); // Call var properties = new MacroStabilityInwardsOutputProperties(output, 1.1); // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(3, dynamicProperties.Count); const string macroStabilityInwardsCategory = "Macrostabiliteit binnenwaarts"; PropertyDescriptor stabilityFactorProperty = dynamicProperties[0]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(stabilityFactorProperty, macroStabilityInwardsCategory, "Stabiliteitsfactor [-]", "Het quotiënt van de weerstandbiedende- en aandrijvende krachten langs een glijvlak.", true); PropertyDescriptor macroStabilityInwardsProbabilityProperty = dynamicProperties[1]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(macroStabilityInwardsProbabilityProperty, macroStabilityInwardsCategory, "Benaderde faalkans [1/jaar]", "De benaderde kans dat het faalmechanisme macrostabiliteit binnenwaarts optreedt voor deze berekening.", true); PropertyDescriptor macroStabilityInwardsReliabilityProperty = dynamicProperties[2]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(macroStabilityInwardsReliabilityProperty, macroStabilityInwardsCategory, "Betrouwbaarheidsindex faalkans [-]", "De betrouwbaarheidsindex van de faalkans voor deze berekening.", true); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); failureMechanism.CalculationsGroup.Children.Add(new MacroStabilityInwardsCalculationScenario { InputParameters = { UseAssessmentLevelManualInput = true }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }); MacroStabilityInwardsCalculation[] calculations = failureMechanism.Calculations .Cast <MacroStabilityInwardsCalculation>() .ToArray(); var expectedAffectedItems = new List <IObservable>(); expectedAffectedItems.AddRange(calculations.Where(c => !c.InputParameters.UseAssessmentLevelManualInput && c.HasOutput)); expectedAffectedItems.AddRange(calculations.Select(c => c.InputParameters) .Where(i => i.HydraulicBoundaryLocation != null)); // Call IEnumerable <IObservable> affectedItems = MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(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: Assert.IsTrue(calculations.Where(c => !c.InputParameters.UseAssessmentLevelManualInput) .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); }
public void GivenScenarioRow_WhenOutputChangedAndUpdate_ThenDerivedOutputUpdated() { // Given var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var row = new MacroStabilityInwardsScenarioRow(calculation, failureMechanism, failureMechanismSection); // Precondition DerivedMacroStabilityInwardsOutput expectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor); Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability); Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN( failureMechanismSection.Length), row.SectionFailureProbability); var random = new Random(11); // When calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = random.NextDouble() }); row.Update(); // Then DerivedMacroStabilityInwardsOutput newExpectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor); Assert.AreEqual(newExpectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability); Assert.AreEqual(newExpectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN( failureMechanismSection.Length), row.SectionFailureProbability); }
public void UpdateChartData_CalculationWithoutOutputWithoutWaternet_ChartDataUpdated() { // Setup MacroStabilityInwardsSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { SurfaceLine = surfaceLine, StochasticSoilProfile = stochasticSoilProfile }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var control = new MacroStabilityInwardsOutputChartControl(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) { ChartDataCollection chartData = GetChartControl(control).Data; // Precondition MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData); MacroStabilityInwardsOutputViewChartDataAssert.AssertOutputChartData(calculation, chartData); calculation.ClearOutput(); // Call control.UpdateChartData(); // Assert MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyChartDataWithEmptySoilLayerAndWithWaternetChartData(chartData); MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyOutputChartData(chartData); } }
public void ContextMenuStrip_MacroStabilityInwardsCalculationWithOutput_ContextMenuItemClearOutputEnabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var nodeData = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuClearIndex, "&Wis uitvoer...", "Wis de uitvoer van deze berekening.", RiskeerCommonFormsResources.ClearIcon); } } }
public void ContextMenuStrip_MacroStabilityInwardsFailureMechanismWithOutput_ContextMenuItemClearAllOutputEnabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculation); var assessmentSection = mocks.Stub <IAssessmentSection>(); var context = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; failureMechanism.CalculationsGroup.Children.Add(calculation); // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) { // Assert ToolStripItem clearOutputItem = contextMenu.Items[contextMenuClearIndex]; Assert.IsTrue(clearOutputItem.Enabled); Assert.AreEqual("Wis de uitvoer van alle berekeningen binnen dit faalmechanisme.", clearOutputItem.ToolTipText); } } }
public void UpdateModelWithImportedData_ProfilesAssignedToCalculationsOneWithRemovedProfile_OnlyCalculationWithRemovedProfileUpdated() { // Setup const string modelsName = "same model"; MacroStabilityInwardsStochasticSoilModel existingModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(modelsName, CreateStochasticSoilProfiles()); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels; targetCollection.AddRange(new[] { existingModel }, sourceFilePath); MacroStabilityInwardsStochasticSoilProfile removedProfile = existingModel.StochasticSoilProfiles.ElementAt(0); MacroStabilityInwardsStochasticSoilProfile unaffectedProfile = existingModel.StochasticSoilProfiles.ElementAt(1); List <MacroStabilityInwardsStochasticSoilProfile> readStochasticSoilProfiles = CreateStochasticSoilProfiles(); readStochasticSoilProfiles.RemoveAt(0); MacroStabilityInwardsStochasticSoilModel readModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(modelsName, readStochasticSoilProfiles); var calculationWithRemovedProfile = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilModel = existingModel, StochasticSoilProfile = removedProfile }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var calculationWithNotUpdatedProfile = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilModel = existingModel, StochasticSoilProfile = unaffectedProfile }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; failureMechanism.CalculationsGroup.Children.Add(calculationWithNotUpdatedProfile); failureMechanism.CalculationsGroup.Children.Add(calculationWithRemovedProfile); var strategy = new MacroStabilityInwardsStochasticSoilModelUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new[] { readModel }, sourceFilePath).ToArray(); // Assert MacroStabilityInwardsStochasticSoilModel firstSoilModel = targetCollection[0]; Assert.AreSame(existingModel, firstSoilModel); Assert.AreEqual(1, firstSoilModel.StochasticSoilProfiles.Count()); Assert.AreSame(unaffectedProfile, firstSoilModel.StochasticSoilProfiles.ElementAt(0)); Assert.IsFalse(calculationWithRemovedProfile.HasOutput); Assert.IsNull(calculationWithRemovedProfile.InputParameters.StochasticSoilProfile); Assert.IsTrue(calculationWithNotUpdatedProfile.HasOutput); Assert.AreSame(unaffectedProfile, calculationWithNotUpdatedProfile.InputParameters.StochasticSoilProfile); CollectionAssert.AreEquivalent(new IObservable[] { targetCollection, firstSoilModel, calculationWithRemovedProfile, calculationWithRemovedProfile.InputParameters }, affectedObjects); }
public void UpdateModelWithImportedData_ProfilesAssignedToCalculationsWithOneImportedModelProfileRemoved_OneProfileRemovedCalculationUpdatedAccordingly() { // Setup const string modelsName = "same model"; MacroStabilityInwardsStochasticSoilModel existingModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(modelsName, CreateStochasticSoilProfiles()); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels; targetCollection.AddRange(new[] { existingModel }, sourceFilePath); MacroStabilityInwardsStochasticSoilProfile firstExistingProfile = existingModel.StochasticSoilProfiles.ElementAt(0); MacroStabilityInwardsStochasticSoilModel readModel = CreateSimpleModel(modelsName, firstExistingProfile.SoilProfile.Name); var calculationWithNotUpdatedProfile = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilModel = existingModel, StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(0) }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var calculationWithDeletedProfile = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilModel = existingModel, StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(1) }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; failureMechanism.CalculationsGroup.Children.Add(calculationWithDeletedProfile); failureMechanism.CalculationsGroup.Children.Add(calculationWithNotUpdatedProfile); var strategy = new MacroStabilityInwardsStochasticSoilModelUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new[] { readModel }, sourceFilePath).ToArray(); // Assert MacroStabilityInwardsStochasticSoilModel firstSoilModel = targetCollection[0]; Assert.AreSame(existingModel, firstSoilModel); Assert.AreEqual(1, firstSoilModel.StochasticSoilProfiles.Count()); Assert.AreSame(firstExistingProfile, firstSoilModel.StochasticSoilProfiles.ElementAt(0)); Assert.IsTrue(calculationWithNotUpdatedProfile.HasOutput); CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile); CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile.InputParameters); Assert.IsFalse(calculationWithDeletedProfile.HasOutput); Assert.IsNull(calculationWithDeletedProfile.InputParameters.StochasticSoilProfile); CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile); CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile.InputParameters); }
public void ContextMenuStrip_HasCalculationWithOutput_ReturnsContextMenuWithCommonItems() { // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; failureMechanism.CalculationsGroup.Children.Add(calculation); var assessmentSection = mocks.Stub <IAssessmentSection>(); var context = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); var applicationFeatureCommandHandler = mocks.Stub <IApplicationFeatureCommands>(); var importCommandHandler = mocks.Stub <IImportCommandHandler>(); var exportCommandHandler = mocks.Stub <IExportCommandHandler>(); var updateCommandHandler = mocks.Stub <IUpdateCommandHandler>(); var viewCommandsHandler = mocks.Stub <IViewCommands>(); using (var treeViewControl = new TreeViewControl()) { var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, importCommandHandler, exportCommandHandler, updateCommandHandler, viewCommandsHandler, context, treeViewControl); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(context, null, treeViewControl)) { // Assert Assert.AreEqual(11, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, 0, "&Openen", "Open de gegevens in een nieuw documentvenster.", CoreGuiResources.OpenIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, 2, "Alles &valideren", "Valideer alle berekeningen binnen dit faalmechanisme.", RiskeerCommonFormsResources.ValidateAllIcon); TestHelper.AssertContextMenuStripContainsItem(menu, 3, "Alles be&rekenen", "Voer alle berekeningen binnen dit faalmechanisme uit.", RiskeerCommonFormsResources.CalculateAllIcon); TestHelper.AssertContextMenuStripContainsItem(menu, 5, "&Wis alle uitvoer...", "Wis de uitvoer van alle berekeningen binnen dit faalmechanisme.", RiskeerCommonFormsResources.ClearIcon); TestHelper.AssertContextMenuStripContainsItem(menu, 7, "Alles i&nklappen", "Klap dit element en alle onderliggende elementen in.", CoreGuiResources.CollapseAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, 8, "Alles ui&tklappen", "Klap dit element en alle onderliggende elementen uit.", CoreGuiResources.ExpandAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, 10, "Ei&genschappen", "Toon de eigenschappen in het Eigenschappenpaneel.", CoreGuiResources.PropertiesHS, false); CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[1], menu.Items[4], menu.Items[6], menu.Items[9] }, typeof(ToolStripSeparator)); } } }
private void ShowFullyConfiguredMacroStabilityInwardsScenariosView() { 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(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(80.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(80.0, 0.0), new Point2D(90.0, 0.0) }) }); failureMechanism.CalculationsGroup.Children.AddRange(new[] { new MacroStabilityInwardsCalculationScenario { Name = "Calculation 1", InputParameters = { SurfaceLine = surfaceLine1 } }, new MacroStabilityInwardsCalculationScenario { Name = "Calculation 2", InputParameters = { SurfaceLine = surfaceLine2 }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = 0.8 }) } }); ShowMacroStabilityInwardsScenariosView(failureMechanism); }
public void UpdateSurfaceLinesWithImportedData_MultipleCalculationsWithSurfaceLinesOneWithRemovedLine_OnlyUpdatesCalculationWithRemovedSurfaceLine() { // Setup const string removedSurfaceLineName = "Name A"; const string unaffectedSurfaceLineName = "Name B"; var removedSurfaceLine = new MacroStabilityInwardsSurfaceLine(removedSurfaceLineName); removedSurfaceLine.SetGeometry(new[] { new Point3D(1, 2, 3), new Point3D(4, 5, 6) }); var affectedCalculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = removedSurfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var unaffectedGeometry = new[] { new Point3D(10, 9, 8), new Point3D(7, 6, 5) }; var unaffectedSurfaceLine = new MacroStabilityInwardsSurfaceLine(unaffectedSurfaceLineName); unaffectedSurfaceLine.SetGeometry(unaffectedGeometry); var unAffectedCalculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = unaffectedSurfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); MacroStabilityInwardsSurfaceLineCollection collection = failureMechanism.SurfaceLines; collection.AddRange(new[] { removedSurfaceLine, unaffectedSurfaceLine }, sourceFilePath); failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); failureMechanism.CalculationsGroup.Children.Add(unAffectedCalculation); MacroStabilityInwardsSurfaceLine importedUnaffectedSurfaceLine = DeepCloneName(unaffectedSurfaceLine); importedUnaffectedSurfaceLine.SetGeometry(unaffectedGeometry); var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(new[] { importedUnaffectedSurfaceLine }, "path").ToArray(); // Assert Assert.IsTrue(unAffectedCalculation.HasOutput); MacroStabilityInwardsInput unaffectedInput = unAffectedCalculation.InputParameters; Assert.AreSame(unaffectedSurfaceLine, unaffectedInput.SurfaceLine); Assert.AreEqual(unaffectedSurfaceLine, unaffectedInput.SurfaceLine); Assert.IsFalse(affectedCalculation.HasOutput); MacroStabilityInwardsInput affectedInput = affectedCalculation.InputParameters; Assert.IsNull(affectedInput.SurfaceLine); CollectionAssert.AreEquivalent(new IObservable[] { collection, affectedCalculation, affectedInput }, affectedObjects); }
public void GivenMultipleCalculationsWithOutput_WhenClearingOutputFromContextMenu_ThenOutputCleared(bool confirm) { // Given using (var treeViewControl = new TreeViewControl()) { var calculation1 = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var calculation2 = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var observer = mocks.StrictMock <IObserver>(); if (confirm) { observer.Expect(o => o.UpdateObserver()).Repeat.Twice(); } var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculation1); failureMechanism.CalculationsGroup.Children.Add(calculation2); var assessmentSection = mocks.Stub <IAssessmentSection>(); var context = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; failureMechanism.CalculationsGroup.Children.Add(calculation1); failureMechanism.CalculationsGroup.Children.Add(calculation2); failureMechanism.CalculationsGroup.Children.ElementAt(0).Attach(observer); failureMechanism.CalculationsGroup.Children.ElementAt(1).Attach(observer); string messageBoxTitle = null, messageBoxText = null; DialogBoxHandler = (name, wnd) => { var messageBox = new MessageBoxTester(wnd); messageBoxText = messageBox.Text; messageBoxTitle = messageBox.Title; if (confirm) { messageBox.ClickOk(); } else { messageBox.ClickCancel(); } }; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(context, null, treeViewControl)) { // When contextMenuStrip.Items[contextMenuClearIndex].PerformClick(); // Then foreach (ICalculation calc in failureMechanism.CalculationsGroup.Children.OfType <ICalculation>()) { Assert.AreNotEqual(confirm, calc.HasOutput); } Assert.AreEqual("Bevestigen", messageBoxTitle); Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); } } }