Example #1
0
        public void When_DataContext_Changed_Multiple()
        {
            var SUT = new DependencyObjectCollection();

            SUT.DataContext = 41;

            var o1 = new MyDependencyObject();

            o1.SetBinding(MyDependencyObject.MyPropertyProperty, new Binding());

            var o2 = new MyDependencyObject();

            o2.SetBinding(MyDependencyObject.MyPropertyProperty, new Binding());

            Assert.AreEqual(0, o1.MyProperty);
            Assert.AreEqual(0, o1.MyProperty);

            SUT.Add(o1);
            SUT.Add(o2);

            Assert.AreEqual(41, o1.MyProperty);
            Assert.AreEqual(41, o2.MyProperty);

            SUT.DataContext = 42;

            Assert.AreEqual(42, o1.MyProperty);
            Assert.AreEqual(42, o2.MyProperty);

            SUT.Clear();

            Assert.AreEqual(0, o1.MyProperty);
            Assert.AreEqual(0, o2.MyProperty);
        }
Example #2
0
        public void When_Changed_By_Indexer()
        {
            var SUT = new DependencyObjectCollection();

            SUT.DataContext = 42;

            var o1 = new MyDependencyObject();

            o1.SetBinding(MyDependencyObject.MyPropertyProperty, new Binding());

            var o2 = new MyDependencyObject();

            o2.SetBinding(MyDependencyObject.MyPropertyProperty, new Binding());

            Assert.AreEqual(0, o1.MyProperty);
            Assert.AreEqual(0, o1.MyProperty);

            SUT.Add(o1);
            Assert.AreEqual(42, o1.MyProperty);
            Assert.AreEqual(0, o2.MyProperty);

            SUT[0] = o2;

            Assert.AreEqual(0, o1.MyProperty);
            Assert.AreEqual(42, o2.MyProperty);
        }
Example #3
0
        public void When_Add_After_DataContext()
        {
            var SUT = new DependencyObjectCollection();

            SUT.DataContext = 42;

            var o1 = new MyDependencyObject();

            o1.SetBinding(MyDependencyObject.MyPropertyProperty, new Binding());

            Assert.AreEqual(0, o1.MyProperty);

            SUT.Add(o1);

            Assert.AreEqual(42, o1.MyProperty);
        }