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); }
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); }
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(); }
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(); }
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); }
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); }