Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs =================================================================== diff -u -r5ef5e3e186036b4985798236624d86b2801b87d3 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision 5ef5e3e186036b4985798236624d86b2801b87d3) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -1,21 +1,27 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using Core.Common.Base.Data; using Core.Common.Base.Plugin; +using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; +using Core.Common.Gui.Settings; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Placeholder; +using Ringtoets.HydraRing.Data; +using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; @@ -31,25 +37,128 @@ [STAThread] // For creation of XAML UI component public void DefaultConstructor_ExpectedValues() { - // call + // Call using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - // assert - Assert.IsInstanceOf(ringtoetsGuiPlugin); + // Assert + Assert.IsInstanceOf(ringtoetsGuiPlugin); Assert.IsInstanceOf(ringtoetsGuiPlugin.RibbonCommandHandler); } } [Test] + [STAThread] // For creation of XAML UI component + public void GivenGuiPluginWithGuiSet_WhenProjectOnGuiChangesToProjectWithoutHydraulicBoundaryDatabase_ThenNoWarning() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + // Call + Action action = () => gui.Project = new Project(); + + // Assert + TestHelper.AssertLogMessagesCount(action, 0); + } + } + + [Test] + [STAThread] // For creation of XAML UI component + public void GivenGuiPluginWithGuiSet_WhenProjectOnGuiChangesToProjectWithHydraulicBoundaryDatabaseWithExistingLocation_ThenNoWarning() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + var testDataDir = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundaryLocationReader"); + var testDataPath = Path.Combine(testDataDir, "complete.sqlite"); + + using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + var project = new Project(); + IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = testDataPath + } + }; + project.Items.Add(section); + + // Call + Action action = () => + { + gui.Project = project; + }; + + // Assert + TestHelper.AssertLogMessagesCount(action, 0); + } + } + + [Test] + [STAThread] // For creation of XAML UI component + public void GivenGuiPluginWithGuiSet_WhenProjectOnGuiChangesToProjectWithHydraulicBoundaryDatabaseWithNonExistingLocation_ThenWarning() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + var project = new Project(); + var notExistingFile = "not_existing_file"; + + IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = notExistingFile + } + }; + project.Items.Add(section); + + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + // Call + Action action = () => + { + gui.Project = project; + }; + + // Assert + string message = string.Format( + Properties.Resources.RingtoetsGuiPlugin_VerifyHydraulicBoundaryDatabasePath_Hydraulic_boundary_database_could_not_be_found_on_path_0_, + notExistingFile); + TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(message, LogLevelConstant.Warn)); + } + } + + [Test] public void GetPropertyInfos_ReturnsSupportedPropertyClasses() { - // setup + // Setup using (var guiPlugin = new RingtoetsGuiPlugin()) { - // call + // Call PropertyInfo[] propertyInfos = guiPlugin.GetPropertyInfos().ToArray(); - // assert + // Assert Assert.AreEqual(2, propertyInfos.Length); var assessmentSectionProperties = propertyInfos.Single(pi => pi.DataType == typeof(IAssessmentSection)); @@ -100,7 +209,7 @@ [Test] public void GetTreeNodeInfos_ReturnsSupportedTreeNodeInfos() { - // setup + // Setup var mocks = new MockRepository(); var applicationCore = new ApplicationCore(); @@ -115,10 +224,10 @@ Gui = guiStub }) { - // call + // Call TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); - // assert + // Assert Assert.AreEqual(10, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(IAssessmentSection))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ReferenceLineContext)));