Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs =================================================================== diff -u -raa8007e0a07c5ab485633583aa095ea34baf1a49 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs) (revision aa8007e0a07c5ab485633583aa095ea34baf1a49) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -25,12 +25,12 @@ using Core.Common.Gui; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; -using Core.Common.Gui.TestUtil; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; using Ringtoets.GrassCoverErosionOutwards.Forms.Views; @@ -54,7 +54,7 @@ Assert.AreEqual(typeof(IEnumerable), info.ViewDataType); Assert.AreEqual(typeof(GrassCoverErosionOutwardsWaveHeightLocationsView), info.ViewType); TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, info.Image); - Assert.AreEqual(Resources.GrassCoverErosionOutwardsHydraulicBoundaryLocation_WaveHeight_DisplayName, info.GetViewName(null, null)); + Assert.AreEqual(Resources.GrassCoverErosionOutwardsWaveHeightLocationsContext_DisplayName, info.GetViewName(null, null)); } } @@ -88,6 +88,149 @@ mockRepository.VerifyAll(); } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + 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 GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingFailureMechanismContext_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSection; + + // Call + var closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingFailureMechanismContext_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSectionB); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // 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 GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + 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 GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + + // Call + var closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + } + private ViewInfo GetInfo(PluginBase plugin) { return plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(GrassCoverErosionOutwardsWaveHeightLocationsView));