Ejemplo n.º 1
0
        public void Test_WeakSource_SetBinding()
        {
            var viewModel = new TestViewModel();
            var view = new TestView();
            var ws = new WeakTarget(view);

            ws.SetBinding<WeakPropertyBinding>("Text1", viewModel, "Name");

            viewModel.Name = Name1;

            Assert.AreEqual(view.Text1, Name1);

            NotSupportedException exception = null;

            try
            {
                ws.SetBinding<WeakNotifyBinding>("Text1", viewModel, "Name");
            }
            catch(NotSupportedException e)
            {
                exception = e;
            }

            Assert.IsNotNull(exception);
        }
Ejemplo n.º 2
0
        public void Test_WeakSource_SetBinding()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();
            var ws        = new WeakTarget(view);

            ws.SetBinding <WeakPropertyBinding>("Text1", viewModel, "Name");

            viewModel.Name = Name1;

            Assert.AreEqual(view.Text1, Name1);

            NotSupportedException exception = null;

            try
            {
                ws.SetBinding <WeakNotifyBinding>("Text1", viewModel, "Name");
            }
            catch (NotSupportedException e)
            {
                exception = e;
            }

            Assert.IsNotNull(exception);
        }
Ejemplo n.º 3
0
        public void Test_WeakSource_ClearAllBindings()
        {
            var viewModel = new TestViewModel();
            var view = new TestView();
            var ws = new WeakTarget(view);

            ws.SetBinding<WeakPropertyBinding>( "Text1", viewModel,"Name");
            ws.SetBinding<WeakPropertyBinding>("ValueInt", viewModel, "Age");

            viewModel.Name = Name1;
            Assert.AreEqual(view.Text1, Name1);
            viewModel.Age = 2;
            Assert.AreEqual(view.ValueInt, 2);

            ws.ClearBindings();
            viewModel.Name = Name2;
            viewModel.Age = 3;

            Assert.AreNotEqual(view.Text1, Name2);
            Assert.AreNotEqual(view.ValueInt, Name2);
        }
Ejemplo n.º 4
0
        public void Test_WeakSource_ClearAllBindings()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();
            var ws        = new WeakTarget(view);

            ws.SetBinding <WeakPropertyBinding>("Text1", viewModel, "Name");
            ws.SetBinding <WeakPropertyBinding>("ValueInt", viewModel, "Age");

            viewModel.Name = Name1;
            Assert.AreEqual(view.Text1, Name1);
            viewModel.Age = 2;
            Assert.AreEqual(view.ValueInt, 2);

            ws.ClearBindings();
            viewModel.Name = Name2;
            viewModel.Age  = 3;


            Assert.AreNotEqual(view.Text1, Name2);
            Assert.AreNotEqual(view.ValueInt, Name2);
        }
Ejemplo n.º 5
0
        public void Test_WeakSource_ClearBinding()
        {
            var viewModel = new TestViewModel();
            var view = new TestView();
            var ws = new WeakTarget(view);

            ws.SetBinding<WeakPropertyBinding>("Text1", viewModel, "Name");

            viewModel.Name = Name1;
            Assert.AreEqual(view.Text1, Name1);

            ws.ClearBinding("Text1", viewModel, "Name");

            viewModel.Name = Name2;
            Assert.AreNotEqual(view.Text2, Name2);
        }
Ejemplo n.º 6
0
        public void Test_WeakSource_ClearBinding()
        {
            var viewModel = new TestViewModel();
            var view      = new TestView();
            var ws        = new WeakTarget(view);

            ws.SetBinding <WeakPropertyBinding>("Text1", viewModel, "Name");

            viewModel.Name = Name1;
            Assert.AreEqual(view.Text1, Name1);

            ws.ClearBinding("Text1", viewModel, "Name");

            viewModel.Name = Name2;
            Assert.AreNotEqual(view.Text2, Name2);
        }
Ejemplo n.º 7
0
        public void Test_MemoryLeak_WeakSource()
        {
            var v         = new TestView();
            var reference = new WeakReference(v);
            var vm        = new TestViewModel();
            var ws        = new WeakTarget(v);

            ws.SetBinding <WeakPropertyBinding>("Text1", vm, "Name");

            vm.Name = "yohan";
            Assert.AreEqual("yohan", v.Text1);

            v = null;
            GC.Collect();
            Assert.IsFalse(reference.IsAlive);

            GC.KeepAlive(ws);
        }
Ejemplo n.º 8
0
        public void Test_MemoryLeak_WeakSource()
        {
            var v = new TestView();
            var reference = new WeakReference(v);
            var vm = new TestViewModel();
            var ws = new WeakTarget(v);
            ws.SetBinding<WeakPropertyBinding>("Text1", vm, "Name");

            vm.Name = "yohan";
            Assert.AreEqual("yohan", v.Text1);

            v = null;
            GC.Collect();
            Assert.IsFalse(reference.IsAlive);

            GC.KeepAlive(ws);
        }