public void NotificationOnWholeObjectChanged() { var instance = new INPCObservableForProperty(); var testClass = new TestClassChanged(); Expression <Func <TestClassChanged, string?> > expr = x => x.Property1; var exp = Reflection.Rewrite(expr.Body); var changes = new List <IObservedChange <object, object?> >(); var propertyName = exp.GetMemberInfo()?.Name; if (propertyName is null) { throw new InvalidOperationException("propertyName should not be null"); } instance.GetNotificationForProperty(testClass, exp, propertyName, false).WhereNotNull().Subscribe(c => changes.Add(c)); testClass.OnPropertyChanged(null); testClass.OnPropertyChanged(string.Empty); Assert.Equal(2, changes.Count); Assert.Equal(testClass, changes[0].Sender); Assert.Equal(testClass, changes[1].Sender); }
public void CheckGetAffinityForObjectValues() { var instance = new INPCObservableForProperty(); Assert.Equal(5, instance.GetAffinityForObject(typeof(TestClassChanged), null, false)); Assert.Equal(0, instance.GetAffinityForObject(typeof(TestClassChanged), null, true)); Assert.Equal(0, instance.GetAffinityForObject(typeof(object), null, false)); Assert.Equal(5, instance.GetAffinityForObject(typeof(TestClassChanging), null, true)); Assert.Equal(0, instance.GetAffinityForObject(typeof(TestClassChanging), null, false)); Assert.Equal(0, instance.GetAffinityForObject(typeof(object), null, false)); }
public void NotificationOnWholeObjectChanged() { var instance = new INPCObservableForProperty(); var testClass = new TestClassChanged(); Expression<Func<TestClassChanged, string>> expr = x => x.Property1; var exp = Reflection.Rewrite(expr.Body); var changes = new List<IObservedChange<object, object>>(); instance.GetNotificationForProperty(testClass, exp, false).Subscribe(c => changes.Add(c)); testClass.OnPropertyChanged(null); testClass.OnPropertyChanged(string.Empty); Assert.Equal(2, changes.Count); Assert.Equal(testClass, changes[0].Sender); Assert.Equal(testClass, changes[1].Sender); }
public void NotificationOnWholeObjectChanged() { var instance = new INPCObservableForProperty(); var testClass = new TestClassChanged(); Expression <Func <TestClassChanged, string> > expr = x => x.Property1; var exp = Reflection.Rewrite(expr.Body); var changes = new List <IObservedChange <object, object> >(); instance.GetNotificationForProperty(testClass, exp, false).Subscribe(c => changes.Add(c)); testClass.OnPropertyChanged(null); testClass.OnPropertyChanged(string.Empty); Assert.Equal(2, changes.Count); Assert.Equal(testClass, changes[0].Sender); Assert.Equal(testClass, changes[1].Sender); }
public void NotificationOnPropertyChanging() { var instance = new INPCObservableForProperty(); var testClass = new TestClassChanging(); Expression <Func <TestClassChanged, string> > expr = x => x.Property1; var exp = Reflection.Rewrite(expr.Body); var changes = new List <IObservedChange <object, object> >(); instance.GetNotificationForProperty(testClass, exp, exp.GetMemberInfo().Name, true).Subscribe(c => changes.Add(c)); testClass.Property1 = "test1"; testClass.Property1 = "test2"; Assert.Equal(2, changes.Count); Assert.Equal(testClass, changes[0].Sender); Assert.Equal(testClass, changes[1].Sender); }