Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Forked from stefandevo/BindingListBugTest.cs
Created June 18, 2014 09:18
Show Gist options
  • Save prashantvc/88f6072dc753697c9738 to your computer and use it in GitHub Desktop.
Save prashantvc/88f6072dc753697c9738 to your computer and use it in GitHub Desktop.
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