-
-
Save prashantvc/88f6072dc753697c9738 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NUnit.Framework; | |
using System.ComponentModel; | |
namespace BindingListBug | |
{ | |
[TestFixture] | |
public class BindingListBugTest | |
{ | |
string changedPropertyName = string.Empty; | |
bool isEventRaised = false; | |
[SetUp] | |
public void SetUp () | |
{ | |
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; | |
if (e.PropertyDescriptor != null) | |
changedPropertyName = e.PropertyDescriptor.Name; | |
}; | |
persons [0].FirstName = "Stefan"; | |
} | |
[Test] | |
public void IsEventRaised () | |
{ | |
Assert.IsTrue (isEventRaised); | |
} | |
[Test] | |
public void DidWeReceiveChangedPropertyName () | |
{ | |
Assert.AreEqual ("FirstName", changedPropertyName); | |
} | |
} | |
public class Person : INotifyPropertyChanged | |
{ | |
private string _lastName; | |
private string _firstName; | |
public string FirstName { | |
get { return _firstName; } | |
set { | |
_firstName = value; | |
OnPropertyChanged ("FirstName"); | |
} | |
} | |
public string LastName { | |
get { return _lastName; } | |
set { | |
_lastName = value; | |
OnPropertyChanged ("LastName"); | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected virtual void OnPropertyChanged (string propertyName = null) | |
{ | |
PropertyChangedEventHandler handler = PropertyChanged; | |
if (handler != null) | |
handler (this, new PropertyChangedEventArgs (propertyName)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment