Skip to content
This repository
Newer
Older
100644 330 lines (250 sloc) 11.068 kb
3ca2c492 »
2012-08-14 Implement two-way binds
1 using System;
2 using System.Collections.Generic;
733738e7 »
2012-11-27 Handle how TypeConverter special-cases strings
3 using System.ComponentModel;
3ca2c492 »
2012-08-14 Implement two-way binds
4 using System.Linq;
b75686b0 »
2012-08-19 Allow signalling updating a two-way bind via an arbitrary IObservable
5 using System.Reactive;
3ca2c492 »
2012-08-14 Implement two-way binds
6 using System.Text;
7 using Xunit;
8
9 namespace ReactiveUI.Tests
10 {
733738e7 »
2012-11-27 Handle how TypeConverter special-cases strings
11 public class PropertyBindModel
12 {
13 public int AThing { get; set; }
14 public string AnotherThing { get; set; }
15 }
16
3ca2c492 »
2012-08-14 Implement two-way binds
17 public class PropertyBindViewModel : ReactiveObject
18 {
5ae3a8c4 »
2012-08-17 Build fixups to tests
19 public string _Property1;
3ca2c492 »
2012-08-14 Implement two-way binds
20 public string Property1 {
21 get { return _Property1; }
0a67c616 »
2013-03-29 Removed backing field conventions.
22 set { this.RaiseAndSetIfChanged(ref _Property1, value); }
3ca2c492 »
2012-08-14 Implement two-way binds
23 }
c90b90a6 »
2012-11-13 Smoke test type conversion
24
25 public int _Property2;
26 public int Property2 {
27 get { return _Property2; }
0a67c616 »
2013-03-29 Removed backing field conventions.
28 set { this.RaiseAndSetIfChanged(ref _Property2, value); }
c90b90a6 »
2012-11-13 Smoke test type conversion
29 }
1d4a8a7d »
2012-11-26 Fix casting issues on reference types. Closes #122
30
50e65568 »
2012-12-04 Add some more tests
31 public double _JustADouble;
32 public double JustADouble {
33 get { return _JustADouble; }
0a67c616 »
2013-03-29 Removed backing field conventions.
34 set { this.RaiseAndSetIfChanged(ref _JustADouble, value); }
50e65568 »
2012-12-04 Add some more tests
35 }
36
8d692c94 »
2013-02-12 Fix issue #117
37 public decimal _JustADecimal;
38 public decimal JustADecimal {
39 get { return _JustADecimal; }
0a67c616 »
2013-03-29 Removed backing field conventions.
40 set { this.RaiseAndSetIfChanged(ref _JustADecimal, value); }
8d692c94 »
2013-02-12 Fix issue #117
41 }
42
3bb6d54d »
2013-02-13 Fixes #180 conversion errors are not handled correctly
43 public int _JustAInt32;
44 public int JustAInt32 {
45 get { return _JustAInt32; }
0a67c616 »
2013-03-29 Removed backing field conventions.
46 set { this.RaiseAndSetIfChanged(ref _JustAInt32, value); }
3bb6d54d »
2013-02-13 Fixes #180 conversion errors are not handled correctly
47 }
48
50e65568 »
2012-12-04 Add some more tests
49 public double? _NullableDouble;
50 public double? NullableDouble {
51 get { return _NullableDouble; }
0a67c616 »
2013-03-29 Removed backing field conventions.
52 set { this.RaiseAndSetIfChanged(ref _NullableDouble, value); }
50e65568 »
2012-12-04 Add some more tests
53 }
54
aadb745a »
2013-05-18 ReactiveCollection => ReactiveList
55 public ReactiveList<string> SomeCollectionOfStrings { get; protected set; }
1d4a8a7d »
2012-11-26 Fix casting issues on reference types. Closes #122
56
daa5841f »
2013-03-04 Add a test to simulate WinRT's hatred of nulls
57 public PropertyBindModel _Model;
58 public PropertyBindModel Model {
59 get { return _Model; }
0a67c616 »
2013-03-29 Removed backing field conventions.
60 set { this.RaiseAndSetIfChanged(ref _Model, value); }
daa5841f »
2013-03-04 Add a test to simulate WinRT's hatred of nulls
61 }
733738e7 »
2012-11-27 Handle how TypeConverter special-cases strings
62
daa5841f »
2013-03-04 Add a test to simulate WinRT's hatred of nulls
63 public PropertyBindViewModel(PropertyBindModel model = null)
1d4a8a7d »
2012-11-26 Fix casting issues on reference types. Closes #122
64 {
daa5841f »
2013-03-04 Add a test to simulate WinRT's hatred of nulls
65 Model = model ?? new PropertyBindModel() {AThing = 42, AnotherThing = "Baz"};
aadb745a »
2013-05-18 ReactiveCollection => ReactiveList
66 SomeCollectionOfStrings = new ReactiveList<string>(new[] { "Foo", "Bar" });
1d4a8a7d »
2012-11-26 Fix casting issues on reference types. Closes #122
67 }
3ca2c492 »
2012-08-14 Implement two-way binds
68 }
69
70 public class PropertyBindingTest
71 {
72 [Fact]
73 public void TwoWayBindSmokeTest()
74 {
75 var vm = new PropertyBindViewModel();
76 var view = new PropertyBindView() {ViewModel = vm};
77 var fixture = new PropertyBinderImplementation();
78
79 vm.Property1 = "Foo";
80 Assert.NotEqual(vm.Property1, view.SomeTextBox.Text);
81
4f93792a »
2012-11-13 Plumb in conversionHint into interfaces
82 var disp = fixture.Bind(vm, view, x => x.Property1, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null);
3ca2c492 »
2012-08-14 Implement two-way binds
83
84 Assert.Equal(vm.Property1, view.SomeTextBox.Text);
85 Assert.Equal("Foo", vm.Property1);
86
87 view.SomeTextBox.Text = "Bar";
88 Assert.Equal(vm.Property1, "Bar");
89
90 disp.Dispose();
91 vm.Property1 = "Baz";
92
93 Assert.Equal("Baz", vm.Property1);
94 Assert.NotEqual(vm.Property1, view.SomeTextBox.Text);
95 }
c90b90a6 »
2012-11-13 Smoke test type conversion
96
97 [Fact]
98 public void TypeConvertedTwoWayBindSmokeTest()
99 {
100 var vm = new PropertyBindViewModel();
101 var view = new PropertyBindView() { ViewModel = vm };
102 var fixture = new PropertyBinderImplementation();
103
104 vm.Property2 = 17;
105 Assert.NotEqual(vm.Property2.ToString(), view.SomeTextBox.Text);
106
107 var disp = fixture.Bind(vm, view, x => x.Property2, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null);
108
109 Assert.Equal(vm.Property2.ToString(), view.SomeTextBox.Text);
110 Assert.Equal(17, vm.Property2);
111
112 view.SomeTextBox.Text = "42";
113 Assert.Equal(42, vm.Property2);
114
3bb6d54d »
2013-02-13 Fixes #180 conversion errors are not handled correctly
115 // Bad formatting error
116 view.SomeTextBox.Text = "--";
117 Assert.Equal(42, vm.Property2);
118
c90b90a6 »
2012-11-13 Smoke test type conversion
119 disp.Dispose();
120 vm.Property2 = 0;
121
122 Assert.Equal(0, vm.Property2);
123 Assert.NotEqual("0", view.SomeTextBox.Text);
8d692c94 »
2013-02-12 Fix issue #117
124
125 vm.JustADecimal = 17.2m;
126 var disp1 = fixture.Bind(vm, view, x => x.JustADecimal, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null);
127
128 Assert.Equal(vm.JustADecimal.ToString(), view.SomeTextBox.Text);
129 Assert.Equal(17.2m, vm.JustADecimal );
130
131 view.SomeTextBox.Text = 42.3m.ToString();
132 Assert.Equal(42.3m, vm.JustADecimal );
133
3bb6d54d »
2013-02-13 Fixes #180 conversion errors are not handled correctly
134 // Bad formatting.
135 view.SomeTextBox.Text = "--";
136 Assert.Equal(42.3m, vm.JustADecimal );
137
8d692c94 »
2013-02-12 Fix issue #117
138 disp1.Dispose();
3bb6d54d »
2013-02-13 Fixes #180 conversion errors are not handled correctly
139
8d692c94 »
2013-02-12 Fix issue #117
140 vm.JustADecimal = 0;
141
142 Assert.Equal(0, vm.JustADecimal);
143 Assert.NotEqual("0", view.SomeTextBox.Text);
3bb6d54d »
2013-02-13 Fixes #180 conversion errors are not handled correctly
144
145 // Empty test
146 vm.JustAInt32 = 12;
147 var disp2 = fixture.Bind(vm, view, x => x.JustAInt32, x => x.SomeTextBox.Text, (IObservable<Unit>)null, null);
148
149 view.SomeTextBox.Text = "";
150 Assert.Equal(12, vm.JustAInt32);
151
152 view.SomeTextBox.Text = "1.2";
153
154 Assert.Equal(12, vm.JustAInt32);
155
156 view.SomeTextBox.Text = "13";
157 Assert.Equal(13, vm.JustAInt32);
c90b90a6 »
2012-11-13 Smoke test type conversion
158 }
1d4a8a7d »
2012-11-26 Fix casting issues on reference types. Closes #122
159
160 [Fact]
733738e7 »
2012-11-27 Handle how TypeConverter special-cases strings
161 public void BindingIntoModelObjects()
162 {
163 var vm = new PropertyBindViewModel();
164 var view = new PropertyBindView() {ViewModel = vm};
165
166 view.OneWayBind(view.ViewModel, x => x.Model.AnotherThing, x => x.SomeTextBox.Text);
167 Assert.Equal("Baz", view.SomeTextBox.Text);
168 }
f31f7190 »
2012-11-27 Handle implicit binds correctly when types are converted. Fixes #125
169
170 [Fact]
171 public void ImplicitBindPlusTypeConversion()
172 {
173 var vm = new PropertyBindViewModel();
174 var view = new PropertyBindView() {ViewModel = vm};
175
176 view.Bind(view.ViewModel, x => x.Property2);
177
178 vm.Property2 = 42;
179 Assert.Equal("42", view.Property2.Text);
180
181 view.Property2.Text = "7";
182 Assert.Equal(7, vm.Property2);
183 }
50e65568 »
2012-12-04 Add some more tests
184
185 [Fact]
186 public void ViewModelNullableToViewNonNullable()
187 {
188 var vm = new PropertyBindViewModel();
189 var view = new PropertyBindView() {ViewModel = vm};
190
191 view.Bind(view.ViewModel, x => x.NullableDouble, x => x.FakeControl.JustADouble);
192 Assert.Equal(0.0, view.FakeControl.JustADouble);
193
194 vm.NullableDouble = 4.0;
195 Assert.Equal(4.0, view.FakeControl.JustADouble);
196
197 vm.NullableDouble = null;
198 Assert.Equal(4.0, view.FakeControl.JustADouble);
199
200 vm.NullableDouble = 0.0;
201 Assert.Equal(0.0, view.FakeControl.JustADouble);
202 }
203
204 [Fact]
205 public void ViewModelNonNullableToViewNullable()
206 {
207 var vm = new PropertyBindViewModel();
208 var view = new PropertyBindView() {ViewModel = vm};
209
210 view.Bind(view.ViewModel, x => x.JustADouble, x => x.FakeControl.NullableDouble);
211 Assert.Equal(0.0, vm.JustADouble);
212
213 view.FakeControl.NullableDouble = 4.0;
214 Assert.Equal(4.0, vm.JustADouble);
215
216 view.FakeControl.NullableDouble = null;
217 Assert.Equal(4.0, vm.JustADouble);
218
219 view.FakeControl.NullableDouble = 0.0;
220 Assert.Equal(0.0, vm.JustADouble);
221 }
222
223 [Fact]
224 public void ViewModelNullableToViewNullable()
225 {
226 var vm = new PropertyBindViewModel();
227 var view = new PropertyBindView() {ViewModel = vm};
228
229 view.Bind(view.ViewModel, x => x.NullableDouble, x => x.FakeControl.NullableDouble);
230 Assert.Equal(null, vm.NullableDouble);
231
232 view.FakeControl.NullableDouble = 4.0;
233 Assert.Equal(4.0, vm.NullableDouble);
234
235 view.FakeControl.NullableDouble = null;
236 Assert.Equal(null, vm.NullableDouble);
237
238 view.FakeControl.NullableDouble = 0.0;
239 Assert.Equal(0.0, vm.NullableDouble);
240 }
49c59f49 »
2013-01-02 Make the programming model for binding hooks easier
241
242 [Fact]
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
243 public void BindToShouldntInitiallySetToNull()
244 {
245 var vm = new PropertyBindViewModel();
246 var view = new PropertyBindView() {ViewModel = null};
247
248 view.OneWayBind(vm, x => x.Model.AnotherThing, x => x.FakeControl.NullHatingString);
249 Assert.Equal("", view.FakeControl.NullHatingString);
250
251 view.ViewModel = vm;
252 Assert.Equal(vm.Model.AnotherThing, view.FakeControl.NullHatingString);
253 }
254
255 [Fact]
256 public void BindToTypeConversionSmokeTest()
257 {
258 var vm = new PropertyBindViewModel();
259 var view = new PropertyBindView() {ViewModel = null};
260
1571ddc9 »
2013-07-12 Introduce WhenAnyValue() mixin
261 view.WhenAnyValue(x => x.ViewModel.JustADouble)
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
262 .BindTo(view, x => x.FakeControl.NullHatingString);
263
264 Assert.Equal("", view.FakeControl.NullHatingString);
265
266 view.ViewModel = vm;
267 Assert.Equal(vm.JustADouble.ToString(), view.FakeControl.NullHatingString);
268 }
14f9afd9 »
2014-04-09 Something wrong with the binding
269
270 [Fact]
271 public void TwoWayBindToSelectedItemOfItemsControl()
272 {
273 var vm = new PropertyBindViewModel();
274 var view = new PropertyBindView() { ViewModel = vm };
275 view.FakeItemsControl.ItemsSource = new ReactiveList<string>(new[] { "aaa", "bbb", "ccc" });
276
277 view.Bind(view.ViewModel, x => x.Property1, x => x.FakeItemsControl.SelectedItem);
278
279 Assert.Null(view.FakeItemsControl.SelectedItem);
280 Assert.Null(vm.Property1);
281
282 view.FakeItemsControl.SelectedItem = "aaa";
283 Assert.Equal("aaa", vm.Property1); // fail
284
285 vm.Property1 = "bbb";
286 Assert.Equal("bbb", view.FakeItemsControl.SelectedItem);
287 }
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
288
289 #if !MONO
290 [Fact]
49c59f49 »
2013-01-02 Make the programming model for binding hooks easier
291 public void ItemsControlShouldGetADataTemplate()
292 {
293 var vm = new PropertyBindViewModel();
294 var view = new PropertyBindView() {ViewModel = vm};
295
487b4c34 »
2013-04-14 This doesn't actually need to override the service locator
296 Assert.Null(view.FakeItemsControl.ItemTemplate);
297 view.OneWayBind(vm, x => x.SomeCollectionOfStrings, x => x.FakeItemsControl.ItemsSource);
a937e983 »
2013-02-07 Fix failing auto DataTemplate test
298
487b4c34 »
2013-04-14 This doesn't actually need to override the service locator
299 Assert.NotNull(view.FakeItemsControl.ItemTemplate);
49c59f49 »
2013-01-02 Make the programming model for binding hooks easier
300 }
a937e983 »
2013-02-07 Fix failing auto DataTemplate test
301
daa5841f »
2013-03-04 Add a test to simulate WinRT's hatred of nulls
302 [Fact]
75350c91 »
2013-03-05 Fix dumb bug where view chain might not actually be initialized :-/
303 public void ItemsControlShouldGetADataTemplateInBindTo()
304 {
305 var vm = new PropertyBindViewModel();
306 var view = new PropertyBindView() {ViewModel = vm};
307
487b4c34 »
2013-04-14 This doesn't actually need to override the service locator
308 Assert.Null(view.FakeItemsControl.ItemTemplate);
1571ddc9 »
2013-07-12 Introduce WhenAnyValue() mixin
309 vm.WhenAnyValue(x => x.SomeCollectionOfStrings)
487b4c34 »
2013-04-14 This doesn't actually need to override the service locator
310 .BindTo(view, v => v.FakeItemsControl.ItemsSource);
75350c91 »
2013-03-05 Fix dumb bug where view chain might not actually be initialized :-/
311
487b4c34 »
2013-04-14 This doesn't actually need to override the service locator
312 Assert.NotNull(view.FakeItemsControl.ItemTemplate);
75350c91 »
2013-03-05 Fix dumb bug where view chain might not actually be initialized :-/
313
1571ddc9 »
2013-07-12 Introduce WhenAnyValue() mixin
314 view.WhenAnyValue(x => x.FakeItemsControl.SelectedItem)
487b4c34 »
2013-04-14 This doesn't actually need to override the service locator
315 .BindTo(vm, x => x.Property1);
75350c91 »
2013-03-05 Fix dumb bug where view chain might not actually be initialized :-/
316 }
317
318 [Fact]
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
319 public void BindingToItemsControl()
08ce999c »
2013-03-04 Add a test to verify type conversion works
320 {
321 var vm = new PropertyBindViewModel();
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
322 var view = new PropertyBindView() {ViewModel = vm};
08ce999c »
2013-03-04 Add a test to verify type conversion works
323
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
324 view.OneWayBind(view.ViewModel, x => x.SomeCollectionOfStrings, x => x.FakeItemsControl.ItemsSource);
325 Assert.True(view.FakeItemsControl.ItemsSource.OfType<string>().Count() > 1);
08ce999c »
2013-03-04 Add a test to verify type conversion works
326 }
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
327 #endif
3ca2c492 »
2012-08-14 Implement two-way binds
328 }
712fd7c0 »
2013-06-11 Fix PropertyBindingTests for iOS
329 }
Something went wrong with that request. Please try again.