Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/PropertyClasses/DuneLocationCalculationsProperties.cs =================================================================== diff -u --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/PropertyClasses/DuneLocationCalculationsProperties.cs (revision 0) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/PropertyClasses/DuneLocationCalculationsProperties.cs (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -0,0 +1,78 @@ +// 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.ComponentModel; +using System.Linq; +using Core.Common.Base; +using Core.Common.Gui.Converters; +using Core.Common.Gui.PropertyBag; +using Core.Common.Util.Attributes; +using Ringtoets.DuneErosion.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.DuneErosion.Forms.PropertyClasses +{ + /// + /// ViewModel of an enumeration of for the properties panel. + /// + public class DuneLocationCalculationsProperties : ObjectProperties>, IDisposable + { + private readonly RecursiveObserver, DuneLocationCalculation> calculationsObserver; + + /// + /// Creates a new instance of . + /// + /// The collection of dune location calculations to set as data. + /// Thrown when is null. + public DuneLocationCalculationsProperties(IObservableEnumerable calculations) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + calculationsObserver = new RecursiveObserver, DuneLocationCalculation>(OnRefreshRequired, list => list) + { + Observable = calculations + }; + + Data = calculations; + } + + [TypeConverter(typeof(ExpandableArrayConverter))] + [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Locations_DisplayName))] + [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Locations_Description))] + public DuneLocationProperties[] Locations + { + get + { + return data.Select(calculation => new DuneLocationProperties(calculation.DuneLocation, calculation)).ToArray(); + } + } + + public void Dispose() + { + calculationsObserver.Dispose(); + } + } +} \ No newline at end of file Fisheye: Tag b4166249e5330682bae1f5d4cb02b3cd05a75647 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/PropertyClasses/DuneLocationsProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj =================================================================== diff -u -r71fda574a476b830bd4b767b624fb52426658701 -rb4166249e5330682bae1f5d4cb02b3cd05a75647 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision 71fda574a476b830bd4b767b624fb52426658701) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -23,7 +23,7 @@ - + True Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs =================================================================== diff -u -r5cd1ac2b1438ea93461625d699a5377739c5abbf -rb4166249e5330682bae1f5d4cb02b3cd05a75647 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision 5cd1ac2b1438ea93461625d699a5377739c5abbf) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -61,9 +61,9 @@ CreateInstance = context => new DuneErosionFailureMechanismProperties(context.WrappedData, new DuneErosionFailureMechanismPropertyChangeHandler()) }; - yield return new PropertyInfo + yield return new PropertyInfo { - CreateInstance = context => new DuneLocationsProperties(context.WrappedData) + CreateInstance = context => new DuneLocationCalculationsProperties(context.WrappedData) }; yield return new PropertyInfo Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PropertyClasses/DuneLocationCalculationsPropertiesTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PropertyClasses/DuneLocationCalculationsPropertiesTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PropertyClasses/DuneLocationCalculationsPropertiesTest.cs (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -0,0 +1,152 @@ +// 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.ComponentModel; +using Core.Common.Base; +using Core.Common.Gui.Converters; +using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.DuneErosion.Forms.PropertyClasses; + +namespace Ringtoets.DuneErosion.Forms.Test.PropertyClasses +{ + [TestFixture] + public class DuneLocationCalculationsPropertiesTest + { + private const int requiredLocationsPropertyIndex = 0; + + [Test] + public void Constructor_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new DuneLocationCalculationsProperties(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Constructor_WithData_ReturnExpectedValues() + { + // Setup + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + var duneLocationCalculations = new ObservableList + { + calculation + }; + + // Call + using (var properties = new DuneLocationCalculationsProperties(duneLocationCalculations)) + { + // Assert + Assert.IsInstanceOf>>(properties); + Assert.IsInstanceOf(properties); + + Assert.AreEqual(1, properties.Locations.Length); + Assert.AreSame(calculation.DuneLocation, properties.Locations[0].Data); + } + } + + [Test] + public void Constructor_Always_PropertiesHaveExpectedAttributesValues() + { + // Setup + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + var duneLocationCalculations = new ObservableList + { + calculation + }; + + // Call + using (var properties = new DuneLocationCalculationsProperties(duneLocationCalculations)) + { + // Assert + Assert.AreSame(duneLocationCalculations, properties.Data); + + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(1, dynamicProperties.Count); + + PropertyDescriptor locationsProperty = dynamicProperties[requiredLocationsPropertyIndex]; + Assert.IsInstanceOf(locationsProperty.Converter); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(locationsProperty, + "Algemeen", + "Locaties", + "Locaties uit de hydraulische randvoorwaardendatabase.", + true); + } + } + + [Test] + public void GivenPropertyControlWithData_WhenSingleCalculationUpdated_RefreshRequiredEventRaised() + { + // Given + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + var duneLocationCalculations = new ObservableList + { + calculation + }; + + using (var properties = new DuneLocationCalculationsProperties(duneLocationCalculations)) + { + + var refreshRequiredRaised = 0; + properties.RefreshRequired += (sender, args) => refreshRequiredRaised++; + + // When + calculation.NotifyObservers(); + + // Then + Assert.AreEqual(1, refreshRequiredRaised); + } + } + + [Test] + public void GivenDisposedPropertyControlWithData_WhenSingleCalculationUpdated_RefreshRequiredEventNotRaised() + { + // Given + var calculation = new DuneLocationCalculation(new TestDuneLocation()); + var duneLocationCalculations = new ObservableList + { + calculation + }; + + using (var properties = new DuneLocationCalculationsProperties(duneLocationCalculations)) + { + + var refreshRequiredRaised = 0; + properties.RefreshRequired += (sender, args) => refreshRequiredRaised++; + + properties.Dispose(); + + // When + calculation.NotifyObservers(); + + // Then + Assert.AreEqual(0, refreshRequiredRaised); + } + } + } +} \ No newline at end of file Fisheye: Tag b4166249e5330682bae1f5d4cb02b3cd05a75647 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PropertyClasses/DuneLocationsPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj =================================================================== diff -u -r71fda574a476b830bd4b767b624fb52426658701 -rb4166249e5330682bae1f5d4cb02b3cd05a75647 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj (.../Ringtoets.DuneErosion.Forms.Test.csproj) (revision 71fda574a476b830bd4b767b624fb52426658701) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj (.../Ringtoets.DuneErosion.Forms.Test.csproj) (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -31,7 +31,7 @@ - + Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs =================================================================== diff -u -r71fda574a476b830bd4b767b624fb52426658701 -rb4166249e5330682bae1f5d4cb02b3cd05a75647 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs (.../DuneErosionPluginTest.cs) (revision 71fda574a476b830bd4b767b624fb52426658701) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs (.../DuneErosionPluginTest.cs) (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -83,7 +83,7 @@ PluginTestHelper.AssertPropertyInfoDefined( propertyInfos, typeof(DuneLocationCalculationsContext), - typeof(DuneLocationsProperties)); + typeof(DuneLocationCalculationsProperties)); PluginTestHelper.AssertPropertyInfoDefined( propertyInfos, typeof(DuneLocation), Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationsContextPropertyInfoTest.cs =================================================================== diff -u -rf74c65d0ad7a4658f8a87a0beace37735b3ce749 -rb4166249e5330682bae1f5d4cb02b3cd05a75647 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationsContextPropertyInfoTest.cs (.../DuneLocationsContextPropertyInfoTest.cs) (revision f74c65d0ad7a4658f8a87a0beace37735b3ce749) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/PropertyInfos/DuneLocationsContextPropertyInfoTest.cs (.../DuneLocationsContextPropertyInfoTest.cs) (revision b4166249e5330682bae1f5d4cb02b3cd05a75647) @@ -46,7 +46,7 @@ // Assert Assert.AreEqual(typeof(DuneLocationCalculationsContext), info.DataType); - Assert.AreEqual(typeof(DuneLocationsProperties), info.PropertyObjectType); + Assert.AreEqual(typeof(DuneLocationCalculationsProperties), info.PropertyObjectType); } } @@ -70,7 +70,7 @@ IObjectProperties objectProperties = info.CreateInstance(context); // Assert - Assert.IsInstanceOf(objectProperties); + Assert.IsInstanceOf(objectProperties); Assert.AreSame(context.WrappedData, objectProperties.Data); }