Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/DesignWaterLevelLocationsContextTreeNodeInfoTest.cs =================================================================== diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r73b4f6d22205e989634d53404cb8197547f7f02a --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/DesignWaterLevelLocationsContextTreeNodeInfoTest.cs (.../DesignWaterLevelLocationsContextTreeNodeInfoTest.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/DesignWaterLevelLocationsContextTreeNodeInfoTest.cs (.../DesignWaterLevelLocationsContextTreeNodeInfoTest.cs) (revision 73b4f6d22205e989634d53404cb8197547f7f02a) @@ -58,11 +58,6 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); - public override void Setup() - { - mockRepository = new MockRepository(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { @@ -129,7 +124,7 @@ public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() { // Setup - var assessmentSection = mockRepository.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mockRepository); var menuBuilder = mockRepository.StrictMock(); using (mockRepository.Ordered()) @@ -142,7 +137,8 @@ menuBuilder.Expect(mb => mb.Build()).Return(null); } - var nodeData = new DesignWaterLevelLocationsContext(assessmentSection); + var nodeData = new DesignWaterLevelLocationsContext(new ObservableList(), + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -167,19 +163,54 @@ } [Test] - public void ContextMenuStrip_HydraulicBoundaryDatabaseNotValid_ContextMenuItemCalculateAllDisabledAndTooltipSet() + public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup - var assessmentSection = mockRepository.Stub(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mockRepository); - var nodeData = new DesignWaterLevelLocationsContext(assessmentSection) + var nodeData = new DesignWaterLevelLocationsContext(new ObservableList(), + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) { - WrappedData = + var gui = mockRepository.Stub(); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mockRepository.ReplayAll(); + + using (var plugin = new RingtoetsPlugin()) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase() + TreeNodeInfo info = GetInfo(plugin); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuRunAssessmentLevelCalculationsIndex]; + + Assert.AreEqual("Alles be&rekenen", contextMenuItem.Text); + StringAssert.Contains("Er is geen hydraulische randvoorwaardendatabase geïmporteerd.", contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateAllIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } } - }; + } + mockRepository.VerifyAll(); // Expect no calls on arguments + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemCalculateAllDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(null, mockRepository, "invalidFilePath"); + + var nodeData = new DesignWaterLevelLocationsContext(assessmentSection.HydraulicBoundaryDatabase.Locations, + assessmentSection); + using (var treeViewControl = new TreeViewControl()) { var gui = mockRepository.Stub(); @@ -216,18 +247,16 @@ { // Setup var assessmentSection = mockRepository.Stub(); - - var nodeData = new DesignWaterLevelLocationsContext(assessmentSection) + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - WrappedData = - { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase - { - FilePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"), "complete.sqlite") - } - } + FilePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"), "complete.sqlite") }; + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var nodeData = new DesignWaterLevelLocationsContext(hydraulicBoundaryDatabase.Locations, + assessmentSection); + using (var treeViewControl = new TreeViewControl()) { var gui = mockRepository.Stub(); @@ -266,7 +295,7 @@ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName"); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + HydraulicBoundaryDatabase = { Locations = { @@ -276,7 +305,8 @@ } }; - var context = new DesignWaterLevelLocationsContext(assessmentSection); + var context = new DesignWaterLevelLocationsContext(assessmentSection.HydraulicBoundaryDatabase.Locations, + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -330,7 +360,7 @@ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName"); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + HydraulicBoundaryDatabase = { Locations = { @@ -343,7 +373,8 @@ } }; - var context = new DesignWaterLevelLocationsContext(assessmentSection); + var context = new DesignWaterLevelLocationsContext(assessmentSection.HydraulicBoundaryDatabase.Locations, + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -396,7 +427,7 @@ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName"); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + HydraulicBoundaryDatabase = { Locations = { @@ -409,7 +440,8 @@ } }; - var context = new DesignWaterLevelLocationsContext(assessmentSection); + var context = new DesignWaterLevelLocationsContext(assessmentSection.HydraulicBoundaryDatabase.Locations, + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -462,7 +494,7 @@ var location = new TestHydraulicBoundaryLocation("locationName"); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + HydraulicBoundaryDatabase = { Locations = { @@ -472,16 +504,9 @@ } }; - var assessmentSectionObserver = mockRepository.StrictMock(); - assessmentSectionObserver.Expect(o => o.UpdateObserver()); - assessmentSection.Attach(assessmentSectionObserver); + var context = new DesignWaterLevelLocationsContext(assessmentSection.HydraulicBoundaryDatabase.Locations, + assessmentSection); - var databaseObserver = mockRepository.StrictMock(); - databaseObserver.Expect(o => o.UpdateObserver()); - assessmentSection.HydraulicBoundaryDatabase.Attach(databaseObserver); - - var context = new DesignWaterLevelLocationsContext(assessmentSection); - using (var treeViewControl = new TreeViewControl()) { var gui = mockRepository.Stub(); @@ -531,13 +556,18 @@ Assert.AreEqual($"Toetspeil berekenen voor locatie '{location.Name}' is gelukt.", msgs[7]); }); Assert.AreEqual(0, location.DesignWaterLevel, location.DesignWaterLevel.GetAccuracy()); - Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, location.DesignWaterLevelCalculation.Output.CalculationConvergence); } } } mockRepository.VerifyAll(); } + public override void Setup() + { + mockRepository = new MockRepository(); + } + private static TreeNodeInfo GetInfo(RingtoetsPlugin plugin) { return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(DesignWaterLevelLocationsContext));