[System] Don't send response on empty stream write. Fixes #47549
[mono.git] / mcs / class / System / Test / System.ComponentModel / BindingListTest.cs
index 92a6253db915b6bc3d0d3643689b8ae02f134512..57d1822e993b039e8a669a977034d898cf5f0de1 100644 (file)
@@ -1,4 +1,3 @@
-#if NET_2_0
 
 using System;
 using System.ComponentModel;
@@ -639,7 +638,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");
+               }
        }
 }
 
-#endif