public void TwoWayBindWithFuncConvertersSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); vm.JustADecimal = 123.45m; Assert.NotEqual(vm.JustADecimal.ToString(), view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.JustADecimal, x => x.SomeTextBox.Text, (IObservable <Unit>?)null, d => d.ToString(), decimal.Parse); Assert.Equal(vm.JustADecimal.ToString(), view.SomeTextBox.Text); Assert.Equal(123.45m, vm.JustADecimal); view.SomeTextBox.Text = "567.89"; Assert.Equal(567.89m, vm.JustADecimal); disp?.Dispose(); vm.JustADecimal = 0; Assert.Equal(0, vm.JustADecimal); Assert.Equal("567.89", view.SomeTextBox.Text); }
public void TwoWayBindSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); vm.Property1 = "Foo"; Assert.NotEqual(vm.Property1, view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable <Unit>)null, null); Assert.Equal(vm.Property1, view.SomeTextBox.Text); Assert.Equal("Foo", vm.Property1); view.SomeTextBox.Text = "Bar"; Assert.Equal(vm.Property1, "Bar"); disp.Dispose(); vm.Property1 = "Baz"; Assert.Equal("Baz", vm.Property1); Assert.NotEqual(vm.Property1, view.SomeTextBox.Text); }
public void TypeConvertedTwoWayBindSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); vm.Property2 = 17; Assert.NotEqual(vm.Property2.ToString(), view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.Property2, x => x.SomeTextBox.Text, (IObservable <Unit>)null, null); Assert.Equal(vm.Property2.ToString(), view.SomeTextBox.Text); Assert.Equal(17, vm.Property2); view.SomeTextBox.Text = "42"; Assert.Equal(42, vm.Property2); disp.Dispose(); vm.Property2 = 0; Assert.Equal(0, vm.Property2); Assert.NotEqual("0", view.SomeTextBox.Text); }
public void DataboundReactiveListDoesNotThrowForInsertRange() { var vm = new LegacyPropertyBindViewModel(); var view = new LegacyPropertyBindView { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); fixture.OneWayBind(vm, view, m => m.SomeCollectionOfStrings, v => v.FakeItemsControl.ItemsSource); vm.SomeCollectionOfStrings.ResetChangeThreshold = int.MinValue; foreach (var item in Create(5)) { vm.SomeCollectionOfStrings.Add(item); } // within reset threshold vm.SomeCollectionOfStrings.InsertRange(2, Create(5)); // outside reset threshold vm.SomeCollectionOfStrings.InsertRange(2, Create(20)); IEnumerable <string> Create(int numElements) => Enumerable.Range(1, numElements).Select(i => $"item_{i}"); }
public void OneWayBindConverter() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); fixture.OneWayBind(vm, view, x => x.JustABoolean, x => x.SomeTextBox.IsEnabled, s => s); Assert.False(view.SomeTextBox.IsEnabled); }
public void BindExpectsConverterFuncsToNotBeNull() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); Func <string?, string?> nullFunc = null !; Assert.Throws <ArgumentNullException>(() => fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable <Unit>?)null, nullFunc, s => s)); Assert.Throws <ArgumentNullException>(() => fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable <Unit>?)null, s => s, nullFunc)); }
public void DataboundReactiveListDoesNotThrowForAddRange() { var vm = new LegacyPropertyBindViewModel(); var view = new LegacyPropertyBindView { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); fixture.OneWayBind(vm, view, m => m.SomeCollectionOfStrings, v => v.FakeItemsControl.ItemsSource); // eliminate the ResetChangeThreshold from the equation vm.SomeCollectionOfStrings.ResetChangeThreshold = int.MinValue; // Within the reset threshold vm.SomeCollectionOfStrings.AddRange(Create(5)); vm.SomeCollectionOfStrings.AddRange(Create(20)); IEnumerable <string> Create(int numElements) => Enumerable.Range(1, numElements).Select(i => $"item_{i}"); }
public void TwoWayBindWithFuncConvertersSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() {ViewModel = vm}; var fixture = new PropertyBinderImplementation(); vm.JustADecimal = 123.45m; Assert.NotEqual(vm.JustADecimal.ToString(), view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.JustADecimal, x => x.SomeTextBox.Text, (IObservable<Unit>)null, d => d.ToString(), Decimal.Parse); Assert.Equal(vm.JustADecimal.ToString(), view.SomeTextBox.Text); Assert.Equal(123.45m, vm.JustADecimal); view.SomeTextBox.Text = "567.89"; Assert.Equal(567.89m, vm.JustADecimal); disp.Dispose(); vm.JustADecimal = 0; Assert.Equal(0, vm.JustADecimal); Assert.Equal("567.89", view.SomeTextBox.Text); }
public void TwoWayBindSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() {ViewModel = vm}; var fixture = new PropertyBinderImplementation(); vm.Property1 = "Foo"; Assert.NotEqual(vm.Property1, view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null); Assert.Equal(vm.Property1, view.SomeTextBox.Text); Assert.Equal("Foo", vm.Property1); view.SomeTextBox.Text = "Bar"; Assert.Equal(vm.Property1, "Bar"); disp.Dispose(); vm.Property1 = "Baz"; Assert.Equal("Baz", vm.Property1); Assert.NotEqual(vm.Property1, view.SomeTextBox.Text); }
public void TypeConvertedTwoWayBindSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); vm.Property2 = 17; Assert.NotEqual(vm.Property2.ToString(), view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.Property2, x => x.SomeTextBox.Text, (IObservable <Unit>)null, null); Assert.Equal(vm.Property2.ToString(), view.SomeTextBox.Text); Assert.Equal(17, vm.Property2); view.SomeTextBox.Text = "42"; Assert.Equal(42, vm.Property2); // Bad formatting error view.SomeTextBox.Text = "--"; Assert.Equal(42, vm.Property2); disp.Dispose(); vm.Property2 = 0; Assert.Equal(0, vm.Property2); Assert.NotEqual("0", view.SomeTextBox.Text); vm.JustADecimal = 17.2m; var disp1 = fixture.Bind(vm, view, x => x.JustADecimal, x => x.SomeTextBox.Text, (IObservable <Unit>)null, null); Assert.Equal(vm.JustADecimal.ToString(), view.SomeTextBox.Text); Assert.Equal(17.2m, vm.JustADecimal); view.SomeTextBox.Text = 42.3m.ToString(); Assert.Equal(42.3m, vm.JustADecimal); // Bad formatting. view.SomeTextBox.Text = "--"; Assert.Equal(42.3m, vm.JustADecimal); disp1.Dispose(); vm.JustADecimal = 0; Assert.Equal(0, vm.JustADecimal); Assert.NotEqual("0", view.SomeTextBox.Text); // Empty test vm.JustAInt32 = 12; var disp2 = fixture.Bind(vm, view, x => x.JustAInt32, x => x.SomeTextBox.Text, (IObservable <Unit>)null, null); view.SomeTextBox.Text = ""; Assert.Equal(12, vm.JustAInt32); view.SomeTextBox.Text = "1.2"; Assert.Equal(12, vm.JustAInt32); view.SomeTextBox.Text = "13"; Assert.Equal(13, vm.JustAInt32); }
public void BindExpectsConverterFuncsToNotBeNull() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() {ViewModel = vm}; var fixture = new PropertyBinderImplementation(); Func<string, string> nullFunc = null; Assert.Throws<ArgumentNullException>(() => fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable<Unit>)null, nullFunc, s => s)); Assert.Throws<ArgumentNullException>(() => fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable<Unit>)null, s => s, nullFunc)); }
public void TypeConvertedTwoWayBindSmokeTest() { var vm = new PropertyBindViewModel(); var view = new PropertyBindView() { ViewModel = vm }; var fixture = new PropertyBinderImplementation(); vm.Property2 = 17; Assert.NotEqual(vm.Property2.ToString(), view.SomeTextBox.Text); var disp = fixture.Bind(vm, view, x => x.Property2, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null); Assert.Equal(vm.Property2.ToString(), view.SomeTextBox.Text); Assert.Equal(17, vm.Property2); view.SomeTextBox.Text = "42"; Assert.Equal(42, vm.Property2); // Bad formatting error view.SomeTextBox.Text = "--"; Assert.Equal(42, vm.Property2); disp.Dispose(); vm.Property2 = 0; Assert.Equal(0, vm.Property2); Assert.NotEqual("0", view.SomeTextBox.Text); vm.JustADecimal = 17.2m; var disp1 = fixture.Bind(vm, view, x => x.JustADecimal, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null); Assert.Equal(vm.JustADecimal.ToString(), view.SomeTextBox.Text); Assert.Equal(17.2m, vm.JustADecimal ); view.SomeTextBox.Text = 42.3m.ToString(); Assert.Equal(42.3m, vm.JustADecimal ); // Bad formatting. view.SomeTextBox.Text = "--"; Assert.Equal(42.3m, vm.JustADecimal ); disp1.Dispose(); vm.JustADecimal = 0; Assert.Equal(0, vm.JustADecimal); Assert.NotEqual("0", view.SomeTextBox.Text); // Empty test vm.JustAInt32 = 12; var disp2 = fixture.Bind(vm, view, x => x.JustAInt32, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null); view.SomeTextBox.Text = ""; Assert.Equal(12, vm.JustAInt32); view.SomeTextBox.Text = "1.2"; Assert.Equal(12, vm.JustAInt32); view.SomeTextBox.Text = "13"; Assert.Equal(13, vm.JustAInt32); }