From 57c18def14b4acb3af02a9bc3232ea3004ab42db Mon Sep 17 00:00:00 2001 From: Antonius Riha Date: Fri, 3 Jan 2014 21:10:34 +0100 Subject: [PATCH] Implement GroupDescription based on moonlight implementation --- .../System.ComponentModel/GroupDescription.cs | 9 ++- .../GroupDescriptionTest.cs | 68 +++++++++++++++++++ .../WindowsBase-tests-net_2_0.csproj | 1 + .../WindowsBase-tests-net_4_0.csproj | 1 + .../WindowsBase-tests-net_4_5.csproj | 1 + .../WindowsBase/WindowsBase_test.dll.sources | 1 + 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 mcs/class/WindowsBase/Test/System.ComponentModel/GroupDescriptionTest.cs diff --git a/mcs/class/WindowsBase/System.ComponentModel/GroupDescription.cs b/mcs/class/WindowsBase/System.ComponentModel/GroupDescription.cs index ed9d824c339..edc1a624b2c 100644 --- a/mcs/class/WindowsBase/System.ComponentModel/GroupDescription.cs +++ b/mcs/class/WindowsBase/System.ComponentModel/GroupDescription.cs @@ -31,12 +31,15 @@ namespace System.ComponentModel { public abstract class GroupDescription : INotifyPropertyChanged { + readonly ObservableCollection groupNames; + protected GroupDescription () { + groupNames = new ObservableCollection (); } public ObservableCollection GroupNames { - get { throw new NotImplementedException (); } + get { return groupNames; } } event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { @@ -48,7 +51,7 @@ namespace System.ComponentModel { public virtual bool NamesMatch (object groupName, object itemName) { - throw new NotImplementedException (); + return Equals (groupName, itemName); } protected virtual void OnPropertyChanged (PropertyChangedEventArgs e) @@ -60,7 +63,7 @@ namespace System.ComponentModel { [EditorBrowsable (EditorBrowsableState.Never)] public bool ShouldSerializeGroupNames () { - throw new NotImplementedException (); + return GroupNames.Count != 0; } public abstract object GroupNameFromItem (object item, int level, CultureInfo culture); diff --git a/mcs/class/WindowsBase/Test/System.ComponentModel/GroupDescriptionTest.cs b/mcs/class/WindowsBase/Test/System.ComponentModel/GroupDescriptionTest.cs new file mode 100644 index 00000000000..037e0394ec5 --- /dev/null +++ b/mcs/class/WindowsBase/Test/System.ComponentModel/GroupDescriptionTest.cs @@ -0,0 +1,68 @@ +// +// GroupDescriptionTest.cs +// +// Author: +// Antonius Riha +// +// Copyright (c) 2014 Antonius Riha +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.ComponentModel; +using System.Globalization; +using NUnit.Framework; + +namespace MonoTests.System.ComponentModel +{ + [TestFixture] + public class GroupDescriptionTest + { + [Test] + public void NamesMatch () + { + var gd = new ConcreteGroupDescription (); + var obj = new object (); + Assert.IsTrue (gd.NamesMatch (obj, obj), "A1"); + Assert.IsFalse (gd.NamesMatch (new object (), new object ()), "A2"); + } + + [Test] + public void ShouldSerializeGroupNames () + { + var g = new ConcreteGroupDescription (); + g.GroupNames.Add ("name"); + Assert.IsTrue (g.ShouldSerializeGroupNames (), "#A1"); + } + + [Test] + public void ShouldSerializeGroupNamesEmpty () + { + var g = new ConcreteGroupDescription (); + Assert.IsFalse (g.ShouldSerializeGroupNames (), "#A1"); + } + + class ConcreteGroupDescription : GroupDescription + { + public override object GroupNameFromItem (object item, int level, CultureInfo culture) + { + throw new NotSupportedException (); + } + } + } +} diff --git a/mcs/class/WindowsBase/WindowsBase-tests-net_2_0.csproj b/mcs/class/WindowsBase/WindowsBase-tests-net_2_0.csproj index 0ed7508a9e7..86ea26d3e9f 100644 --- a/mcs/class/WindowsBase/WindowsBase-tests-net_2_0.csproj +++ b/mcs/class/WindowsBase/WindowsBase-tests-net_2_0.csproj @@ -49,6 +49,7 @@ + diff --git a/mcs/class/WindowsBase/WindowsBase-tests-net_4_0.csproj b/mcs/class/WindowsBase/WindowsBase-tests-net_4_0.csproj index 1bc72234ac8..8e125454ae8 100644 --- a/mcs/class/WindowsBase/WindowsBase-tests-net_4_0.csproj +++ b/mcs/class/WindowsBase/WindowsBase-tests-net_4_0.csproj @@ -49,6 +49,7 @@ + diff --git a/mcs/class/WindowsBase/WindowsBase-tests-net_4_5.csproj b/mcs/class/WindowsBase/WindowsBase-tests-net_4_5.csproj index 589bc53ce45..f194fb2369a 100644 --- a/mcs/class/WindowsBase/WindowsBase-tests-net_4_5.csproj +++ b/mcs/class/WindowsBase/WindowsBase-tests-net_4_5.csproj @@ -49,6 +49,7 @@ + diff --git a/mcs/class/WindowsBase/WindowsBase_test.dll.sources b/mcs/class/WindowsBase/WindowsBase_test.dll.sources index 437fef32ef8..23dde059fc7 100644 --- a/mcs/class/WindowsBase/WindowsBase_test.dll.sources +++ b/mcs/class/WindowsBase/WindowsBase_test.dll.sources @@ -3,6 +3,7 @@ System.Collections.ObjectModel/ReadOnlyObservableCollectionTest.cs System.Collections.Specialized/NotifyCollectionChangedEventArgsTest.cs System.Collections.Specialized/CollectionChangedEventValidators.cs System.ComponentModel/CurrentChangingEventArgsTest.cs +System.ComponentModel/GroupDescriptionTest.cs System.ComponentModel/PropertyFilterAttributeTest.cs System.ComponentModel/SortDescriptionCollectionTest.cs System.ComponentModel/SortDescriptionTest.cs -- 2.25.1