Beispiel #1
0
        public void When_Updating_Collected()
        {
            var           SUT = new MyObject();
            WeakReference sub1WR, sub1Store;

            void CreateSub()
            {
                var sub1 = new SubObject();

                SUT.SubObject = sub1;
                sub1.SetParent(SUT);

                sub1WR    = new WeakReference(sub1);
                sub1Store = new WeakReference(((IDependencyObjectStoreProvider)sub1).Store);

                SUT.SubObject = null;
            }

            CreateSub();

            SUT.TemplatedParent = SUT;

            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            SUT.TemplatedParent = null;

            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            Assert.IsNull(sub1WR.Target);
            Assert.IsNull(sub1Store.Target);
        }
Beispiel #2
0
        public void When_Path_Invalid_And_NotifyPropertyChanged()
        {
            var SUT = new MyObject();

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyStringPropertyProperty, new Binding("C.D"));

            Assert.AreEqual("", sub.MyStringProperty);
            Assert.AreEqual(0, sub.MyStringPropertyCounter);

            SUT.SubObject = sub;

            Assert.AreEqual("", sub.MyStringProperty);
            Assert.AreEqual(0, sub.MyStringPropertyCounter);

            SUT.DataContext = new PropagationContext2();

            Assert.AreEqual("", sub.MyStringProperty);
            Assert.AreEqual(0, sub.MyStringPropertyCounter);

            SUT.DataContext = new PropagationContext();

            Assert.AreEqual("44", sub.MyStringProperty);

            // This must be one, even if the original binding was
            // set to an invalid property path for PropagationContext2.
            Assert.AreEqual(1, sub.MyStringPropertyCounter);
        }
Beispiel #3
0
        public void When_Path_Invalid_And_Fallback_Value_And_Converter()
        {
            var SUT = new MyObject();

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyPropertyProperty, new Binding("B")
            {
                FallbackValue = "21", Converter = new OppositeConverter()
            });

            Assert.AreEqual(21, sub.MyProperty);
            Assert.AreEqual(1, sub.MyPropertyCounter);

            SUT.SubObject = sub;

            // We are testing that the converter isn't called when using FallbackValue
            Assert.AreEqual(21, sub.MyProperty);
            Assert.AreEqual(1, sub.MyPropertyCounter);

            SUT.DataContext = new PropagationContext();

            // We are testing that the converter is called when not using FallbackValue
            Assert.AreEqual(-43, sub.MyProperty);
            Assert.AreEqual(2, sub.MyPropertyCounter);
        }
Beispiel #4
0
        public void When_Path_Invalid()
        {
            var SUT = new MyObject();

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyPropertyProperty, new Binding("B"));

            Assert.AreEqual(0, sub.MyProperty);
            Assert.AreEqual(0, sub.MyPropertyCounter);

            SUT.SubObject = sub;

            Assert.AreEqual(0, sub.MyProperty);
            Assert.AreEqual(0, sub.MyPropertyCounter);

            SUT.DataContext = 42;

            Assert.AreEqual(0, sub.MyProperty);
            Assert.AreEqual(0, sub.MyPropertyCounter);

            SUT.DataContext = new PropagationContext();

            Assert.AreEqual(43, sub.MyProperty);
            Assert.AreEqual(1, sub.MyPropertyCounter);
        }
Beispiel #5
0
        public void When_DependencyObject_Bindable_Removed()
        {
            var SUT  = new MyObject();
            var sub1 = new SubObject();

            SUT.SubObject = sub1;
            SUT.SubObject = null;

            SUT.DataContext = SUT;

            Assert.IsNull(sub1.DataContext);
        }
Beispiel #6
0
        public void When_DataContext_And_SelfReference()
        {
            var SUT = new MyObject();

            SUT.SelfTest = SUT;

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyPropertyProperty, new Binding());
            SUT.SubObject = sub;

            // This should not fail because of a stack overflow.
            SUT.DataContext = 42;

            Assert.AreEqual(42, sub.MyProperty);
        }
Beispiel #7
0
        public void When_DataContext_Set_After()
        {
            var SUT = new MyObject();

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyPropertyProperty, new Binding());

            Assert.AreEqual(0, sub.MyProperty);

            SUT.SubObject = sub;

            Assert.AreEqual(0, sub.MyProperty);

            SUT.DataContext = 42;

            Assert.AreEqual(42, sub.MyProperty);
        }
Beispiel #8
0
        public void When_DataContext_Set_Before()
        {
            var SUT = new MyObject();

            SUT.DataContext = 42;

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyPropertyProperty, new Binding());

            Assert.AreEqual(0, sub.MyProperty);

            SUT.SubObject = sub;

            // The behavior of UWP is undefined. The datacontext is pass through unknown means tp
            // non-visual elements, to allow binding. But if defined through code, the datacontext
            // is not flowing. We're reproducing this behavior here.
            Assert.AreEqual(0, sub.MyProperty);
        }
Beispiel #9
0
        public void When_Path_Invalid_And_Fallback_Value()
        {
            var SUT = new MyObject();

            var sub = new SubObject();

            sub.SetBinding(SubObject.MyPropertyProperty, new Binding("B")
            {
                FallbackValue = "21"
            });

            Assert.AreEqual(21, sub.MyProperty);
            Assert.AreEqual(1, sub.MyPropertyCounter);

            SUT.SubObject = sub;

            Assert.AreEqual(21, sub.MyProperty);
            Assert.AreEqual(1, sub.MyPropertyCounter);

            SUT.DataContext = new PropagationContext();

            Assert.AreEqual(43, sub.MyProperty);
            Assert.AreEqual(2, sub.MyPropertyCounter);
        }