Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -rfd572b1d0d0be95b5218314d9022665514b68caf -rbd58395dc91037106a3c2136b918eeb7012507ab --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision fd572b1d0d0be95b5218314d9022665514b68caf) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision bd58395dc91037106a3c2136b918eeb7012507ab) @@ -25,6 +25,7 @@ using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; +using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Helpers; @@ -406,31 +407,39 @@ }; } - private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(StabilityPointStructuresFailureMechanismContext failureMechanismContext, + private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(StabilityPointStructuresFailureMechanismContext context, object parentData, TreeViewControl treeViewControl) { - IEnumerable> calculations = failureMechanismContext.WrappedData - .Calculations - .Cast>(); + StructuresCalculation[] calculations = context.WrappedData + .Calculations + .Cast>() + .ToArray(); IInquiryHelper inquiryHelper = GetInquiryHelper(); - var builder = new RiskeerContextMenuBuilder(Gui.Get(failureMechanismContext, treeViewControl)); + IViewCommands viewCommands = Gui.ViewCommands; + + var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); + return builder.AddOpenItem() .AddSeparator() - .AddToggleRelevancyOfFailureMechanismItem(failureMechanismContext, RemoveAllViewsForItem) + .AddToggleRelevancyOfFailureMechanismItem(context, RemoveAllViewsForItem) .AddSeparator() .AddValidateAllCalculationsInFailureMechanismItem( - failureMechanismContext, + context, ValidateAllInFailureMechanism, EnableValidateAndCalculateMenuItemForFailureMechanism) .AddPerformAllCalculationsInFailureMechanismItem( - failureMechanismContext, + context, CalculateAllInFailureMechanism, EnableValidateAndCalculateMenuItemForFailureMechanism) .AddSeparator() - .AddClearAllCalculationOutputInFailureMechanismItem(failureMechanismContext.WrappedData) - .AddClearIllustrationPointsOfCalculationsInFailureMechanismItem(() => IllustrationPointsHelper.HasIllustrationPoints(calculations), - CreateChangeHandler(inquiryHelper, calculations)) + .AddClearAllCalculationOutputInFailureMechanismItem( + () => calculations.Any(c => c.HasOutput), + new StructuresClearCalculationOutputChangeHandler( + calculations.Where(c => c.HasOutput), inquiryHelper, viewCommands)) + .AddClearIllustrationPointsOfCalculationsInFailureMechanismItem( + () => IllustrationPointsHelper.HasIllustrationPoints(calculations), + CreateChangeHandler(inquiryHelper, calculations)) .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -rb0021e52ef17e3101d6e7089e3052ceb4621f3fe -rbd58395dc91037106a3c2136b918eeb7012507ab --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision b0021e52ef17e3101d6e7089e3052ceb4621f3fe) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision bd58395dc91037106a3c2136b918eeb7012507ab) @@ -71,35 +71,34 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, nameof(HydraulicBoundaryDatabase)); private MockRepository mocksRepository; + private StabilityPointStructuresPlugin plugin; + private TreeNodeInfo info; [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Setup - using (var plugin = new StabilityPointStructuresPlugin()) - { - TreeNodeInfo info = GetInfo(plugin); + mocksRepository.ReplayAll(); - // Assert - Assert.IsNotNull(info.Text); - Assert.IsNotNull(info.ForeColor); - Assert.IsNotNull(info.Image); - Assert.IsNotNull(info.ContextMenuStrip); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.ExpandOnCreate); - Assert.IsNotNull(info.ChildNodeObjects); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.CheckedState); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); - } + // Assert + Assert.IsNotNull(info.Text); + Assert.IsNotNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ExpandOnCreate); + Assert.IsNotNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.CheckedState); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); } [Test] @@ -111,75 +110,69 @@ var failureMechanism = new StabilityPointStructuresFailureMechanism(); var failureMechanismContext = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); - using (var plugin = new StabilityPointStructuresPlugin()) - { - TreeNodeInfo info = GetInfo(plugin); + // Call + object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); - // Call - object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + // Assert + Assert.AreEqual(3, children.Length); - // Assert - Assert.AreEqual(3, children.Length); + var inputsFolder = (CategoryTreeFolder) children[0]; + Assert.AreEqual("Invoer", inputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); - var inputsFolder = (CategoryTreeFolder) children[0]; - Assert.AreEqual("Invoer", inputsFolder.Name); - Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); + Assert.AreEqual(4, inputsFolder.Contents.Count()); + var failureMechanismSectionsContext = (StabilityPointStructuresFailureMechanismSectionsContext) inputsFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismSectionsContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismSectionsContext.AssessmentSection); - Assert.AreEqual(4, inputsFolder.Contents.Count()); - var failureMechanismSectionsContext = (StabilityPointStructuresFailureMechanismSectionsContext) inputsFolder.Contents.ElementAt(0); - Assert.AreSame(failureMechanism, failureMechanismSectionsContext.WrappedData); - Assert.AreSame(assessmentSection, failureMechanismSectionsContext.AssessmentSection); + var profilesContext = (ForeshoreProfilesContext) inputsFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism.ForeshoreProfiles, profilesContext.WrappedData); + Assert.AreSame(failureMechanism, profilesContext.ParentFailureMechanism); + Assert.AreSame(assessmentSection, profilesContext.ParentAssessmentSection); - var profilesContext = (ForeshoreProfilesContext) inputsFolder.Contents.ElementAt(1); - Assert.AreSame(failureMechanism.ForeshoreProfiles, profilesContext.WrappedData); - Assert.AreSame(failureMechanism, profilesContext.ParentFailureMechanism); - Assert.AreSame(assessmentSection, profilesContext.ParentAssessmentSection); + var stabilityPointStructuresContext = (StabilityPointStructuresContext) inputsFolder.Contents.ElementAt(2); + Assert.AreSame(failureMechanism.StabilityPointStructures, stabilityPointStructuresContext.WrappedData); + Assert.AreSame(failureMechanism, stabilityPointStructuresContext.FailureMechanism); + Assert.AreSame(assessmentSection, stabilityPointStructuresContext.AssessmentSection); - var stabilityPointStructuresContext = (StabilityPointStructuresContext) inputsFolder.Contents.ElementAt(2); - Assert.AreSame(failureMechanism.StabilityPointStructures, stabilityPointStructuresContext.WrappedData); - Assert.AreSame(failureMechanism, stabilityPointStructuresContext.FailureMechanism); - Assert.AreSame(assessmentSection, stabilityPointStructuresContext.AssessmentSection); + var inputComment = (Comment) inputsFolder.Contents.ElementAt(3); + Assert.AreSame(failureMechanism.InputComments, inputComment); - var inputComment = (Comment) inputsFolder.Contents.ElementAt(3); - Assert.AreSame(failureMechanism.InputComments, inputComment); + var calculationsFolder = (StabilityPointStructuresCalculationGroupContext) children[1]; + Assert.AreSame(failureMechanism.CalculationsGroup, calculationsFolder.WrappedData); + Assert.IsNull(calculationsFolder.Parent); + Assert.AreSame(failureMechanism, calculationsFolder.FailureMechanism); - var calculationsFolder = (StabilityPointStructuresCalculationGroupContext) children[1]; - Assert.AreSame(failureMechanism.CalculationsGroup, calculationsFolder.WrappedData); - Assert.IsNull(calculationsFolder.Parent); - Assert.AreSame(failureMechanism, calculationsFolder.FailureMechanism); + var outputsFolder = (CategoryTreeFolder) children[2]; + Assert.AreEqual("Oordeel", outputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); - var outputsFolder = (CategoryTreeFolder) children[2]; - Assert.AreEqual("Oordeel", outputsFolder.Name); - Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); - Assert.AreEqual(4, outputsFolder.Contents.Count()); + Assert.AreEqual(4, outputsFolder.Contents.Count()); - var failureMechanismAssemblyCategoriesContext = (FailureMechanismAssemblyCategoriesContext) outputsFolder.Contents.ElementAt(0); - Assert.AreSame(failureMechanism, failureMechanismAssemblyCategoriesContext.WrappedData); - Assert.AreSame(assessmentSection, failureMechanismAssemblyCategoriesContext.AssessmentSection); + var failureMechanismAssemblyCategoriesContext = (FailureMechanismAssemblyCategoriesContext) outputsFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismAssemblyCategoriesContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismAssemblyCategoriesContext.AssessmentSection); - using (new AssemblyToolCalculatorFactoryConfig()) - { - var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; - AssemblyCategoriesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyCategoriesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; - failureMechanismAssemblyCategoriesContext.GetFailureMechanismSectionAssemblyCategoriesFunc(); - Assert.AreEqual(failureMechanism.GeneralInput.N, calculator.AssemblyCategoriesInput.N); - } + failureMechanismAssemblyCategoriesContext.GetFailureMechanismSectionAssemblyCategoriesFunc(); + Assert.AreEqual(failureMechanism.GeneralInput.N, calculator.AssemblyCategoriesInput.N); + } - var scenariosContext = (StabilityPointStructuresScenariosContext) outputsFolder.Contents.ElementAt(1); - Assert.AreSame(failureMechanism, scenariosContext.ParentFailureMechanism); - Assert.AreSame(failureMechanism.CalculationsGroup, scenariosContext.WrappedData); + var scenariosContext = (StabilityPointStructuresScenariosContext) outputsFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism.CalculationsGroup, scenariosContext.WrappedData); + Assert.AreSame(failureMechanism, scenariosContext.ParentFailureMechanism); - var failureMechanismResultsContext = (ProbabilityFailureMechanismSectionResultContext) outputsFolder.Contents.ElementAt(2); - Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); - Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); - Assert.AreSame(assessmentSection, failureMechanismResultsContext.AssessmentSection); + var failureMechanismResultsContext = (ProbabilityFailureMechanismSectionResultContext) outputsFolder.Contents.ElementAt(2); + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismResultsContext.AssessmentSection); - var outputComment = (Comment) outputsFolder.Contents.ElementAt(3); - Assert.AreSame(failureMechanism.OutputComments, outputComment); - } - - mocksRepository.VerifyAll(); + var outputComment = (Comment) outputsFolder.Contents.ElementAt(3); + Assert.AreSame(failureMechanism.OutputComments, outputComment); } [Test] @@ -195,20 +188,13 @@ }; var failureMechanismContext = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); - using (var plugin = new StabilityPointStructuresPlugin()) - { - TreeNodeInfo info = GetInfo(plugin); + // Call + object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); - // Call - object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); - - // Assert - Assert.AreEqual(1, children.Length); - var comment = (Comment) children[0]; - Assert.AreSame(failureMechanism.NotRelevantComments, comment); - } - - mocksRepository.VerifyAll(); + // Assert + Assert.AreEqual(1, children.Length); + var comment = (Comment) children[0]; + Assert.AreSame(failureMechanism.NotRelevantComments, comment); } [Test] @@ -239,23 +225,22 @@ menuBuilder.Expect(mb => mb.Build()).Return(null); } - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); // Call info.ContextMenuStrip(failureMechanismContext, null, treeViewControl); } // Assert - mocksRepository.VerifyAll(); + // Assert is done in TearDown } [Test] @@ -281,7 +266,6 @@ menuBuilder.Expect(mb => mb.Build()).Return(null); } - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); @@ -290,21 +274,18 @@ plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - // Call info.ContextMenuStrip(failureMechanismContext, null, treeViewControl); } // Assert - mocksRepository.VerifyAll(); + // Assert is done in TearDown } [Test] public void ContextMenuStrip_FailureMechanismIsRelevant_AddCustomItems() { // Setup - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeView = new TreeViewControl()) { var assessmentSection = mocksRepository.Stub(); @@ -317,12 +298,11 @@ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - // Call using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSection, treeView)) { @@ -339,7 +319,6 @@ "Er zijn geen berekeningen om te valideren.", RiskeerCommonFormsResources.ValidateAllIcon, false); - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex, "Alles be&rekenen", "Er zijn geen berekeningen om uit te voeren.", @@ -358,15 +337,12 @@ false); } } - - mocksRepository.VerifyAll(); } [Test] public void ContextMenuStrip_FailureMechanismIsNotRelevant_AddCustomItems() { // Setup - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeView = new TreeViewControl()) { var assessmentSection = mocksRepository.Stub(); @@ -385,8 +361,6 @@ plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - // Call using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSection, treeView)) { @@ -399,8 +373,6 @@ RiskeerCommonFormsResources.Checkbox_empty); } } - - mocksRepository.VerifyAll(); } [Test] @@ -415,7 +387,6 @@ viewCommands.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext)); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); @@ -426,8 +397,6 @@ plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) { // Call @@ -437,8 +406,6 @@ Assert.IsFalse(failureMechanism.IsRelevant); } } - - mocksRepository.VerifyAll(); } [Test] @@ -456,19 +423,15 @@ viewCommands.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext)); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.ViewCommands).Return(viewCommands); gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) { // Call @@ -478,31 +441,28 @@ Assert.IsTrue(failureMechanism.IsRelevant); } } - - mocksRepository.VerifyAll(); } [Test] public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() { // Setup - var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocksRepository); var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); - TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call @@ -528,23 +488,22 @@ public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() { // Setup - var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); - TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call @@ -554,14 +513,14 @@ ToolStripItem calculateAllContextMenuItem = contextMenu.Items[contextMenuCalculateAllIndex]; Assert.AreEqual("Alles be&rekenen", calculateAllContextMenuItem.Text); - StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", calculateAllContextMenuItem.ToolTipText); + StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. ", calculateAllContextMenuItem.ToolTipText); TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateAllIcon, calculateAllContextMenuItem.Image); Assert.IsFalse(calculateAllContextMenuItem.Enabled); ToolStripItem validateAllContextMenuItem = contextMenu.Items[contextMenuValidateAllIndex]; Assert.AreEqual("Alles &valideren", validateAllContextMenuItem.Text); - StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", validateAllContextMenuItem.ToolTipText); + StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. ", validateAllContextMenuItem.ToolTipText); TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ValidateAllIcon, validateAllContextMenuItem.Image); Assert.IsFalse(validateAllContextMenuItem.Enabled); } @@ -572,10 +531,11 @@ public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled() { // Setup - var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { FilePath = validFilePath, @@ -589,15 +549,14 @@ var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); - TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call @@ -621,10 +580,9 @@ public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations() { // Setup - var mainWindow = mocksRepository.Stub(); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculationScenario { Name = "A", @@ -661,12 +619,12 @@ var failureMechanismContext = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); int nrOfCalculators = failureMechanism.Calculations.Count(); var calculatorFactory = mocksRepository.Stub(); @@ -683,7 +641,6 @@ .Times(nrOfCalculators); mocksRepository.ReplayAll(); - TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; DialogBoxHandler = (name, wnd) => @@ -725,29 +682,26 @@ public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations() { // Setup - var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculationScenario { Name = "A", InputParameters = { - HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), - InflowModelType = StabilityPointStructureInflowModelType.LowSill, - LoadSchematizationType = LoadSchematizationType.Linear + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() } }); failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculationScenario { Name = "B", InputParameters = { - HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), - InflowModelType = StabilityPointStructureInflowModelType.LowSill, - LoadSchematizationType = LoadSchematizationType.Linear + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() } }); string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { FilePath = validFilePath @@ -759,17 +713,16 @@ var failureMechanismContext = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) { @@ -792,28 +745,246 @@ } [Test] + public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() + { + // Setup + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + calculationWithOutput, + new StructuresCalculationScenario() + } + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearAllIndex]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + new StructuresCalculationScenario() + } + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearAllIndex]; + + // Assert + Assert.IsFalse(toolStripItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndAborted_ThenInquiryAndCalculationsOutputNotCleared() + { + // Given + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + calculationWithOutput, + new StructuresCalculationScenario() + } + } + }; + + var calculationObserver = mocksRepository.StrictMock(); + calculationWithOutput.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.StrictMock()); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearAllIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + + Assert.IsTrue(calculationWithOutput.HasOutput); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndContinued_ThenInquiryAndOutputViewsClosedAndCalculationsOutputCleared() + { + // Given + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var calculationWithoutOutput = new StructuresCalculationScenario(); + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + calculationWithOutput, + calculationWithoutOutput + } + } + }; + + var affectedCalculationObserver = mocksRepository.StrictMock(); + affectedCalculationObserver.Expect(o => o.UpdateObserver()); + calculationWithOutput.Attach(affectedCalculationObserver); + + var unaffectedCalculationObserver = mocksRepository.StrictMock(); + calculationWithoutOutput.Attach(unaffectedCalculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var viewCommands = mocksRepository.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculationWithOutput.Output)); + + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearAllIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + + Assert.IsFalse(calculationWithOutput.HasOutput); + } + } + } + + [Test] public void ContextMenuStrip_FailureMechanismWithCalculationsContainingIllustrationPoints_ContextMenuItemClearIllustrationPointsEnabled() { // Setup - var calculationWithIllustrationPoints = new TestStabilityPointStructuresCalculationScenario + var calculationWithIllustrationPoints = new StructuresCalculationScenario { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) }; - var calculationWithOutput = new TestStabilityPointStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; - var failureMechanism = new TestStabilityPointStructuresFailureMechanism + var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculationWithIllustrationPoints, calculationWithOutput, - new TestStabilityPointStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -823,18 +994,16 @@ var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Call @@ -850,19 +1019,19 @@ public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutIllustrationPoints_ContextMenuItemClearIllustrationPointsDisabled() { // Setup - var calculationWithOutput = new TestStabilityPointStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; - var failureMechanism = new TestStabilityPointStructuresFailureMechanism + var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculationWithOutput, - new TestStabilityPointStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -872,18 +1041,16 @@ var nodeData = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Call @@ -899,25 +1066,25 @@ public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndAborted_ThenInquiryAndIllustrationPointsNotCleared() { // Given - var calculationWithIllustrationPoints = new TestStabilityPointStructuresCalculationScenario + var calculationWithIllustrationPoints = new StructuresCalculationScenario { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) }; - var calculationWithOutput = new TestStabilityPointStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; - var failureMechanism = new TestStabilityPointStructuresFailureMechanism + var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculationWithIllustrationPoints, calculationWithOutput, - new TestStabilityPointStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -939,16 +1106,15 @@ helper.ClickCancel(); }; - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { @@ -968,25 +1134,25 @@ public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinued_ThenInquiryAndIllustrationPointsCleared() { // Given - var calculationWithIllustrationPoints = new TestStabilityPointStructuresCalculationScenario + var calculationWithIllustrationPoints = new StructuresCalculationScenario { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) }; - var calculationWithOutput = new TestStabilityPointStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; - var failureMechanism = new TestStabilityPointStructuresFailureMechanism + var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculationWithIllustrationPoints, calculationWithOutput, - new TestStabilityPointStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -1012,16 +1178,15 @@ helper.ClickOk(); }; - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; - TreeNodeInfo info = GetInfo(plugin); using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { @@ -1040,11 +1205,15 @@ public override void Setup() { mocksRepository = new MockRepository(); + plugin = new StabilityPointStructuresPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructuresFailureMechanismContext)); } - private static TreeNodeInfo GetInfo(StabilityPointStructuresPlugin plugin) + public override void TearDown() { - return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructuresFailureMechanismContext)); + plugin.Dispose(); + + mocksRepository.VerifyAll(); } } } \ No newline at end of file