Esempio n. 1
0
        public static ViewModelPropertyObserver <T> GetPropertyObserver <T>(this INotifyPropertyChanged notifyPropertyChanged, string propertyName)
        {
            ViewModelPropertyObserver <T> observer = new ViewModelPropertyObserver <T>();
            var property = notifyPropertyChanged.GetType().GetProperty(propertyName);

            if (property == null)
            {
                throw new Exception("Can not obeserve property");
            }
            notifyPropertyChanged.PropertyChanged += (s, args) =>
            {
                if (s != notifyPropertyChanged)
                {
                    return;
                }
                if (args.PropertyName != propertyName)
                {
                    return;
                }
                observer.PropertyValue = (T)property.GetValue(s, null);
                observer.NumberOfTimesPropertyChanged++;
            };
            observer.PropertyValue = (T)property.GetValue(notifyPropertyChanged, null);
            return(observer);
        }
Esempio n. 2
0
 public static void AssertProperyHasChanged <T>(this ViewModelPropertyObserver <T> observer, T t)
 {
     Assert.AreEqual(t, observer.PropertyValue);
     Assert.AreNotEqual(0, observer.NumberOfTimesPropertyChanged);
 }