Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs =================================================================== diff -u -r161308cb864a66713f62357c6bcdb6ede03b619f -r497b1f631e5c806ce5addc76c2becdeee29f6c6c --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs (.../WaveHeightLocationsViewInfoTest.cs) (revision 161308cb864a66713f62357c6bcdb6ede03b619f) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs (.../WaveHeightLocationsViewInfoTest.cs) (revision 497b1f631e5c806ce5addc76c2becdeee29f6c6c) @@ -19,34 +19,34 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using System.Linq; using Core.Common.Gui; using Core.Common.Gui.Commands; using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.GuiServices; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Plugin.Test.ViewInfos { [TestFixture] public class WaveHeightLocationsViewInfoTest { - private MockRepository mocks; private RingtoetsPlugin plugin; private ViewInfo info; [SetUp] public void SetUp() { - mocks = new MockRepository(); plugin = new RingtoetsPlugin(); info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(WaveHeightLocationsView)); } @@ -61,16 +61,14 @@ public void GetViewName_Always_ReturnsViewName() { // Setup - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - var view = new WaveHeightLocationsView(); + using (var view = new WaveHeightLocationsView()) + { + // Call + var viewName = info.GetViewName(view, Enumerable.Empty()); - // Call - var viewName = info.GetViewName(view, assessmentSection); - - // Assert - Assert.AreEqual("Golfhoogtes", viewName); - mocks.VerifyAll(); + // Assert + Assert.AreEqual("Golfhoogtes", viewName); + } } [Test] @@ -80,7 +78,7 @@ var viewDataType = info.ViewDataType; // Assert - Assert.AreEqual(typeof(IAssessmentSection), viewDataType); + Assert.AreEqual(typeof(IEnumerable), viewDataType); } [Test] @@ -100,13 +98,14 @@ var image = info.Image; // Assert - TestHelper.AssertImagesAreEqual(Resources.GenericInputOutputIcon, image); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); } [Test] public void GetViewData_Always_ReturnsHydraulicBoundaryDatabase() { // Setup + var mocks = new MockRepository(); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); var assessmentSection = mocks.Stub(); assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; @@ -117,43 +116,123 @@ var viewData = info.GetViewData(context); // Assert - Assert.AreSame(assessmentSection, viewData); + Assert.AreSame(hydraulicBoundaryDatabase.Locations, viewData); mocks.VerifyAll(); } [Test] + [RequiresSTA] public void AfterCreate_WithGuiSet_SetsSpecificPropertiesToView() { // Setup - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; IGui guiStub = mocks.Stub(); guiStub.Stub(g => g.ProjectOpened += null).IgnoreArguments(); guiStub.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.MainWindow).Return(mocks.Stub()); + guiStub.Stub(g => g.DocumentViewController).Return(mocks.Stub()); mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; var context = new WaveHeightLocationsContext(assessmentSection); - var view = new WaveHeightLocationsView(); - + using (var view = new WaveHeightLocationsView()) using (var ringtoetsPlugin = new RingtoetsPlugin()) { info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(WaveHeightLocationsView)); ringtoetsPlugin.Gui = guiStub; + ringtoetsPlugin.Activate(); // Call info.AfterCreate(view, context); // Assert - Assert.IsInstanceOf(view.CalculationCommandHandler); - Assert.AreSame(view.ApplicationSelection, guiStub); + Assert.IsInstanceOf(view.CalculationGuiService); } mocks.VerifyAll(); } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new WaveHeightLocationsView()) + { + view.AssessmentSection = assessmentSection; + + // Call + var closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingAssessmentSection_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new WaveHeightLocationsView()) + { + view.AssessmentSection = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new WaveHeightLocationsView()) + { + view.Data = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ViewDataNull_ReturnsFalse() + { + // Setup + using (var view = new WaveHeightLocationsView()) + { + // Call + var closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + } } } \ No newline at end of file