Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationCalculationPropertyInfoTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationCalculationPropertyInfoTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationCalculationPropertyInfoTest.cs (revision 06441edaab0995428e20704fbedc959f5515f4a7) @@ -0,0 +1,74 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.Gui.PropertyBag; +using NUnit.Framework; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.DuneErosion.Forms.PropertyClasses; + +namespace Ringtoets.DuneErosion.Plugin.Test.PropertyInfos +{ + [TestFixture] + public class DuneLocationCalculationPropertyInfoTest + { + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new DuneErosionPlugin()) + { + // Call + PropertyInfo info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(DuneLocationCalculation), info.DataType); + Assert.AreEqual(typeof(DuneLocationCalculationProperties), info.PropertyObjectType); + } + } + + [Test] + public void CreateInstance_WithDuneLocationCalculation_SetsDuneLocationCalculationAsData() + { + // Setup + var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation()); + + using (var plugin = new DuneErosionPlugin()) + { + PropertyInfo info = GetInfo(plugin); + + // Call + IObjectProperties objectProperties = info.CreateInstance(duneLocationCalculation); + + // Assert + Assert.IsInstanceOf(objectProperties); + Assert.AreSame(duneLocationCalculation, objectProperties.Data); + } + } + + private static PropertyInfo GetInfo(DuneErosionPlugin plugin) + { + return plugin.GetPropertyInfos().First(pi => pi.DataType == typeof(DuneLocationCalculation)); + } + } +} \ No newline at end of file Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationCalculationsContextPropertyInfoTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationCalculationsContextPropertyInfoTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationCalculationsContextPropertyInfoTest.cs (revision 06441edaab0995428e20704fbedc959f5515f4a7) @@ -0,0 +1,85 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using Core.Common.Base; +using Core.Common.Gui.Plugin; +using Core.Common.Gui.PropertyBag; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Forms.PresentationObjects; +using Ringtoets.DuneErosion.Forms.PropertyClasses; + +namespace Ringtoets.DuneErosion.Plugin.Test.PropertyInfos +{ + [TestFixture] + public class DuneLocationCalculationsContextPropertyInfoTest + { + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new DuneErosionPlugin()) + { + // Call + PropertyInfo info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(DuneLocationCalculationsContext), info.DataType); + Assert.AreEqual(typeof(DuneLocationCalculationsProperties), info.PropertyObjectType); + } + } + + [Test] + public void CreateInstance_WithContext_SetsDuneLocationsAsData() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var context = new DuneLocationCalculationsContext(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSection); + + using (var plugin = new DuneErosionPlugin()) + { + PropertyInfo info = GetInfo(plugin); + + // Call + IObjectProperties objectProperties = info.CreateInstance(context); + + // Assert + Assert.IsInstanceOf(objectProperties); + Assert.AreSame(context.WrappedData, objectProperties.Data); + } + + mockRepository.VerifyAll(); + } + + private static PropertyInfo GetInfo(DuneErosionPlugin plugin) + { + return plugin.GetPropertyInfos().First(pi => pi.DataType == typeof(DuneLocationCalculationsContext)); + } + } +} \ No newline at end of file Fisheye: Tag 06441edaab0995428e20704fbedc959f5515f4a7 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationPropertyInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 06441edaab0995428e20704fbedc959f5515f4a7 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationsContextPropertyInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/Ringtoets.DuneErosion.Plugin.Test.csproj =================================================================== diff -u -rd02138fd08881584c9ec57b6d87f6426c6e43eb2 -r06441edaab0995428e20704fbedc959f5515f4a7 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/Ringtoets.DuneErosion.Plugin.Test.csproj (.../Ringtoets.DuneErosion.Plugin.Test.csproj) (revision d02138fd08881584c9ec57b6d87f6426c6e43eb2) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/Ringtoets.DuneErosion.Plugin.Test.csproj (.../Ringtoets.DuneErosion.Plugin.Test.csproj) (revision 06441edaab0995428e20704fbedc959f5515f4a7) @@ -26,14 +26,14 @@ - - + + - + Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/ViewInfos/DuneLocationCalculationsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/ViewInfos/DuneLocationCalculationsViewInfoTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/ViewInfos/DuneLocationCalculationsViewInfoTest.cs (revision 06441edaab0995428e20704fbedc959f5515f4a7) @@ -0,0 +1,416 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using Core.Common.Base; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.DuneErosion.Forms.GuiServices; +using Ringtoets.DuneErosion.Forms.PresentationObjects; +using Ringtoets.DuneErosion.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.DuneErosion.Plugin.Test.ViewInfos +{ + [TestFixture] + public class DuneLocationCalculationsViewInfoTest + { + private DuneErosionPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + plugin = new DuneErosionPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(DuneLocationCalculationsView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Call + string viewName = info.GetViewName(null, null); + + // Assert + Assert.AreEqual("Hydraulische randvoorwaarden", viewName); + } + + [Test] + public void ViewDataType_Always_ReturnsViewDataType() + { + // Call + Type viewDataType = info.ViewDataType; + + // Assert + Assert.AreEqual(typeof(IEnumerable), viewDataType); + } + + [Test] + public void DataType_Always_ReturnsDataType() + { + // Call + Type dataType = info.DataType; + + // Assert + Assert.AreEqual(typeof(DuneLocationCalculationsContext), dataType); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } + + [Test] + public void GetViewData_Always_ReturnWrappedDataInContext() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new DuneLocationCalculationsContext(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSection); + + // Call + object viewData = info.GetViewData(context); + + // Assert + Assert.AreSame(context.WrappedData, viewData); + mocks.VerifyAll(); + } + + [Test] + public void AdditionalDataCheck_LocationsEmpty_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new DuneLocationCalculationsContext(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSection); + + // Call + bool additionalDataCheck = info.AdditionalDataCheck(context); + + // Assert + Assert.IsFalse(additionalDataCheck); + } + + [Test] + public void AdditionalDataCheck_WithLocations_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var duneLocations = new ObservableList + { + new DuneLocationCalculation(new TestDuneLocation()) + }; + + var context = new DuneLocationCalculationsContext(duneLocations, + new DuneErosionFailureMechanism(), + assessmentSection); + + // Call + bool additionalDataCheck = info.AdditionalDataCheck(context); + + // Assert + Assert.IsTrue(additionalDataCheck); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedProperties() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var window = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(gs => gs.MainWindow).Return(window); + mocks.ReplayAll(); + + var failureMechanism = new DuneErosionFailureMechanism(); + var context = new DuneLocationCalculationsContext( + new ObservableList(), + failureMechanism, + assessmentSection); + + plugin.Gui = gui; + plugin.Activate(); + + // Call + using (var view = info.CreateInstance(context) as DuneLocationCalculationsView) + { + // Assert + Assert.AreSame(assessmentSection, view.AssessmentSection); + Assert.AreSame(failureMechanism, view.FailureMechanism); + } + + mocks.VerifyAll(); + } + + [Test] + public void AfterCreate_Always_SetsExpectedProperties() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var window = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(gs => gs.MainWindow).Return(window); + mocks.ReplayAll(); + + var failureMechanism = new DuneErosionFailureMechanism(); + var locations = new ObservableList(); + + var data = new DuneLocationCalculationsContext( + locations, + failureMechanism, + assessmentSection); + + plugin.Gui = gui; + plugin.Activate(); + + using (var view = new DuneLocationCalculationsView(locations, + failureMechanism, + assessmentSection)) + { + // Call + info.AfterCreate(view, data); + + // Assert + Assert.IsInstanceOf(view.CalculationGuiService); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var failureMechanism = new DuneErosionFailureMechanism(); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + using (var view = new DuneLocationCalculationsView(new ObservableList(), + failureMechanism, + assessmentSection)) + { + // Call + bool 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(); + assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new DuneErosionFailureMechanism() + }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); + assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new DuneErosionFailureMechanism() + }); + mocks.ReplayAll(); + + using (var view = new DuneLocationCalculationsView(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSectionA)) + { + // Call + bool 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(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new DuneErosionFailureMechanism() + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + var failureMechanism = new DuneErosionFailureMechanism(); + + var duneErosionFailureMechanismContext = new DuneErosionFailureMechanismContext( + failureMechanism, + assessmentSection); + + using (var view = new DuneLocationCalculationsView(new ObservableList(), + failureMechanism, + assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, duneErosionFailureMechanismContext); + + // 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(); + assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new DuneErosionFailureMechanism() + }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); + assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new DuneErosionFailureMechanism() + }); + mocks.ReplayAll(); + + var duneErosionFailureMechanismContext = new DuneErosionFailureMechanismContext( + new DuneErosionFailureMechanism(), + assessmentSectionB); + + using (var view = new DuneLocationCalculationsView(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSectionA)) + { + // Call + bool closeForData = info.CloseForData(view, duneErosionFailureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new DuneErosionFailureMechanism() + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + using (var view = new DuneLocationCalculationsView(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ViewDataNull_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new DuneLocationCalculationsView(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag 06441edaab0995428e20704fbedc959f5515f4a7 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/ViewInfos/DuneLocationsViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?