Exemple #1
0
        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?> >();

            var propertyName = exp.GetMemberInfo()?.Name;

            if (propertyName is null)
            {
                throw new InvalidOperationException("propertyName should not be null");
            }

            instance.GetNotificationForProperty(testClass, exp, propertyName, true).WhereNotNull().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);
        }
        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, 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);
        }
        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, 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);
        }