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"); }
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"); }
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"); }
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"); }
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"); }
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); }
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"); }
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"); }
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 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()); }
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"); }
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"); }
public void RightCompletesBeforeLeftGetsMatches() { 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 submitted to the ouput stream"); rightS.Complete(); var outValue = valueStack.Peek(); Assert.AreEqual(1, valueStack.Count, "a value should be submitted to the ouput stream"); Assert.AreEqual(1, outValue.Item1, "the out value should match the unmatched input"); Assert.AreEqual(0, outValue.Item2, "the unmatched output should have no linked references"); Assert.IsFalse(isComplete, "the output stream should not be completed"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
public void WaitEnd() { 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"); tmp.Complete(); Assert.IsTrue(returnedTask.Wait(5000), "The task should complete"); Assert.IsTrue(completed, "complete should be triggered"); }
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"); }
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); }
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); }
public void SplitObservables2() { 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.Scan((acc, val) => acc + val.Value, 0)); resS.Subscribe(i => lastValues.Add(i), () => isCompleted = true); src.PushValue(new KeyValuePair <int, int>(1, 1)); src.Complete(); CollectionAssert.AreEquivalent(new[] { 1 }, lastValues); Assert.IsTrue(isCompleted); }
public void GetLastForEmptyStream() { var valueStack = new Stack <int>(); var errorStack = new Stack <Exception>(); bool isComplete = false; var obs1 = new PushSubject <int>(); var output = obs1.Last(); output.Subscribe(valueStack.Push, () => isComplete = true, errorStack.Push); obs1.Complete(); Assert.AreEqual(0, valueStack.Count, "no value should be submitted"); Assert.IsTrue(isComplete, "the stream should be completed"); }
public void NoElements() { 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.Complete(); Assert.AreEqual(0, valueStack.Count(), "the output stream should be empty"); Assert.IsTrue(isComplete, "the stream should be finished if every input stream is complete"); }
public void TriggerStreamCompletesBeforeMainStreamIsTriggered() { 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"); obs2.Complete(); Assert.IsTrue(isComplete, "the output stream should be completed as it cannot be triggered anymore"); }
public void GetListForEmptyStream() { 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.Complete(); Assert.AreEqual(1, valueStack.Count, "no value should be submitted"); var lst = valueStack.Peek(); Assert.IsTrue(lst.Count == 0, "all values must be exactly in the list"); Assert.IsTrue(isComplete, "the stream should be completed"); }