src/TestCommon/Helpers/PropertyChangedHelper.cs
/// <summary>
/// Verifies a property change notification is raised when setting a property and
/// that the property was set correctly.
/// </summary>
/// <typeparam name="T">Type of the property.</typeparam>
/// <param name="obj">Object containing the property to verify.</param>
/// <param name="propertyName">Name of the property.</param>
/// <param name="newValue">Value to set the property to.</param>
/// <param name="setProperty">Delegate which sets the property.</param>
/// <param name="getProperty">Delegate which gets the property.</param>
Verifies a property change notification is raised when setting a property and
that the property was set correctly.
Verifies a property change notification is raised when setting a property and that the property was set correctly .
public static void VerifyPropertyChangedEvent<T>(INotifyPropertyChanged obj, string propertyName, T newValue, Action<T> setProperty, Func<T> getProperty)
        {
            bool propertyChangedEventRaised = false;
            obj.PropertyChanged += (sender, e) =>
            {
                propertyChangedEventRaised = true;
                Assert.Equal(propertyName, e.PropertyName);
            };
            setProperty(newValue);
            Assert.True(propertyChangedEventRaised);
            if (newValue.GetType().IsValueType)
            {
                Assert.Equal(newValue, getProperty());
            }
            else
            {
                Assert.Equal(newValue, getProperty());
            }
        }
public static void VerifyPropertyChangedEvent < T > ( INotifyPropertyChanged obj , string propertyName , T newValue , Action < T > setProperty , Func < T > getProperty ) { bool propertyChangedEventRaised = false ; obj . PropertyChanged += ( sender , e ) => { propertyChangedEventRaised = true ; Assert . Equal ( propertyName , e . PropertyName ) ; } ; setProperty ( newValue ) ; Assert . True ( propertyChangedEventRaised ) ; if ( newValue . GetType ( ) . IsValueType ) { Assert . Equal ( newValue , getProperty ( ) ) ; } else { Assert . Equal ( newValue , getProperty ( ) ) ; } }
Verifies a property change notification is raised when setting a property and
that the property was set correctly.
Verifies a property change notification is raised when setting a property and that the property was set correctly .
obj
INotifyPropertyChanged
Object containing the property to verify.
Object containing the property to verify .
propertyName
string
Name of the property.
Name of the property .
newValue
T
Value to set the property to.
Value to set the property to .
setProperty
Action<T>
Delegate which sets the property.
Delegate which sets the property .
getProperty
Func<T>
Delegate which gets the property.
Delegate which gets the property .
typeparam
Type of the property.
Type of the property .