예제 #1
0
        public void Replace()
        {
            var left  = new ListBehaviorSubject <int>();
            var right = new ListBehaviorSubject <int>();

            left.OnAdd(1);
            left.OnAdd(2);
            left.OnAdd(3);

            right.OnAdd(4);
            right.OnAdd(5);
            right.OnAdd(6);

            var list = new List <int>();

            var sub = left.Concat(right).Subscribe(Observer.Create <ListChange <int> >(change => change.Apply(list)));

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, list);

            left.OnReplace(0, 100);
            right.OnReplace(0, 200);

            CollectionAssert.AreEqual(new[] { 100, 2, 3, 200, 5, 6 }, list);

            left.OnReplace(2, 0);
            right.OnReplace(2, 0);

            CollectionAssert.AreEqual(new[] { 100, 2, 0, 200, 5, 0 }, list);

            sub.Dispose();
        }
예제 #2
0
        public void Completed2()
        {
            var left  = new ListBehaviorSubject <int>();
            var right = new ListBehaviorSubject <int>();

            var list = new List <int>();

            bool completed = false;

            var sub = left.Concat(right)
                      .Subscribe(Observer.Create <ListChange <int> >(change => change.Apply(list), () => completed = true));

            right.OnCompleted();
            Assert.IsFalse(completed);
            left.OnCompleted();
            Assert.IsTrue(completed);
        }