Esempio n. 1
0
        public void ScanValues()
        {
            var  valueStack = new Stack <List <int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;

            var obs = new PushSubject <int>();

            var output = obs.Scan((acc, val) => { acc = acc.ToList(); acc.Add(val); return(acc); }, new List <int>());

            output.Subscribe(valueStack.Push, () => isComplete = true, errorStack.Push);

            for (int size = 0; size < 4; size++)
            {
                obs.PushValue(size);
                Assert.IsTrue(AreListEquals(valueStack.Peek(), size), "the accumulation should be done");

                var ex = new Exception();
                obs.PushException(ex);
                Assert.IsTrue(Object.ReferenceEquals(ex, errorStack.Peek()), "input errors should go in the output stream");
            }
            obs.Complete();
            Assert.IsTrue(isComplete, "the stream must be completed");
        }