public void Basics() { var src = new ListBehaviorSubject <int>(); var list = new List <int>(); var sub = src.Where(i => i % 2 == 0).Subscribe(change => change.Apply(list)); CollectionAssert.IsEmpty(list); for (var i = 0; i < 6; ++i) { src.OnAdd(i); } CollectionAssert.AreEqual(new[] { 0, 2, 4 }, list); src.OnRemove(1); CollectionAssert.AreEqual(new[] { 0, 2, 4 }, list); src.OnReplace(1, 4); CollectionAssert.AreEqual(new[] { 0, 4, 4 }, list); src.OnInsert(0, -2); CollectionAssert.AreEqual(new[] { -2, 0, 4, 4 }, list); src.OnClear(); CollectionAssert.IsEmpty(list); sub.Dispose(); }
public void ListBehaviorSubject_Subscribe_reflects_changes() { var lbs = new ListBehaviorSubject <int>(); lbs.OnAdd(1); lbs.OnAdd(2); lbs.OnAdd(3); var list = new List <int>(); var sub = lbs.Subscribe(Observer.Create <ListChange <int> >(change => change.Apply(list))); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, list); lbs.OnAdd(4); CollectionAssert.AreEqual(new[] { 1, 2, 3, 4 }, list); lbs.OnInsert(0, 0); CollectionAssert.AreEqual(new[] { 0, 1, 2, 3, 4 }, list); lbs.OnRemove(1); CollectionAssert.AreEqual(new[] { 0, 2, 3, 4 }, list); lbs.OnClear(); CollectionAssert.AreEqual(new int[] {}, list); sub.Dispose(); lbs.OnAdd(41); CollectionAssert.AreEqual(new int[] { }, list); }
public void Basics() { var src = new ListBehaviorSubject <int>(); var list = new List <int>(); var sub = src.SeparateBy(() => - 1).Subscribe(change => change.Apply(list)); CollectionAssert.IsEmpty(list); for (var i = 0; i < 3; ++i) { src.OnAdd(i); } CollectionAssert.AreEqual(new[] { 0, -1, 1, -1, 2 }, list); src.OnRemove(0); CollectionAssert.AreEqual(new[] { 1, -1, 2 }, list); src.OnRemove(1); CollectionAssert.AreEqual(new[] { 1 }, list); src.OnInsert(0, 4); CollectionAssert.AreEqual(new[] { 4, -1, 1 }, list); src.OnAdd(5); CollectionAssert.AreEqual(new[] { 4, -1, 1, -1, 5 }, list); src.OnReplace(1, 11); CollectionAssert.AreEqual(new[] { 4, -1, 11, -1, 5 }, list); src.OnClear(); CollectionAssert.IsEmpty(list); sub.Dispose(); }