public void ShouldNotConnectInitially() { var isRunning = true; var subject = new Subject<long>(); Observable.Interval(TimeSpan.FromSeconds(.1)).Subscribe(l => { if (isRunning) subject.OnNext(l + 5); }); var prop = subject.ToConnectableObservable(() => isRunning = true, () => isRunning = false) .ToColdReadOnlyReactiveProperty(); prop.Value.Should().Be(0); }
public void ShouldDisconnectOnUnsubscribe() { var isRunning = true; var subject = new Subject<long>(); Observable.Interval(TimeSpan.FromSeconds(.1)).Subscribe(l => { if (isRunning) subject.OnNext(l + 5); }); var prop = subject.ToConnectableObservable(() => isRunning = true, () => isRunning = false) .ToColdReadOnlyReactiveProperty(); var d = prop.Subscribe(value => { }); Thread.Sleep(150); d.Dispose(); var valueOnUnsubscribe = prop.Value; Thread.Sleep(150); prop.Value.Should().Be(valueOnUnsubscribe); }