public void TestCollectionUnsubscribe() { { var c = new[] { 1, 2, 3 }.ToCollection().ToLiveCollection(); var d = c.ToIndependent(); var observer = d.CreateObserver(() => { }); using (d.Subscribe(observer)) { using (var s = observer.GetState()) { Assert.IsTrue(s.Status == StateStatus.Connecting); Assert.IsTrue(s.Inner.UnorderedEqual(new[] { 1, 2, 3 })); Assert.IsTrue(s.Delta == null); } } using (Publish.Transaction(true)) { c.PublishInner.Add(0); } using (var s = observer.GetState()) { Assert.IsTrue(s.Status == StateStatus.Completing); Assert.IsTrue(s.Inner.UnorderedEqual(new[] { 0, 1, 2, 3 })); Assert.IsTrue(s.Delta.Inserts.UnorderedEqual(new[] { 0 })); Assert.IsTrue(s.Delta.Deletes == null); } } GC.Collect(); GC.WaitForPendingFinalizers(); }
public void TestCollectionRestart() { var c = new[] { 1 }.ToCollection().ToLiveCollection(); var f = c.ToIndependent(); f.Trace("f"); f.States().Take(1).Check( () => { }, results => { var state = results.Single(); Assert.AreEqual(StateStatus.Connecting, state.Status); Assert.AreEqual(null, state.Delta); Assert.IsTrue(state.Inner.UnorderedEqual(new[] { 1 })); Assert.AreEqual(0, state.LastUpdated); }); f.States().Skip(1).Take(1).Check( () => c.PublishInner.Connect(new[] { 1, 2, 3 }, 1000), results => { var state = results.Single(); Assert.AreEqual(StateStatus.Reconnecting, state.Status); Assert.AreEqual(null, state.Delta); Assert.IsTrue(state.Inner.UnorderedEqual(new[] { 1, 2, 3 })); Assert.AreEqual(1000, state.LastUpdated); }); }