示例#1
0
        /// <summary>
        /// Verifies that the provided object did not raise INotifyPropertyChanged.PropertyChanged as a result of executing the given
        /// test code.
        /// </summary>
        /// <typeparam name="TDeclaring">The type of object declaring the property</typeparam>
        /// <typeparam name="TValue">The value of the property</typeparam>
        /// <param name="object">The object declaring the property</param>
        /// <param name="property">The property</param>
        /// <param name="testCode">The code that should not change the property</param>
        public static void PropertyDoesNotChange <TDeclaring, TValue>(TDeclaring @object, Expression <Func <TDeclaring, TValue> > property, Assert.PropertyChangedDelegate testCode)
            where TDeclaring : INotifyPropertyChanged
        {
            object sender = null;
            PropertyChangedEventArgs    args    = null;
            PropertyChangedEventHandler handler = (o, e) =>
            {
                sender = o;
                args   = e;
            };

            try
            {
                @object.PropertyChanged += handler;
                testCode();
            }
            finally
            {
                @object.PropertyChanged -= handler;
            }

            if (args != null && ReferenceEquals(sender, @object))
            {
                string propertyName = Reflect.PropertyOf(property).Name;
                if (args.PropertyName == propertyName)
                {
                    throw new PropertyDoesNotChangeException(propertyName);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Verifies that the provided object raised INotifyPropertyChanged.PropertyChanged as a result of executing the given
 /// test code.
 /// </summary>
 /// <typeparam name="TDeclaring">The type of object declaring the property</typeparam>
 /// <typeparam name="TValue">The value of the property</typeparam>
 /// <param name="object">The object declaring the property</param>
 /// <param name="property">The property</param>
 /// <param name="testCode">The code that should change the property</param>
 public static void PropertyChanged <TDeclaring, TValue>(TDeclaring @object, Expression <Func <TDeclaring, TValue> > property, Assert.PropertyChangedDelegate testCode)
     where TDeclaring : INotifyPropertyChanged
 {
     Assert.PropertyChanged(@object, Reflect.PropertyOf(property).Name, testCode);
 }