Ejemplo n.º 1
0
        public void SimpleJoin2()
        {
            var  valueStack = new Stack <Tuple <int, int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  leftS      = new PushSubject <int>();
            var  rightS     = new PushSubject <int>();

            var output = leftS.LeftJoin(rightS, i => i, i => i, null, (l, r) => new Tuple <int, int>(l, r));

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

            leftS.PushValue(1);
            leftS.Complete();
            Assert.AreEqual(0, valueStack.Count, "no value should be in the output stream yet");
            Assert.IsFalse(isComplete, "as long as nothing is issued on the left whereas the right is not complete and the left has still no match, the stream should not complete");

            rightS.PushValue(1);

            var outElt = valueStack.Peek();

            Assert.AreEqual(1, outElt.Item1, "a joined output should be issued");
            Assert.IsTrue(outElt.Item1 == outElt.Item2, "joined values should match");
            Assert.IsTrue(isComplete, "output stream should be completed");
        }
Ejemplo n.º 2
0
        public void SeveralLeftWaitMatches()
        {
            var  valueStack = new Stack <Tuple <int, int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  leftS      = new PushSubject <int>();
            var  rightS     = new PushSubject <int>();

            var output = leftS.LeftJoin(rightS, i => i, i => i, null, (l, r) => new Tuple <int, int>(l, r));

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

            leftS.PushValue(1);
            leftS.PushValue(1);

            Assert.AreEqual(0, valueStack.Count, "no value should be submitted to the ouput stream");

            rightS.PushValue(1);

            var outValue = valueStack.Pop();

            Assert.AreEqual(1, outValue.Item1, "the out value should match the unmatched input");
            outValue = valueStack.Pop();
            Assert.AreEqual(1, outValue.Item1, "the out value should match the unmatched input");
            Assert.IsFalse(isComplete, "the output stream should not be completed");
        }
        public void SimplePushBeforeTriggerIncluded()
        {
            var  valueStack = new Stack <int>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();

            var output = obs1.TakeUntil(i => i == 0, true);

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

            obs1.PushValue(1);
            Assert.AreEqual(1, valueStack.Peek(), "the input value should be issued");

            var ex = new Exception();

            obs1.PushException(ex);
            Assert.IsTrue(Object.ReferenceEquals(ex, errorStack.Peek()), "the exception should be issued");

            obs1.PushValue(0);
            Assert.AreEqual(0, valueStack.Peek(), "the input value should be issued");

            obs1.PushValue(3);
            Assert.AreEqual(2, valueStack.Count, "the ouput stream should not issue any other value");

            ex = new Exception();
            obs1.PushException(ex);
            Assert.AreEqual(1, errorStack.Count, "the exception should not be issued");

            obs1.Complete();
            Assert.IsTrue(isComplete, "the output stream should be competed");
        }
Ejemplo n.º 4
0
        public void ErrorInMap()
        {
            var outputValues = new Stack <int>();
            var errors       = new Stack <Exception>();
            var completed    = false;
            var obs          = new PushSubject <int>();

            var mapped = obs.Map(i => 10 / i);

            mapped.Subscribe(outputValues.Push, () => completed = true, errors.Push);

            for (int value = -2; value < 0; value++)
            {
                obs.PushValue(value);
                Assert.AreEqual(10 / value, outputValues.Peek(), "the output value should match the map");
                Assert.AreEqual(0, errors.Count, "no error should be submitted");
            }
            obs.PushValue(0);
            Assert.AreEqual(2, outputValues.Count, "no value should be added if error");
            Assert.IsInstanceOfType(errors.Peek(), typeof(DivideByZeroException), "a division by zero should be received in the stream");

            obs.PushValue(1);
            Assert.AreEqual(10 / 1, outputValues.Peek(), "the output value should match the map");
            Assert.AreEqual(1, errors.Count, "no nore error should be submitted");

            obs.Complete();
            Assert.IsTrue(completed, "the stream should be completed");
        }
Ejemplo n.º 5
0
        public void SteppedTest5()
        {
            var left         = new PushSubject <int>();
            var ______right  = new PushSubject <int>();
            var outputValues = new List <int>();

            left.Substract(______right, i => i, i => i).Subscribe(outputValues.Add);

            left.PushValue(1);
            ______right.PushValue(2);
            left.PushValue(2);
            ______right.PushValue(5);
            left.PushValue(2);
            left.PushValue(3);
            left.PushValue(4);
            ______right.PushValue(5);
            left.PushValue(4);
            ______right.PushValue(6);
            left.PushValue(5);
            ______right.Complete();
            left.PushValue(6);
            left.PushValue(7);
            left.PushValue(7);
            left.PushValue(8);
            left.Complete();
            CollectionAssert.AreEquivalent(new[] { 1, 3, 4, 4, 7, 7, 8 }, outputValues.ToArray());
        }
Ejemplo n.º 6
0
        public void FilterValues()
        {
            var inputValues  = new[] { -2, -1, 0, 1, 2 };
            var outputValues = new List <int>();
            var obs          = new PushSubject <int>();
            var filtered     = obs.Filter(i => i > 0);

            filtered.Subscribe(outputValues.Add);

            foreach (var item in inputValues)
            {
                obs.PushValue(item);
            }

            obs.Complete();

            Assert.IsTrue(filtered.ToTaskAsync().Wait(5000), "The filtering should complete");

            var expected = inputValues.Where(i => i > 0).ToList();

            for (int i = 0; i < outputValues.Count; i++)
            {
                Assert.AreEqual(expected[i], outputValues[i], "all values should match");
            }
            Assert.AreEqual(expected.Count, outputValues.Count, $"nb items from the output must match the input one");
        }
Ejemplo n.º 7
0
        public void FilterValues()
        {
            var inputValues  = new IInterface1[] { new MyClass1(), new MyClass2(), new MyClass1(), new MyClass2() };
            var outputValues = new List <MyClass1>();
            var obs          = new PushSubject <IInterface1>();
            var filtered     = obs.OfType <MyClass1>();

            filtered.Subscribe(outputValues.Add);

            foreach (var item in inputValues)
            {
                obs.PushValue(item);
            }

            obs.Complete();

            Assert.IsTrue(filtered.ToTaskAsync().Wait(5000), "The filtering should complete");

            var expected = inputValues.Where(i => i is MyClass1).ToList();

            for (int i = 0; i < outputValues.Count; i++)
            {
                Assert.AreSame(expected[i], outputValues[i], "all values should match");
            }
            Assert.AreEqual(expected.Count, outputValues.Count, $"nb items from the output must match the input one");
        }
Ejemplo n.º 8
0
        public void SteppedTest2()
        {
            var left         = new PushSubject <int>();
            var ______right  = new PushSubject <int>();
            var outputValues = new List <int>();

            left.Substract(______right, i => i, i => i).Subscribe(outputValues.Add);

            left.PushValue(1);        //<-
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(2);        //<-
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(2);        //<-
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(3);        //<-
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            ______right.PushValue(2); //->
            CollectionAssert.AreEquivalent(new int[] { 1 }.ToList(), outputValues);
            ______right.PushValue(5); //->
            CollectionAssert.AreEquivalent(new int[] { 1, 3 }.ToList(), outputValues);
            left.PushValue(4);        //<-
            CollectionAssert.AreEquivalent(new int[] { 1, 3, 4 }.ToList(), outputValues);
            left.PushValue(5);        //<-
            CollectionAssert.AreEquivalent(new int[] { 1, 3, 4 }.ToList(), outputValues);
            left.PushValue(6);        //<-
            CollectionAssert.AreEquivalent(new int[] { 1, 3, 4 }.ToList(), outputValues);
            left.Complete();
            CollectionAssert.AreEquivalent(new int[] { 1, 3, 4 }.ToList(), outputValues);
            ______right.Complete();
            CollectionAssert.AreEquivalent(new int[] { 1, 3, 4, 6 }.ToList(), outputValues);
        }
Ejemplo n.º 9
0
        public void ComplexDistinct1()
        {
            var  valueStack = new Stack <Tuple <int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;

            var obs = new PushSubject <Tuple <int> >();

            var output = obs.Distinct(l => l.Item1);

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

            obs.PushValue(new Tuple <int>(1));
            Assert.AreEqual(1, valueStack.Peek().Item1, "the input value should be issued");

            obs.PushValue(new Tuple <int>(2));
            Assert.AreEqual(2, valueStack.Peek().Item1, "the input value should be issued");

            obs.PushValue(new Tuple <int>(1));
            Assert.AreEqual(2, valueStack.Count, "the input value should not be issued as it has been submitted first");

            obs.PushValue(new Tuple <int>(3));
            Assert.AreEqual(3, valueStack.Peek().Item1, "the input value should be issued");

            obs.PushValue(new Tuple <int>(1));
            Assert.AreEqual(3, valueStack.Count, "the input value should not be issued as it has been submitted first");

            obs.PushValue(new Tuple <int>(2));
            Assert.AreEqual(3, valueStack.Count, "the input value should not be issued as it has been submitted first");

            obs.Complete();
            Assert.IsTrue(isComplete, "the stream should be completed");
        }
Ejemplo n.º 10
0
        public void GetSimpleList()
        {
            var  valueStack = new Stack <List <int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();

            var output = obs1.ToList();

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

            obs1.PushValue(1);
            Assert.AreEqual(0, valueStack.Count, "no value should be submitted");

            obs1.PushValue(2);
            Assert.AreEqual(0, valueStack.Count, "no value should be submitted");

            obs1.Complete();
            Assert.AreEqual(1, valueStack.Count, "one value should be submitted");
            var lst = valueStack.Peek();

            Assert.AreEqual(1, lst[0], "values should be accumulated");
            Assert.AreEqual(2, lst[1], "values should be accumulated");
            Assert.IsTrue(lst.Count == 2, "all values must be exactly in the list");
            Assert.IsTrue(isComplete, "the stream should be completed");
        }
Ejemplo n.º 11
0
        public void DoWithError()
        {
            var  valueStack = new Stack <int>();
            var  doStack    = new Stack <int>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();

            var output = obs1.Do(i => doStack.Push(1 / i));

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

            obs1.PushValue(0);
            Assert.AreEqual(0, valueStack.Peek(), "value should be submitted");
            Assert.AreEqual(0, doStack.Count, "no value should be sent");
            Assert.IsFalse(isComplete, "the stream should not be completed");

            obs1.PushValue(2);
            Assert.AreEqual(2, valueStack.Peek(), "value should be submitted");
            Assert.AreEqual(1 / 2, doStack.Peek(), "value should be submitted");
            Assert.IsFalse(isComplete, "the stream should not be completed");

            Assert.AreEqual(2, valueStack.Count, "no value should be submitted");
            Assert.AreEqual(1, doStack.Count, "no value should be submitted");
        }
Ejemplo n.º 12
0
        public void SimpleJoin()
        {
            var  valueStack = new Stack <Tuple <int, int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  leftS      = new PushSubject <int>();
            var  rightS     = new PushSubject <int>();

            var output = leftS.LeftJoin(rightS, i => i, i => i, null, (l, r) => new Tuple <int, int>(l, r));

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

            leftS.PushValue(1);

            Assert.AreEqual(0, valueStack.Count, "no value should be in the output stream yet");

            rightS.PushValue(1);

            var outElt = valueStack.Peek();

            Assert.AreEqual(1, outElt.Item1, "a joined output should be issued");
            Assert.IsTrue(outElt.Item1 == outElt.Item2, "joined values should match");

            leftS.PushValue(1);

            outElt = valueStack.Peek();
            Assert.AreEqual(2, valueStack.Count, "a joined output should be issued");
            Assert.AreEqual(1, outElt.Item1, "a joined output should be issued");
            Assert.IsTrue(outElt.Item1 == outElt.Item2, "joined values should match");

            rightS.PushValue(2);
            Assert.AreEqual(2, valueStack.Count, "no more output should be issued");

            rightS.PushValue(3);
            Assert.AreEqual(2, valueStack.Count, "no more output should be issued");

            leftS.PushValue(2);

            outElt = valueStack.Peek();
            Assert.AreEqual(3, valueStack.Count, "a joined output should be issued");
            Assert.AreEqual(2, outElt.Item1, "a joined output should be issued");
            Assert.IsTrue(outElt.Item1 == outElt.Item2, "joined values should match");

            leftS.PushValue(2);

            outElt = valueStack.Peek();
            Assert.AreEqual(4, valueStack.Count, "a joined output should be issued");
            Assert.AreEqual(2, outElt.Item1, "a joined output should be issued");
            Assert.IsTrue(outElt.Item1 == outElt.Item2, "joined values should match");

            leftS.PushValue(3);

            outElt = valueStack.Peek();
            Assert.AreEqual(5, valueStack.Count, "a joined output should be issued");
            Assert.AreEqual(3, outElt.Item1, "a joined output should be issued");
            Assert.IsTrue(outElt.Item1 == outElt.Item2, "joined values should match");

            leftS.Complete();
            Assert.IsTrue(isComplete, "output stream should be completed");
        }
Ejemplo n.º 13
0
        public void SimplePushBeforeTriggerExclude()
        {
            var  valueStack = new Stack <int>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();

            var output = obs1.SkipUntil(i => i == 0, false);

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

            obs1.PushValue(1);
            Assert.AreEqual(0, valueStack.Count, "the output stream should not issue any value as long as it's not triggered");

            var ex = new Exception();

            obs1.PushException(ex);
            Assert.AreEqual(0, errorStack.Count, "as the stream is not triggered, no error should be issued");

            obs1.PushValue(0);
            Assert.AreEqual(0, valueStack.Count, "the output stream should not issue any value as long as it's not triggered");

            obs1.PushValue(3);
            Assert.AreEqual(3, valueStack.Peek(), "the ouput stream should issue values as long as the trigger stream issues a value");

            ex = new Exception();
            obs1.PushException(ex);
            Assert.AreEqual(1, errorStack.Count, "as the stream is not triggered, no error should be issued");
            Assert.IsTrue(Object.ReferenceEquals(ex, errorStack.Peek()), "as the stream is triggered, the error should be issued");

            obs1.Complete();
            Assert.IsTrue(isComplete, "the output stream should be competed");
        }
Ejemplo n.º 14
0
        public void ComplexDistinct()
        {
            var  valueStack = new Stack <Tuple <int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;

            var obs = new PushSubject <Tuple <int> >();

            var output = obs.DistinctUntilChanged((l, r) => l.Item1 == r.Item1);

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

            obs.PushValue(new Tuple <int>(1));
            Assert.AreEqual(1, valueStack.Peek().Item1, "the input value should be issued");

            obs.PushValue(new Tuple <int>(2));
            Assert.AreEqual(2, valueStack.Peek().Item1, "the input value should be issued");

            obs.PushValue(new Tuple <int>(1));
            Assert.AreEqual(3, valueStack.Count, "the input value can be issued as long as the previous value is different");
            Assert.AreEqual(1, valueStack.Peek().Item1, "the input value should be issued");

            obs.PushValue(new Tuple <int>(1));
            Assert.AreEqual(3, valueStack.Count, "the input value should not be issued issued again as it is the same");

            obs.PushValue(new Tuple <int>(2));
            Assert.AreEqual(4, valueStack.Count, "the input value can to be issued again as it is not the same than the previous one");
            Assert.AreEqual(2, valueStack.Peek().Item1, "the input value should be issued");

            obs.Complete();
            Assert.IsTrue(isComplete, "the stream should be completed");
        }
Ejemplo n.º 15
0
        public void SimpleMultiMap()
        {
            var  valueStack = new List <string>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs        = new PushSubject <int>();

            var output = obs.MultiMap <int, string>((i, push) =>
            {
                for (int val = 0; val < i; val++)
                {
                    push(val.ToString());
                }
            });

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

            obs.PushValue(0);
            Assert.AreEqual(0, valueStack.Count, "no value should be in the output stream");

            obs.PushValue(1);
            CollectionAssert.AreEquivalent(new[] { "0" }.ToList(), valueStack);

            obs.PushValue(4);
            CollectionAssert.AreEquivalent(new[] { "0", "0", "1", "2", "3" }.ToList(), valueStack);

            obs.Complete();
            Assert.IsTrue(isComplete, "the output stream should be completed");
        }
        public void SimpleErrors()
        {
            var  valueStack = new Stack <Exception>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();

            var output = obs1.ExceptionsToObservable();

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

            var ex = new Exception();

            obs1.PushException(ex);
            Assert.IsTrue(Object.ReferenceEquals(ex, valueStack.Peek()), "exception message should be in the output stream");
            Assert.AreEqual(0, errorStack.Count, "no exception should be in the error output stream");

            ex = new Exception();
            obs1.PushException(ex);
            Assert.IsTrue(Object.ReferenceEquals(ex, valueStack.Peek()), "exception message should be in the output stream");
            Assert.AreEqual(0, errorStack.Count, "no exception should be in the error output stream");

            obs1.Complete();
            Assert.AreEqual(2, valueStack.Count, "no more exception should be in the error output stream");
            Assert.IsTrue(isComplete, "the output stream should be complete");
        }
Ejemplo n.º 17
0
        public void TriggerAfterMainStreamComplete()
        {
            var  valueStack = new Stack <int>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();
            var  obs2       = new PushSubject <int>();

            var output = obs1.SkipUntil(obs2);

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

            obs1.PushValue(1);
            Assert.AreEqual(0, valueStack.Count, "the output stream should not issue any value as long as it's not triggered");

            obs1.Complete();
            Assert.IsTrue(isComplete, "the output stream should be competed");

            obs2.PushValue(1);
            Assert.AreEqual(0, valueStack.Count, "the output stream should not issue any value as long as it's not triggered");

            var ex = new Exception();

            obs1.PushException(ex);
            Assert.AreEqual(0, errorStack.Count, "as the stream is completed, no error should be issued");
        }
Ejemplo n.º 18
0
        public void ExactChunkAmountOfElements()
        {
            var  valueStack = new Stack <IEnumerable <int> >();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs1       = new PushSubject <int>();

            var output = obs1.Chunk(3);

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

            obs1.PushValue(1);
            Assert.AreEqual(0, valueStack.Count(), "the output stream should be empty");
            obs1.PushValue(2);
            Assert.AreEqual(0, valueStack.Count(), "the output stream should be empty");
            obs1.PushValue(3);
            Assert.AreEqual(1, valueStack.Count(), "the output stream should return a chunk of values");
            var value = valueStack.Peek().ToList();

            Assert.AreEqual(3, value.Count, "the chunk of values should be the size of the chunk");

            Assert.AreEqual(1, value[0], "All values must match");
            Assert.AreEqual(2, value[1], "All values must match");
            Assert.AreEqual(3, value[2], "All values must match");

            var ex = new Exception();

            obs1.PushException(ex);
            Assert.IsTrue(Object.ReferenceEquals(ex, errorStack.Peek()), "input errors should go in the output stream");

            obs1.Complete();

            Assert.AreEqual(1, valueStack.Count(), "the output stream should have returned one chunk");
            Assert.IsTrue(isComplete, "the stream should be finished if every input stream is complete");
        }
Ejemplo n.º 19
0
        public void Synchronisation()
        {
            var outputValues = new Stack <int>();
            var errors       = new Stack <Exception>();
            var completed    = false;
            var obs          = new PushSubject <int>();

            var mapped = obs.Filter(i => i > 0);

            mapped.Subscribe(outputValues.Push, () => completed = true, errors.Push);

            obs.PushValue(0);
            Assert.AreEqual(0, outputValues.Count, "no output should be issued");
            Assert.IsFalse(completed, "the stream should not be completed");

            obs.PushValue(10);
            Assert.AreEqual(1, outputValues.Count, "one output should be issued");
            Assert.AreEqual(10, outputValues.Peek(), "issued value should match output");
            Assert.IsFalse(completed, "the stream should not be completed");

            obs.PushValue(11);
            Assert.AreEqual(2, outputValues.Count, "two output should be issued");
            Assert.AreEqual(11, outputValues.Peek(), "issued value should match output");
            Assert.IsFalse(completed, "the stream should not be completed");

            obs.Complete();
            Assert.IsTrue(completed, "the stream should be completed");
        }
Ejemplo n.º 20
0
        public void CompletesFromTopReached()
        {
            var  sub      = new PushSubject <int>();
            bool complete = false;

            sub.Take(1).Subscribe(_ => { }, () => complete = true);
            sub.PushValue(1);
            Assert.IsTrue(complete, "stream must be completed from the moment the top is reached");
        }
Ejemplo n.º 21
0
        public void PushErrorAfterComplete()
        {
            var errors = new List <Exception>();
            var tmp    = new PushSubject <int>();

            tmp.Subscribe(_ => { }, () => { }, errors.Add);
            tmp.Complete();
            tmp.PushException(new Exception());
            Assert.AreEqual(0, errors.Count, "pushed errors should not be streamed");
        }
Ejemplo n.º 22
0
        public void PushValueAfterComplete()
        {
            var values = new List <int>();
            var tmp    = new PushSubject <int>();

            tmp.Subscribe(values.Add);
            tmp.Complete();
            tmp.PushValue(1);
            Assert.AreEqual(0, values.Count, "pushed value should not be streamed");
        }
Ejemplo n.º 23
0
        public void PushSimpleValue()
        {
            var  values    = new List <int>();
            bool completed = false;
            var  tmp       = new PushSubject <int>();

            tmp.Subscribe(values.Add, () => completed = true);
            tmp.PushValue(1);
            Assert.AreEqual(1, values[0], "pushed value doesn't match");
            Assert.IsFalse(completed, "shouldn't be completed");
        }
Ejemplo n.º 24
0
        public void WaitEndWitoutComplete()
        {
            bool completed = false;
            var  tmp       = new PushSubject <int>();

            tmp.Subscribe((_) => { }, () => completed = true);
            var returnedTask = tmp.ToTaskAsync();

            Assert.IsFalse(returnedTask.IsCompleted, "The task shouldn't be completed");
            Assert.IsFalse(returnedTask.Wait(1000), "The task should not complete");
            Assert.IsFalse(completed, "complete should not be triggered");
        }
Ejemplo n.º 25
0
        public void PushCompleted()
        {
            bool valueSubmitted = false;
            bool completed      = false;
            var  tmp            = new PushSubject <int>();

            tmp.Subscribe(i => valueSubmitted = true, () => completed = true);
            tmp.Complete();
            Assert.IsTrue(completed, "stream should be completed");
            tmp.PushValue(1);
            Assert.IsFalse(valueSubmitted, "no more value should be submitted to the output stream");
        }
Ejemplo n.º 26
0
        public void SteppedTest1()
        {
            var left         = new PushSubject <int>();
            var right        = new PushSubject <int>();
            var outputValues = new List <int>();

            left.Substract(right, i => i, i => i).Subscribe(outputValues.Add);

            left.PushValue(1);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            right.PushValue(2);
            CollectionAssert.AreEquivalent(new int[] { 1 }.ToList(), outputValues);
        }
Ejemplo n.º 27
0
        public void SplitEmptyObservables1()
        {
            var  lastValues  = new List <int>();
            bool isCompleted = false;
            // var lastValues=new List<KeyValuePair<int, int>>();
            IPushSubject <KeyValuePair <int, int> > src = new PushSubject <KeyValuePair <int, int> >();
            var resS = src.Group(i => i.Key, iS => iS.Map(i => i.Value).Last());

            resS.Subscribe(i => lastValues.Add(i), () => isCompleted = true);

            src.Complete();
            CollectionAssert.AreEquivalent(new int[0], lastValues);
            Assert.IsTrue(isCompleted);
        }
Ejemplo n.º 28
0
        public void PushSimpleError()
        {
            var errors = new List <Exception>();
            var values = new List <int>();
            var tmp    = new PushSubject <int>();

            tmp.Subscribe(values.Add, () => { }, errors.Add);
            var task      = tmp.CompletesOnException(errors.Add).ToTaskAsync();
            var exception = new Exception();

            tmp.PushException(exception);
            Assert.AreSame(exception, errors[0], "the exception should be retrieved");
            Assert.IsTrue(task.Wait(5000), "the stream should be completed");
        }
Ejemplo n.º 29
0
        public void PushValuesAfterComplete()
        {
            var  valueStack = new Stack <int>();
            var  errorStack = new Stack <Exception>();
            bool isComplete = false;
            var  obs        = new PushSubject <int>();
            var  sobs       = new[] { new PushSubject <int>(), new PushSubject <int>() };

            var output = obs.FlatMap(i => sobs[i]);

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

            obs.PushValue(0);
            Assert.AreEqual(0, valueStack.Count, "no value should be in the output stream");

            sobs[0].PushValue(1);
            Assert.AreEqual(1, valueStack.Peek(), "values from the input streams should be in the output stream");

            sobs[1].PushValue(2);
            Assert.AreEqual(1, valueStack.Count, "values from the input streams that are not used should not be in the output stream");

            var ex = new Exception();

            sobs[0].PushException(ex);
            Assert.IsTrue(Object.ReferenceEquals(ex, errorStack.Peek()), "errors from the input streams should be in the output stream");

            obs.PushValue(1);
            Assert.AreEqual(1, valueStack.Count, "no more values from the input streams should be in the output stream");

            sobs[0].PushValue(3);
            Assert.AreEqual(3, valueStack.Peek(), "values from the input streams should be in the output stream");

            sobs[1].PushValue(4);
            Assert.AreEqual(4, valueStack.Peek(), "values from the input streams should be in the output stream");

            obs.Complete();
            Assert.IsFalse(isComplete, "the output stream should not be completed unless its sub stream are completed");

            sobs[0].PushValue(5);
            Assert.AreEqual(5, valueStack.Peek(), "values from the input streams should be in the output stream");

            sobs[0].Complete();
            Assert.IsFalse(isComplete, "the output stream should not be completed unless its sub stream are completed");

            sobs[1].PushValue(6);
            Assert.AreEqual(6, valueStack.Peek(), "values from the input streams should be in the output stream");

            sobs[1].Complete();
            Assert.IsTrue(isComplete, "the output stream should be completed if the source is complete and its sub stream are completed");
        }
Ejemplo n.º 30
0
        public void SteppedTest4()
        {
            var left         = new PushSubject <int>();
            var ______right  = new PushSubject <int>();
            var outputValues = new List <int>();

            left.Substract(______right, i => i, i => i).Subscribe(outputValues.Add);

            left.PushValue(2);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            ______right.PushValue(0);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(2);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            ______right.PushValue(2);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(4);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(4);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            ______right.PushValue(3);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            left.PushValue(5);
            CollectionAssert.AreEquivalent(new int[] { }.ToList(), outputValues);
            ______right.PushValue(6);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5 }.ToList(), outputValues);
            left.PushValue(5);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            ______right.PushValue(6);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            ______right.PushValue(7);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            left.PushValue(8);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            ______right.PushValue(7);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            ______right.PushValue(8);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            left.PushValue(9);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            left.PushValue(9);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            ______right.PushValue(9);
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            left.Complete();
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
            ______right.Complete();
            CollectionAssert.AreEquivalent(new int[] { 4, 4, 5, 5 }.ToList(), outputValues);
        }