public void OFPReplacingTheHostWithNullThenSettingItBackShouldResubscribeTheObservable() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() { Child = new TestFixture() }; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); fixture.Child.IsOnlyOneWord = "Foo"; sched.Start(); Assert.Equal(1, changes.Count); fixture.Child.IsOnlyOneWord = "Bar"; sched.Start(); Assert.Equal(2, changes.Count); // Oops, now the child is Null, we may now blow up fixture.Child = null; 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); 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 }); }); }
public void WhenAnyThroughAViewShouldntGiveNullValues() { var vm = new HostTestFixture() { Child = new TestFixture() { IsNotNullString = "Foo", IsOnlyOneWord = "Baz", PocoProperty = "Bamf" }, }; var fixture = new HostTestView(); var output = new List <string>(); Assert.Equal(0, output.Count); Assert.Null(fixture.ViewModel); fixture.WhenAnyValue(x => x.ViewModel.Child.IsNotNullString).Subscribe(output.Add); fixture.ViewModel = vm; Assert.Equal(1, output.Count); fixture.ViewModel.Child.IsNotNullString = "Bar"; Assert.Equal(2, output.Count); new[] { "Foo", "Bar" }.AssertAreEqual(output); }
public void OFPChangingTheHostPropertyShouldFireAChildChangeNotificationOnlyIfThePreviousChildIsDifferent() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() { Child = new TestFixture() }; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); 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 OFPSimpleChildPropertyTest() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() { Child = new TestFixture() }; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); 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 BindToIsNotFooledByIntermediateObjectSwitching() { new TestScheduler().With(sched => { var input = new ScheduledSubject <string>(sched); var fixture = new HostTestFixture { Child = new TestFixture() }; input.BindTo(fixture, x => x.Child.IsNotNullString); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Foo"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); fixture.Child = new TestFixture(); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); input.OnNext("Bar"); sched.Start(); Assert.Equal("Bar", fixture.Child.IsNotNullString); }); }
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 WhenAnySmokeTest() { new TestScheduler().With( sched => { var fixture = new HostTestFixture { Child = new TestFixture() }; fixture.SomeOtherParam = 5; fixture.Child.IsNotNullString = "Foo"; var output1 = new List <IObservedChange <HostTestFixture, int> >(); var output2 = new List <IObservedChange <HostTestFixture, string> >(); fixture.WhenAny( x => x.SomeOtherParam, x => x.Child.IsNotNullString, (sop, nns) => new { sop, nns }).Subscribe( x => { output1.Add(x.sop); output2.Add(x.nns); }); sched.Start(); Assert.Equal(1, output1.Count); Assert.Equal(1, output2.Count); Assert.Equal(fixture, output1[0].Sender); Assert.Equal(fixture, output2[0].Sender); Assert.Equal(5, output1[0].Value); Assert.Equal("Foo", output2[0].Value); fixture.SomeOtherParam = 10; sched.Start(); Assert.Equal(2, output1.Count); Assert.Equal(2, output2.Count); Assert.Equal(fixture, output1[1].Sender); Assert.Equal(fixture, output2[1].Sender); Assert.Equal(10, output1[1].Value); Assert.Equal("Foo", output2[1].Value); fixture.Child.IsNotNullString = "Bar"; sched.Start(); Assert.Equal(3, output1.Count); Assert.Equal(3, output2.Count); Assert.Equal(fixture, output1[2].Sender); Assert.Equal(fixture, output2[2].Sender); Assert.Equal(10, output1[2].Value); Assert.Equal("Bar", output2[2].Value); }); }
public void GetValueShouldReturnTheValueFromAPath() { var input = new HostTestFixture() { Child = new TestFixture() {IsNotNullString = "Foo"}, }; Expression<Func<HostTestFixture, string>> expression = x => x.Child.IsNotNullString; var fixture = new ObservedChange<HostTestFixture, string>(input, expression.Body); Assert.Equal("Foo", fixture.GetValue()); }
public void SubscriptionToWhenAnyShouldReturnCurrentValue() { var obj = new HostTestFixture(); var observedValue = 1; obj.WhenAnyValue(x => x.SomeOtherParam).Subscribe(x => observedValue = x); obj.SomeOtherParam = 42; Assert.True(observedValue == obj.SomeOtherParam); }
public void SetValuePathSmokeTest() { var output = new HostTestFixture() { Child = new TestFixture() {IsNotNullString = "Foo"}, }; Expression<Func<TestFixture, string>> expression = x => x.IsOnlyOneWord; var fixture = new ObservedChange<TestFixture, string>(new TestFixture() { IsOnlyOneWord = "Bar" }, expression.Body); fixture.SetValueToProperty(output, x => x.Child.IsNotNullString); Assert.Equal("Bar", output.Child.IsNotNullString); }
public void AutoPersistDoesntWorkOnNonDataContractClasses() { var fixture = new HostTestFixture(); bool shouldDie = true; try { fixture.AutoPersist(x => Observable.Return(Unit.Default)); } catch (Exception ex) { shouldDie = false; } Assert.False(shouldDie); }
public void GetValueShouldReturnTheValueFromAPath() { var input = new HostTestFixture { Child = new TestFixture { IsNotNullString = "Foo" }, }; Expression <Func <HostTestFixture, string> > expression = x => x !.Child !.IsNotNullString !; var fixture = new ObservedChange <HostTestFixture, string?>(input, expression.Body, default); Assert.Equal("Foo", fixture.GetValue()); }
public void AutoPersistDoesntWorkOnNonDataContractClasses() { var fixture = new HostTestFixture(); bool shouldDie = true; try { fixture.AutoPersist(x => Observable.Return(Unit.Default)); } catch (Exception) { shouldDie = false; } Assert.False(shouldDie); }
public void AutoPersistDoesntWorkOnNonDataContractClasses() { var fixture = new HostTestFixture(); var shouldDie = true; try { fixture.AutoPersist(_ => Observables.Unit); } catch (Exception) { shouldDie = false; } Assert.False(shouldDie); }
public void SetValuePathSmokeTest() { var output = new HostTestFixture { Child = new TestFixture { IsNotNullString = "Foo" }, }; Expression <Func <TestFixture, string> > expression = x => x.IsOnlyOneWord !; var fixture = new ObservedChange <TestFixture, string?>(new TestFixture { IsOnlyOneWord = "Bar" }, expression.Body, default); fixture.SetValueToProperty(output, x => x.Child !.IsNotNullString); Assert.Equal("Bar", output.Child.IsNotNullString); }
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" }); }); }
public void GetValueShouldReturnTheValueFromAPath() { var input = new HostTestFixture() { Child = new TestFixture() { IsNotNullString = "Foo" }, }; var fixture = new ObservedChange <HostTestFixture, string>() { Sender = input, PropertyName = "Child.IsNotNullString", Value = null, }; Assert.Equal("Foo", fixture.GetValue()); }
public void BindToSmokeTest() { (new TestScheduler()).With(sched => { var input = new ScheduledSubject<string>(sched); var fixture = new HostTestFixture() {Child = new TestFixture()}; input.BindTo(fixture, x => x.Child.IsNotNullString); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Foo"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); input.OnNext("Bar"); sched.Start(); Assert.Equal("Bar", fixture.Child.IsNotNullString); }); }
public void DisposingDisconnectsTheBindTo() { (new TestScheduler()).With(sched => { var input = new ScheduledSubject<string>(sched); var fixture = new HostTestFixture() {Child = new TestFixture()}; var subscription = input.BindTo(fixture, x => x.Child.IsNotNullString); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Foo"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); subscription.Dispose(); input.OnNext("Bar"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); }); }
public void BindToSmokeTest() { (new TestScheduler()).With(sched => { var input = new ScheduledSubject <string>(sched); var fixture = new HostTestFixture() { Child = new TestFixture() }; input.BindTo(fixture, x => x.Child.IsNotNullString); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Foo"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); input.OnNext("Bar"); sched.Start(); Assert.Equal("Bar", fixture.Child.IsNotNullString); }); }
public void SetValuePathSmokeTest() { var output = new HostTestFixture() { Child = new TestFixture() { IsNotNullString = "Foo" }, }; var fixture = new ObservedChange <TestFixture, string>() { Sender = new TestFixture() { IsOnlyOneWord = "Bar" }, PropertyName = "IsOnlyOneWord", Value = null, }; fixture.SetValueToProperty(output, x => x.Child.IsNotNullString); Assert.Equal("Bar", output.Child.IsNotNullString); }
public void BindToIsNotFooledByIntermediateObjectSwitching() { (new TestScheduler()).With(sched => { var input = new ScheduledSubject<string>(sched); var fixture = new HostTestFixture() {Child = new TestFixture()}; var subscription = input.BindTo(fixture, x => x.Child.IsNotNullString); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Foo"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); fixture.Child = new TestFixture(); sched.Start(); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Bar"); sched.Start(); Assert.Equal("Bar", fixture.Child.IsNotNullString); }); }
public void DisposingDisconnectsTheBindTo() { new TestScheduler().With(sched => { var input = new ScheduledSubject <string>(sched); var fixture = new HostTestFixture { Child = new TestFixture() }; var subscription = input.BindTo(fixture, x => x.Child.IsNotNullString); Assert.Null(fixture.Child.IsNotNullString); input.OnNext("Foo"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); subscription.Dispose(); input.OnNext("Bar"); sched.Start(); Assert.Equal("Foo", fixture.Child.IsNotNullString); }); }
public void OFPSimpleChildPropertyTest() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() {Child = new TestFixture()}; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); 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.PropertyName == "Child.IsOnlyOneWord")); changes.Select(x => x.Value).AssertAreEqual(new[] {"Foo", "Bar", "Baz"}); }); }
public void SetValuePathSmokeTest() { var output = new HostTestFixture() { Child = new TestFixture() {IsNotNullString = "Foo"}, }; var fixture = new ObservedChange<TestFixture, string>() { Sender = new TestFixture() { IsOnlyOneWord = "Bar" }, PropertyName = "IsOnlyOneWord", Value = null, }; fixture.SetValueToProperty(output, x => x.Child.IsNotNullString); Assert.Equal("Bar", output.Child.IsNotNullString); }
public void GetValueShouldReturnTheValueFromAPath() { var input = new HostTestFixture() { Child = new TestFixture() {IsNotNullString = "Foo"}, }; var fixture = new ObservedChange<HostTestFixture, string>() { Sender = input, PropertyName = "Child.IsNotNullString", Value = null, }; Assert.Equal("Foo", fixture.GetValue()); }
public void OFPChangingTheHostPropertyShouldFireAChildChangeNotificationOnlyIfThePreviousChildIsDifferent() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() {Child = new TestFixture()}; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); 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 OFPReplacingTheHostWithNullThenSettingItBackShouldResubscribeTheObservable() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() {Child = new TestFixture()}; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); fixture.Child.IsOnlyOneWord = "Foo"; sched.Start(); Assert.Equal(1, changes.Count); fixture.Child.IsOnlyOneWord = "Bar"; sched.Start(); Assert.Equal(2, changes.Count); // Oops, now the child is Null, we may now blow up fixture.Child = null; 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); Assert.True(changes.All(x => x.Sender == fixture)); Assert.True(changes.All(x => x.PropertyName == "Child.IsOnlyOneWord")); changes.Select(x => x.Value).AssertAreEqual(new[] {"Foo", "Bar", null}); }); }
public void WhenAnySmokeTest() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() {Child = new TestFixture()}; fixture.SomeOtherParam = 5; fixture.Child.IsNotNullString = "Foo"; var output1 = new List<IObservedChange<HostTestFixture, int>>(); var output2 = new List<IObservedChange<HostTestFixture, string>>(); fixture.WhenAny(x => x.SomeOtherParam, x => x.Child.IsNotNullString, (sop, nns) => new {sop, nns}).Subscribe(x => { output1.Add(x.sop); output2.Add(x.nns); }); sched.Start(); Assert.Equal(1, output1.Count); Assert.Equal(1, output2.Count); Assert.Equal(fixture, output1[0].Sender); Assert.Equal(fixture, output2[0].Sender); Assert.Equal(5, output1[0].Value); Assert.Equal("Foo", output2[0].Value); fixture.SomeOtherParam = 10; sched.Start(); Assert.Equal(2, output1.Count); Assert.Equal(2, output2.Count); Assert.Equal(fixture, output1[1].Sender); Assert.Equal(fixture, output2[1].Sender); Assert.Equal(10, output1[1].Value); Assert.Equal("Foo", output2[1].Value); fixture.Child.IsNotNullString = "Bar"; sched.Start(); Assert.Equal(3, output1.Count); Assert.Equal(3, output2.Count); Assert.Equal(fixture, output1[2].Sender); Assert.Equal(fixture, output2[2].Sender); Assert.Equal(10, output1[2].Value); Assert.Equal("Bar", output2[2].Value); }); }
public void SubscriptionToWhenAnyShouldReturnCurrentValue() { var obj = new HostTestFixture(); int observedValue = 1; obj.WhenAny(x => x.SomeOtherParam, x => x.Value) .Subscribe(x => observedValue = x); obj.SomeOtherParam = 42; Assert.True(observedValue == obj.SomeOtherParam); }
public void OFPReplacingTheHostShouldResubscribeTheObservable() { (new TestScheduler()).With(sched => { var fixture = new HostTestFixture() {Child = new TestFixture()}; var changes = fixture.ObservableForProperty(x => x.Child.IsOnlyOneWord).CreateCollection(); fixture.Child.IsOnlyOneWord = "Foo"; sched.Run(); Assert.Equal(1, changes.Count); fixture.Child.IsOnlyOneWord = "Bar"; sched.Run(); 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.Run(); Assert.Equal(3, changes.Count); // Here we've set the value but it shouldn't change fixture.Child.IsOnlyOneWord = null; sched.Run(); Assert.Equal(3, changes.Count); fixture.Child.IsOnlyOneWord = "Baz"; sched.Run(); Assert.Equal(4, changes.Count); fixture.Child.IsOnlyOneWord = "Baz"; sched.Run(); Assert.Equal(4, changes.Count); Assert.True(changes.All(x => x.Sender == fixture)); Assert.True(changes.All(x => x.PropertyName == "Child.IsOnlyOneWord")); changes.Select(x => x.Value).AssertAreEqual(new[] {"Foo", "Bar", null, "Baz"}); }); }