public void AttachPropertyChangedHandler_Should_Be_Called_On_Chain()
        {
            var source = new Mock<IObservableDependencyObject>();
            var foo = new Mock<IObservableDependencyObject>();
            var bar = new Mock<IObservableDependencyObject>();

            Mock<IPropertyPathParser> mockPathParser = new Mock<IPropertyPathParser>();
            mockPathParser.Setup(x => x.Parse(source.Object, "Foo.Bar")).Returns(new[]
            {
                new PropertyPathToken(source.Object, "Foo"),
                new PropertyPathToken(foo.Object, "Bar"),
                new PropertyPathToken(bar.Object, null),
            });

            Mock<DependencyObject> mockTarget = new Mock<DependencyObject>();

            Binding binding = new Binding
            {
                Path = new PropertyPath("Foo.Bar"),
                Source = source.Object,
            };

            BindingExpression target = new BindingExpression(
                mockPathParser.Object,
                mockTarget.Object,
                Control.BackgroundProperty,
                binding);

            target.GetValue();

            source.Verify(x => x.AttachPropertyChangedHandler("Foo", It.IsAny<DependencyPropertyChangedEventHandler>()));
            foo.Verify(x => x.AttachPropertyChangedHandler("Bar", It.IsAny<DependencyPropertyChangedEventHandler>()));
            bar.Verify(x => x.AttachPropertyChangedHandler("Bar", It.IsAny<DependencyPropertyChangedEventHandler>()), Times.Never());
        }
Esempio n. 2
0
        public BindingExpression SetBinding(DependencyProperty dp, Binding binding)
        {
            PropertyPathParser pathParser = new PropertyPathParser();
            BindingExpression expression = new BindingExpression(pathParser, this, dp, binding);
            object oldValue = this.GetValue(dp);
            object newValue = expression.GetValue();

            this.propertyBindings.Add(dp, expression);
            this.SetValueInternal(dp, oldValue, newValue);

            return expression;
        }