public void OFPSimpleChildPropertyTest() { new TestScheduler().With(sched => { var fixture = new HostTestFixture { Child = new TestFixture() }; fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord) .ToObservableChangeSet(ImmediateScheduler.Instance) .Bind(out var changes) .Subscribe(); fixture.Child.IsOnlyOneWord = "Foo"; sched.Start(); Assert.Equal(1, changes.Count); fixture.Child.IsOnlyOneWord = "Bar"; sched.Start(); Assert.Equal(2, changes.Count); fixture.Child.IsOnlyOneWord = "Baz"; sched.Start(); Assert.Equal(3, changes.Count); fixture.Child.IsOnlyOneWord = "Baz"; sched.Start(); Assert.Equal(3, changes.Count); Assert.True(changes.All(x => x.Sender == fixture)); Assert.True(changes.All(x => x.GetPropertyName() == "Child.IsOnlyOneWord")); changes.Select(x => x.Value).AssertAreEqual(new[] { "Foo", "Bar", "Baz" }); }); }
public void OFPChangingTheHostPropertyShouldFireAChildChangeNotificationOnlyIfThePreviousChildIsDifferent() { new TestScheduler().With(sched => { var fixture = new HostTestFixture { Child = new TestFixture() }; fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord) .ToObservableChangeSet(ImmediateScheduler.Instance) .Bind(out var changes) .Subscribe(); fixture.Child.IsOnlyOneWord = "Foo"; sched.Start(); Assert.Equal(1, changes.Count); fixture.Child.IsOnlyOneWord = "Bar"; sched.Start(); Assert.Equal(2, changes.Count); fixture.Child = new TestFixture { IsOnlyOneWord = "Bar" }; sched.Start(); Assert.Equal(2, changes.Count); }); }
public void OFPReplacingTheHostShouldResubscribeTheObservable() { new TestScheduler().With(sched => { var fixture = new HostTestFixture { Child = new TestFixture() }; fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord) .ToObservableChangeSet(ImmediateScheduler.Instance) .Bind(out var changes) .Subscribe(); fixture.Child.IsOnlyOneWord = "Foo"; sched.Start(); Assert.Equal(1, changes.Count); fixture.Child.IsOnlyOneWord = "Bar"; sched.Start(); Assert.Equal(2, changes.Count); // Tricky! This is a change too, because from the perspective // of the binding, we've went from "Bar" to null fixture.Child = new TestFixture(); sched.Start(); Assert.Equal(3, changes.Count); // Here we've set the value but it shouldn't change fixture.Child.IsOnlyOneWord = null; sched.Start(); Assert.Equal(3, changes.Count); fixture.Child.IsOnlyOneWord = "Baz"; sched.Start(); Assert.Equal(4, changes.Count); fixture.Child.IsOnlyOneWord = "Baz"; sched.Start(); Assert.Equal(4, changes.Count); Assert.True(changes.All(x => x.Sender == fixture)); Assert.True(changes.All(x => x.GetPropertyName() == "Child.IsOnlyOneWord")); changes.Select(x => x.Value).AssertAreEqual(new[] { "Foo", "Bar", null, "Baz" }); }); }