forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependencyObjectObservableForPropertyTest.cs
58 lines (48 loc) · 1.94 KB
/
DependencyObjectObservableForPropertyTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ReactiveUI.Xaml;
using Xunit;
namespace ReactiveUI.Tests
{
public class DepObjFixture : FrameworkElement
{
public static readonly DependencyProperty TestStringProperty =
DependencyProperty.Register("TestString", typeof(string), typeof(DepObjFixture), new PropertyMetadata(null));
public string TestString {
get { return (string)GetValue(TestStringProperty); }
set { SetValue(TestStringProperty, value); }
}
}
public class DependencyObjectObservableForPropertyTest
{
[Fact]
public void DependencyObjectObservableForPropertySmokeTest()
{
var fixture = new DepObjFixture();
var binder = new DependencyObjectObservableForProperty();
Assert.NotEqual(0, binder.GetAffinityForObject(typeof (DepObjFixture)));
var results = new List<IObservedChange<object, object>>();
var disp1 = binder.GetNotificationForProperty(fixture, "TestString").Subscribe(results.Add);
var disp2 = binder.GetNotificationForProperty(fixture, "TestString").Subscribe(results.Add);
fixture.TestString = "Foo";
fixture.TestString = "Bar";
Assert.Equal(4, results.Count);
disp1.Dispose();
disp2.Dispose();
}
[Fact]
public void WhenAnyWithDependencyObjectTest()
{
var inputs = new[] {"Foo", "Bar", "Baz"};
var fixture = new DepObjFixture();
var outputs = fixture.WhenAny(x => x.TestString, x => x.Value).CreateCollection();
inputs.ForEach(x => fixture.TestString = x);
Assert.Null(outputs.First());
Assert.Equal(4, outputs.Count);
Assert.True(inputs.Zip(outputs.Skip(1), (expected, actual) => expected == actual).All(x => x));
}
}
}