Exemplo n.º 1
0
        public void RaisesPropertyChangedOnParentValueSet()
        {
            using (new DefaultImplementationFixture())
            {
                var raised = 0;

                var parent = new DependencyObjectFake();
                var child  = new DependencyObjectFake();
                var childInheritanceSource = child.Component.GetValueSource <InheritanceValueSource>();

                var prop = Dependency.Property.RegisterAttached("AttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default", isInherited: true, propertyChangedCallback: (s, e) =>
                {
                    if (object.ReferenceEquals(s, child))
                    {
                        raised++;
                    }
                }));

                childInheritanceSource.ParentComponent = parent.Component;

                Assert.Equal("default", child.GetValue(prop));

                parent.SetValue(prop, "inherited");

                Assert.Equal("inherited", child.GetValue(prop));
                Assert.Equal(1, raised);
            }
        }
Exemplo n.º 2
0
        public void CanOverrideMetadataPropertyChangedCallback()
        {
            using (new DefaultImplementationFixture())
            {
                var raisedParent = new List <IDependencyObject>();
                var raisedChild  = new List <IDependencyObject>();

                var parent = new DependencyObjectFake();
                var child  = new SecondDependencyObjectFake();

                var prop = Dependency.Property.RegisterAttached("AttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default", isInherited: true, propertyChangedCallback: (s, e) =>
                {
                    raisedParent.Add(s);
                }));

                prop.OverrideMetadata(typeof(SecondDependencyObjectFake), new PropertyMetadata("overriden", propertyChangedCallback: (s, e) =>
                {
                    raisedChild.Add(s);
                }));

                var childInheritanceSource = child.Component.GetValueSource <InheritanceValueSource>();
                childInheritanceSource.ParentComponent = parent.Component;

                parent.SetValue(prop, "inherited");

                Assert.Collection(raisedParent,
                                  x => Assert.Same(parent, x),
                                  x => Assert.Same(child, x));

                Assert.Collection(raisedChild,
                                  x => Assert.Same(child, x));
            }
        }
Exemplo n.º 3
0
        public void SetPropertyValue_SetTopSecond()
        {
            using (new DefaultImplementationFixture())
            {
                var member   = Dependency.Property.Register("Value", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default"));
                var attached = Dependency.Property.RegisterAttached("AttachedValue", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default"));
                var owner    = new DependencyObjectFake();
                var top      = owner.Component.GetValueSource <ValueStoreFake>();

                owner.SetValue(member, "local");
                top.SetValue(member, "top");

                owner.SetValue(attached, "local");
                top.SetValue(attached, "top");

                Assert.Equal("top", owner.GetValue(member));
                Assert.Equal("top", owner.GetValue(attached));
            }
        }
Exemplo n.º 4
0
        public void SetMemberReadOnlyPropertyValueViaDP()
        {
            using (new DefaultImplementationFixture())
            {
                var propKey = Dependency.Property.RegisterReadOnly("IsEnabled", typeof(bool), typeof(DependencyObjectFake), new PropertyMetadata(true));
                var prop    = propKey.DependencyProperty;
                var owner   = new DependencyObjectFake();

                Assert.Throws <InvalidOperationException>(() => owner.SetValue(prop, false));
            }
        }
Exemplo n.º 5
0
        public void SetMemberPropertyValue()
        {
            using (new DefaultImplementationFixture())
            {
                var prop  = Dependency.Property.Register("IsEnabled", typeof(bool), typeof(DependencyObjectFake), new PropertyMetadata(true));
                var owner = new DependencyObjectFake();

                owner.SetValue(prop, false);

                Assert.False((bool)owner.GetValue(prop));
            }
        }
Exemplo n.º 6
0
        public void WontInheritNonInheritingPropertyValues()
        {
            using (new DefaultImplementationFixture())
            {
                var parent = new DependencyObjectFake();

                var child = new DependencyObjectFake();
                var childInheritanceSource = child.Component.GetValueSource <InheritanceValueSource>();

                var inheritingProp        = Dependency.Property.RegisterAttached("AttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default", isInherited: true));
                var nonInheritingAttached = Dependency.Property.RegisterAttached("NonInheritingAttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default"));
                var nonInheritingMember   = Dependency.Property.Register("NonInheritingMemberProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default"));

                parent.SetValue(inheritingProp, "inherited");
                parent.SetValue(nonInheritingAttached, "inherited");
                parent.SetValue(nonInheritingMember, "inherited");

                childInheritanceSource.ParentComponent = parent.Component;

                Assert.Equal("inherited", child.GetValue(inheritingProp));
                Assert.Equal("default", child.GetValue(nonInheritingAttached));
                Assert.Equal("default", child.GetValue(nonInheritingAttached));
            }
        }
Exemplo n.º 7
0
        public void CanInheritValueFromParent()
        {
            using (new DefaultImplementationFixture())
            {
                var prop   = Dependency.Property.RegisterAttached("AttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default", isInherited: true));
                var parent = new DependencyObjectFake();
                var child  = new DependencyObjectFake();
                var childInheritanceSource = child.Component.GetValueSource <InheritanceValueSource>();

                parent.SetValue(prop, "inherited");

                Assert.Equal("default", child.GetValue(prop));

                childInheritanceSource.ParentComponent = parent.Component;

                Assert.Equal("inherited", child.GetValue(prop));
            }
        }