Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -rc31624c97c0497973430f779ab1d82c46696a2a1 -r0a202fb1943caf5a69d09c1f312bbdeb15021b63 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision c31624c97c0497973430f779ab1d82c46696a2a1) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 0a202fb1943caf5a69d09c1f312bbdeb15021b63) @@ -137,11 +137,9 @@ public override IEnumerable GetTreeNodeInfos() { - yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo( - FailureMechanismEnabledChildNodeObjects, - FailureMechanismDisabledChildNodeObjects, - FailureMechanismEnabledContextMenuStrip, - FailureMechanismDisabledContextMenuStrip); + yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismStateContextTreeNodeInfo( + CalculationsChildNodeObjects, + CalculationsContextMenuStrip); yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismStateContextTreeNodeInfo( FailurePathChildNodeObjects, @@ -355,41 +353,29 @@ #region TreeNodeInfos - #region StabilityPointStructuresFailureMechanismContext TreeNodeInfo + #region StabilityPointStructuresCalculationsContext TreeNodeInfo - private static object[] FailureMechanismEnabledChildNodeObjects(StabilityPointStructuresCalculationsContext context) + private static object[] CalculationsChildNodeObjects(StabilityPointStructuresCalculationsContext context) { - StabilityPointStructuresFailureMechanism wrappedData = context.WrappedData; + StabilityPointStructuresFailureMechanism failureMechanism = context.WrappedData; IAssessmentSection assessmentSection = context.Parent; return new object[] { new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Inputs_DisplayName, - GetInputs(wrappedData, assessmentSection), - TreeFolderCategory.Input), - new StabilityPointStructuresCalculationGroupContext(wrappedData.CalculationsGroup, - null, - wrappedData, - assessmentSection), + GetCalculationsInputs(failureMechanism, assessmentSection), TreeFolderCategory.Input), + new StabilityPointStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, + null, failureMechanism, assessmentSection), new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Outputs_DisplayName, - GetOutputs(wrappedData, assessmentSection), - TreeFolderCategory.Output) + GetOutputs(failureMechanism, assessmentSection), TreeFolderCategory.Output) }; } - private static object[] FailureMechanismDisabledChildNodeObjects(StabilityPointStructuresCalculationsContext context) + private static IEnumerable GetCalculationsInputs(StabilityPointStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) { return new object[] { - context.WrappedData.NotRelevantComments - }; - } - - private static IEnumerable GetInputs(StabilityPointStructuresFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) - { - return new object[] - { new StabilityPointStructuresFailureMechanismSectionsContext(failureMechanism, assessmentSection), new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection), new StabilityPointStructuresContext(failureMechanism.StabilityPointStructures, failureMechanism, assessmentSection), @@ -410,19 +396,17 @@ }; } - private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(StabilityPointStructuresCalculationsContext context, - object parentData, - TreeViewControl treeViewControl) + private ContextMenuStrip CalculationsContextMenuStrip(StabilityPointStructuresCalculationsContext context, + object parentData, + TreeViewControl treeViewControl) { IEnumerable> calculations = context.WrappedData - .Calculations - .Cast>(); + .Calculations + .Cast>(); IInquiryHelper inquiryHelper = GetInquiryHelper(); var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); return builder.AddOpenItem() .AddSeparator() - .AddToggleRelevancyOfFailureMechanismItem(context, RemoveAllViewsForItem) - .AddSeparator() .AddValidateAllCalculationsInFailureMechanismItem( context, ValidateAllInFailureMechanism, @@ -443,26 +427,6 @@ .Build(); } - private ContextMenuStrip FailureMechanismDisabledContextMenuStrip(StabilityPointStructuresCalculationsContext context, - object parentData, - TreeViewControl treeViewControl) - { - var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); - - return builder.AddToggleRelevancyOfFailureMechanismItem(context, RemoveAllViewsForItem) - .AddSeparator() - .AddCollapseAllItem() - .AddExpandAllItem() - .AddSeparator() - .AddPropertiesItem() - .Build(); - } - - private void RemoveAllViewsForItem(StabilityPointStructuresCalculationsContext context) - { - Gui.ViewCommands.RemoveAllViewsForItem(context); - } - private static string EnableValidateAndCalculateMenuItemForFailureMechanism(StabilityPointStructuresCalculationsContext context) { return EnableValidateAndCalculateMenu(context.Parent); Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationsContextTreeNodeInfoTest.cs =================================================================== diff -u -rc31624c97c0497973430f779ab1d82c46696a2a1 -r0a202fb1943caf5a69d09c1f312bbdeb15021b63 --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationsContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationsContextTreeNodeInfoTest.cs) (revision c31624c97c0497973430f779ab1d82c46696a2a1) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationsContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationsContextTreeNodeInfoTest.cs) (revision 0a202fb1943caf5a69d09c1f312bbdeb15021b63) @@ -21,14 +21,14 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using Core.Gui; -using Core.Gui.Commands; using Core.Gui.ContextMenu; using Core.Gui.Forms.MainWindow; using Core.Gui.TestUtil.ContextMenu; @@ -60,14 +60,11 @@ [TestFixture] public class StabilityPointStructuresCalculationsContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuRelevancyIndexWhenRelevant = 2; - private const int contextMenuRelevancyIndexWhenNotRelevant = 0; + private const int contextMenuValidateAllIndex = 2; + private const int contextMenuCalculateAllIndex = 3; + private const int contextMenuClearAllIndex = 5; + private const int contextMenuClearIllustrationPointsIndex = 6; - private const int contextMenuValidateAllIndex = 4; - private const int contextMenuCalculateAllIndex = 5; - private const int contextMenuClearAllIndex = 7; - private const int contextMenuClearIllustrationPointsIndex = 8; - private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, nameof(HydraulicBoundaryDatabase)); private MockRepository mocksRepository; @@ -103,10 +100,11 @@ } [Test] - public void ChildNodeObjects_FailureMechanismIsRelevant_ReturnChildDataNodes() + public void Text_WithContext_ReturnsName() { // Setup - var assessmentSection = new AssessmentSectionStub(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); @@ -116,6 +114,42 @@ TreeNodeInfo info = GetInfo(plugin); // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual(failureMechanism.Name, text); + } + } + + [Test] + public void Image_Always_ReturnsFailureMechanismIcon() + { + // Setup + using (var plugin = new StabilityPointStructuresPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.FailureMechanismIcon, image); + } + } + + [Test] + public void ChildNodeObjects_WithContext_ReturnChildDataNodes() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call object[] children = info.ChildNodeObjects(context).ToArray(); // Assert @@ -183,38 +217,9 @@ } [Test] - public void ChildNodeObjects_FailureMechanismIsNotRelevant_ReturnOnlyFailureMechanismNotRelevantComments() + public void ContextMenuStrip_WithContext_CallsContextMenuBuilderMethods() { // Setup - var assessmentSection = mocksRepository.Stub(); - mocksRepository.ReplayAll(); - - var failureMechanism = new StabilityPointStructuresFailureMechanism - { - IsRelevant = false - }; - var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); - - using (var plugin = new StabilityPointStructuresPlugin()) - { - TreeNodeInfo info = GetInfo(plugin); - - // Call - object[] children = info.ChildNodeObjects(context).ToArray(); - - // Assert - Assert.AreEqual(1, children.Length); - var comment = (Comment) children[0]; - Assert.AreSame(failureMechanism.NotRelevantComments, comment); - } - - mocksRepository.VerifyAll(); - } - - [Test] - public void ContextMenuStrip_FailureMechanismIsRelevant_CallsContextMenuBuilderMethods() - { - // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); var assessmentSection = mocksRepository.Stub(); var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); @@ -225,9 +230,7 @@ menuBuilder.Expect(mb => mb.AddOpenItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); @@ -259,52 +262,10 @@ } [Test] - public void ContextMenuStrip_FailureMechanismIsNotRelevant_CallsContextMenuBuilderMethods() + public void ContextMenuStrip_WithContext_AddCustomItems() { // Setup - var failureMechanism = new StabilityPointStructuresFailureMechanism - { - IsRelevant = false - }; - var assessmentSection = mocksRepository.Stub(); - var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); - - var menuBuilder = mocksRepository.StrictMock(); - using (mocksRepository.Ordered()) - { - menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); - 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(context, treeViewControl)).Return(menuBuilder); - mocksRepository.ReplayAll(); - - plugin.Gui = gui; - - TreeNodeInfo info = GetInfo(plugin); - - // Call - info.ContextMenuStrip(context, null, treeViewControl); - } - - // Assert - mocksRepository.VerifyAll(); - } - - [Test] - public void ContextMenuStrip_FailureMechanismIsRelevant_AddCustomItems() - { - // Setup - using (var plugin = new StabilityPointStructuresPlugin()) using (var treeView = new TreeViewControl()) { var assessmentSection = mocksRepository.Stub(); @@ -327,13 +288,8 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(context, assessmentSection, treeView)) { // Assert - Assert.AreEqual(14, menu.Items.Count); + Assert.AreEqual(12, menu.Items.Count); - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenRelevant, - "I&s relevant", - "Geeft aan of dit toetsspoor relevant is of niet.", - RiskeerCommonFormsResources.Checkbox_ticked); - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex, "Alles &valideren", "Er zijn geen berekeningen om te valideren.", @@ -363,126 +319,6 @@ } [Test] - public void ContextMenuStrip_FailureMechanismIsNotRelevant_AddCustomItems() - { - // Setup - using (var plugin = new StabilityPointStructuresPlugin()) - using (var treeView = new TreeViewControl()) - { - var assessmentSection = mocksRepository.Stub(); - var failureMechanism = new StabilityPointStructuresFailureMechanism - { - IsRelevant = false - }; - var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - var gui = mocksRepository.Stub(); - gui.Stub(cmp => cmp.Get(context, treeView)).Return(menuBuilder); - gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); - gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - mocksRepository.ReplayAll(); - - plugin.Gui = gui; - - TreeNodeInfo info = GetInfo(plugin); - - // Call - using (ContextMenuStrip menu = info.ContextMenuStrip(context, assessmentSection, treeView)) - { - // Assert - Assert.AreEqual(6, menu.Items.Count); - - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenNotRelevant, - "I&s relevant", - "Geeft aan of dit toetsspoor relevant is of niet.", - RiskeerCommonFormsResources.Checkbox_empty); - } - } - - mocksRepository.VerifyAll(); - } - - [Test] - public void ContextMenuStrip_FailureMechanismIsRelevantAndClickOnIsRelevantItem_MakeFailureMechanismNotRelevantAndRemovesAllViewsForItem() - { - // Setup - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var assessmentSection = mocksRepository.Stub(); - var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); - var viewCommands = mocksRepository.StrictMock(); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - viewCommands.Expect(vs => vs.RemoveAllViewsForItem(context)); - - 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(context, 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(context, null, treeViewControl)) - { - // Call - contextMenu.Items[contextMenuRelevancyIndexWhenRelevant].PerformClick(); - - // Assert - Assert.IsFalse(failureMechanism.IsRelevant); - } - } - - mocksRepository.VerifyAll(); - } - - [Test] - public void ContextMenuStrip_FailureMechanismIsNotRelevantAndClickOnIsRelevantItem_MakeFailureMechanismRelevantAndRemovesAllViewsForItem() - { - // Setup - var failureMechanism = new StabilityPointStructuresFailureMechanism - { - IsRelevant = false - }; - var assessmentSection = mocksRepository.Stub(); - var context = new StabilityPointStructuresCalculationsContext(failureMechanism, assessmentSection); - var viewCommands = mocksRepository.StrictMock(); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - - viewCommands.Expect(vs => vs.RemoveAllViewsForItem(context)); - - 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(context, 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(context, null, treeViewControl)) - { - // Call - contextMenu.Items[contextMenuRelevancyIndexWhenNotRelevant].PerformClick(); - - // Assert - Assert.IsTrue(failureMechanism.IsRelevant); - } - } - - mocksRepository.VerifyAll(); - } - - [Test] public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() { // Setup