Implement GroupDescription based on moonlight implementation
authorAntonius Riha <antoniusriha@gmail.com>
Fri, 3 Jan 2014 20:10:34 +0000 (21:10 +0100)
committerAntonius Riha <antoniusriha@gmail.com>
Fri, 3 Jan 2014 20:15:32 +0000 (21:15 +0100)
mcs/class/WindowsBase/System.ComponentModel/GroupDescription.cs
mcs/class/WindowsBase/Test/System.ComponentModel/GroupDescriptionTest.cs [new file with mode: 0644]
mcs/class/WindowsBase/WindowsBase-tests-net_2_0.csproj
mcs/class/WindowsBase/WindowsBase-tests-net_4_0.csproj
mcs/class/WindowsBase/WindowsBase-tests-net_4_5.csproj
mcs/class/WindowsBase/WindowsBase_test.dll.sources

index ed9d824c339d54b0b75b502eb2f7ff8b274dd824..edc1a624b2cad169f836cc1c2bf57727e5bfea8a 100644 (file)
@@ -31,12 +31,15 @@ namespace System.ComponentModel {
 
        public abstract class GroupDescription : INotifyPropertyChanged
        {
+               readonly ObservableCollection<object> groupNames;
+
                protected GroupDescription ()
                {
+                       groupNames = new ObservableCollection<object> ();
                }
 
                public ObservableCollection<object> 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 (file)
index 0000000..037e039
--- /dev/null
@@ -0,0 +1,68 @@
+//
+// GroupDescriptionTest.cs
+//
+// Author:
+//       Antonius Riha <antoniusriha@gmail.com>
+//
+// 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 ();
+                       }
+               }
+       }
+}
index 0ed7508a9e7e82a7fbab7f7eac05d8ac08b68184..86ea26d3e9f0a952ca56713c849367664270b8f0 100644 (file)
@@ -49,6 +49,7 @@
     <Compile Include="Test\System.Collections.Specialized\CollectionChangedEventValidators.cs" />\r
     <Compile Include="Test\System.Collections.Specialized\NotifyCollectionChangedEventArgsTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\CurrentChangingEventArgsTest.cs" />\r
+    <Compile Include="Test\System.ComponentModel\GroupDescriptionTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\PropertyFilterAttributeTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\SortDescriptionCollectionTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\SortDescriptionTest.cs" />\r
index 1bc72234ac809c3fabb28de213f4c585f8881f14..8e125454ae84ffaea73b82d5aecaaeb833dd2f40 100644 (file)
@@ -49,6 +49,7 @@
     <Compile Include="Test\System.Collections.Specialized\CollectionChangedEventValidators.cs" />\r
     <Compile Include="Test\System.Collections.Specialized\NotifyCollectionChangedEventArgsTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\CurrentChangingEventArgsTest.cs" />\r
+    <Compile Include="Test\System.ComponentModel\GroupDescriptionTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\PropertyFilterAttributeTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\SortDescriptionCollectionTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\SortDescriptionTest.cs" />\r
index 589bc53ce45f26c006f6cfeffc57673d3c344ab6..f194fb2369ae1b5b6b47668a988bb28b3cd91613 100644 (file)
@@ -49,6 +49,7 @@
     <Compile Include="Test\System.Collections.Specialized\CollectionChangedEventValidators.cs" />\r
     <Compile Include="Test\System.Collections.Specialized\NotifyCollectionChangedEventArgsTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\CurrentChangingEventArgsTest.cs" />\r
+    <Compile Include="Test\System.ComponentModel\GroupDescriptionTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\PropertyFilterAttributeTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\SortDescriptionCollectionTest.cs" />\r
     <Compile Include="Test\System.ComponentModel\SortDescriptionTest.cs" />\r
index 437fef32ef8023c4c6cd3bbb10ad9cb84f6595ff..23dde059fc782810f16af267960150c04d2f7f99 100644 (file)
@@ -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