Added test for bug #20672 (fixed in aeab5b59021f4a712d54357c8bbeaa6fac12dc37)
authorAlexis Christoforides <alexis@thenull.net>
Thu, 19 Jun 2014 23:47:01 +0000 (19:47 -0400)
committerAlexis Christoforides <alexis@thenull.net>
Thu, 19 Jun 2014 23:49:33 +0000 (19:49 -0400)
mcs/class/System/Test/System.ComponentModel/BindingListTest.cs

index 92a6253db915b6bc3d0d3643689b8ae02f134512..43faa5cc10712ab55fccc52d944734a78468a49c 100644 (file)
@@ -639,6 +639,62 @@ namespace MonoTests.System.ComponentModel
                        
                        Assert.AreEqual (1, count, "1");
                }
+
+               private class Person : INotifyPropertyChanged
+               {
+                       private string _lastName;
+                       private string _firstName;
+
+                       public string FirstName {
+                               get { return _firstName; }
+                               set {
+                                       _firstName = value;
+                                       OnPropertyChanged ("FirstName"); // string matches property name
+                               }
+                       }
+
+                       public string LastName {
+                               get { return _lastName; }
+                               set {
+                                       _lastName = value;
+                                       OnPropertyChanged ("Apepe"); // string doesn't match property name
+                               }
+                       }
+
+                       public event PropertyChangedEventHandler PropertyChanged;
+
+                       protected virtual void OnPropertyChanged (string propertyName = null)
+                       {
+                               PropertyChangedEventHandler handler = PropertyChanged;
+                               if (handler != null)
+                                       handler (this, new PropertyChangedEventArgs (propertyName));
+                       }
+               }
+
+               [Test] // https://bugzilla.xamarin.com/show_bug.cgi?id=20672
+               public void Bug20672 ()
+               {
+                       string changedPropertyName = string.Empty;
+                       bool isEventRaised = false;
+                       bool? hasPropertyDescriptor = false;
+
+                       var persons = new BindingList<Person>();
+                       persons.Add (new Person() { FirstName = "Stefaan", LastName = "de Vogelaere" });
+                       persons.Add (new Person() { FirstName = "Christophe", LastName = "De Langhe" });
+                       persons.ListChanged += (object sender, ListChangedEventArgs e) => {
+                           isEventRaised = true;
+                           hasPropertyDescriptor = e.PropertyDescriptor != null;
+                       };
+
+                       //if the OnPropertyChanged string matches a valid property name, PropertyDescriptor should be generated
+                       persons[0].FirstName = "Stefan";
+                       Assert.IsTrue (isEventRaised);
+                       Assert.IsTrue ((bool) hasPropertyDescriptor, "#1");
+
+                       //if the OnPropertyChanged string doesn't match a valid property name, no PropertyDescriptor should be generated
+                       persons[0].LastName = "de le Vulu";
+                       Assert.IsFalse ((bool) hasPropertyDescriptor, "#2");
+               }
        }
 }