Library Kata "INotifyPropertyChanged Tester"

Implement a library that can be used to check whether a class has the interface INotifyPropertyChanged implemented correctly.

The interface INotifyPropertyChanged is used for data binding. Through the PropertyChanged event, subscribers are informed that a property of the object has changed. Screen elements can then be updated, for example.

An automated test for a property usually looks like this:

[Test]
public void Name_Property_releases_PropertyChanged_Event_correct_out() {
    var kunde = new Kunde();
    var count = 0;
    customer.PropertyChanged += (o, e) => {
        count++;
        Assert.That(e.PropertyName, Is.EqualTo("Name"));
    };

    kunde.Name = "Stefan";

    Assert.That(count,Is.EqualTo(1));
}

Creating this test for each property of a class is a lot of work, which is out of proportion to the benefit. With the help of the library to be implemented, the test should look like this:

[Test]
public void Properties_resolve_PropertyChanged_Event_correct_off() {
   NotificationTester.Verify();
}

The type of the class to be tested is passed as a generic method parameter to the Verify method. This then instantiates an object of the type and uses reflection to determine all properties for which the PropertyChanged event must be implemented. All properties are then checked to see whether they trigger the event and whether the name of the property is passed correctly.

en_USEnglish