예제 #1
0
        public void VerifyBaseMethodDisposeWhenReferenceIsLost()
        {
            var view = new DummyView();
            var vm   = new DummyVm();

            int called = 0;

            BindingCore.CreateBinding(view,
                                      vm,
                                      d => d.DummyProperty,
                                      (dummyView, s) =>
            {
                dummyView.TextProperty = s;
                called++;
            });
            called.ShouldBe(1);

            vm.DummyProperty = "Random value";
            called.ShouldBe(2);

            view = null;
            GC.Collect();

            vm.DummyProperty = "Random value number 2";
            called.ShouldBe(2);
        }
예제 #2
0
        public void VerifyBaseMethodDisposeUnhooksBindings()
        {
            var view = new DummyView();
            var vm   = new DummyVm();

            int called  = 0;
            var binding = BindingCore.CreateBinding(view,
                                                    vm,
                                                    d => d.DummyProperty,
                                                    (dummyView, s) =>
            {
                dummyView.TextProperty = s;
                called++;
            });

            called.ShouldBe(1);
            view.TextProperty.ShouldBe(vm.DummyProperty);

            vm.DummyProperty = "Random value";
            called.ShouldBe(2);
            view.TextProperty.ShouldBe(vm.DummyProperty);

            binding.Dispose();

            vm.DummyProperty = "Random value numer 2";
            called.ShouldBe(2);
            view.TextProperty.ShouldNotBe(vm.DummyProperty);

            vm.DummyProperty = "Random value numer 3";
            called.ShouldBe(2);
            view.TextProperty.ShouldNotBe(vm.DummyProperty);
        }
예제 #3
0
        public void VerifyBaseMethodThrowsIfGetValIsNotVmProperty()
        {
            DummyView view = new DummyView();
            DummyVm   vm   = new DummyVm();

            Should.Throw <ArgumentException>(
                () =>
                BindingCore.CreateBinding(vm, vm, model => "1", (model, val) => model.DummyProperty = val));

            var binding = BindingCore.CreateBinding(view, vm, model => model.DummyProperty, (model, val) => model.TextProperty = val);

            binding.ShouldNotBeNull();
        }
예제 #4
0
        public void VerifyBaseMethodThrowsIfInvokedWithNullParameters()
        {
            DummyView nullView  = null;
            DummyView valueView = new DummyView();
            DummyVm   nullVm    = null;
            DummyVm   valueVm   = new DummyVm();

            Should.Throw <ArgumentNullException>(
                () => BindingCore.CreateBinding(nullView, valueVm, vm => vm.DummyProperty, (m, t) => m.TextProperty = t));
            Should.Throw <ArgumentNullException>(
                () => BindingCore.CreateBinding(valueView, nullVm, vm => vm.DummyProperty, (m, t) => m.TextProperty = t));
            Should.Throw <ArgumentNullException>(
                () => BindingCore.CreateBinding <DummyView, DummyVm, string>(valueView, valueVm, null, (m, t) => m.TextProperty = t));
            Should.Throw <ArgumentNullException>(
                () => BindingCore.CreateBinding(valueView, valueVm, vm => vm.DummyProperty, null));
            var binding = BindingCore.CreateBinding(valueView, valueVm, vm => vm.DummyProperty, (m, t) => m.TextProperty = t);

            binding.ShouldNotBeNull();
        }
예제 #5
0
        public void VerifyBaseMethodExecutesOnceAtCall()
        {
            var view = new DummyView();
            var vm   = new DummyVm();

            int called = 0;

            called.ShouldBe(0);

            BindingCore.CreateBinding(view,
                                      vm,
                                      d => d.DummyProperty,
                                      (v, text) =>
            {
                v.TextProperty = text;
                called++;
            });

            called.ShouldBe(1);
        }
예제 #6
0
        public void VerifyBaseMethodGetsInvokedWhenPropertyChanges()
        {
            var view = new DummyView();
            var vm   = new DummyVm();

            int called = 0;

            BindingCore.CreateBinding(view,
                                      vm,
                                      d => d.DummyProperty,
                                      (dummyView, s) =>
            {
                dummyView.TextProperty = s;
                called++;
            });
            called.ShouldBe(1);

            vm.DummyProperty = "Random value";
            called.ShouldBe(2);

            vm.DummyProperty = "Random value number 2";
            called.ShouldBe(3);
        }