Esempio n. 1
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");
        }
Esempio n. 2
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");
        }
Esempio n. 3
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");
        }
Esempio n. 4
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");
        }
Esempio n. 5
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");
        }
Esempio n. 6
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");
        }
Esempio n. 7
0
        public void PushSimpleError()
        {
            var  errors    = new List <Exception>();
            var  values    = new List <int>();
            bool completed = false;
            var  tmp       = new PushSubject <int>();

            tmp.Subscribe(values.Add, () => completed = true, errors.Add);
            var exception = new Exception();

            tmp.PushException(exception);
            Assert.AreSame(exception, errors[0], "the exception should be retrieved");
            Assert.IsFalse(completed, "shouldn't be completed");
            tmp.PushValue(1);
            Assert.AreEqual(1, values[0], "pushed value should still go in the stream after exception");
        }
Esempio n. 8
0
        public void PushMulipleValues()
        {
            int  nb           = 10;
            var  inputValues  = Enumerable.Range(0, nb).ToList();
            var  outputValues = new List <int>();
            bool completed    = false;
            var  tmp          = new PushSubject <int>();

            tmp.Subscribe(outputValues.Add, () => completed = true);
            foreach (var item in inputValues)
            {
                tmp.PushValue(item);
            }
            for (int i = 0; i < nb; i++)
            {
                Assert.AreEqual(inputValues[i], outputValues[i], "all values should be the same");
            }
            Assert.AreEqual(inputValues.Count, outputValues.Count, "nb items from the input source must be the same that in the output");
            Assert.IsFalse(completed, "shouldn't be completed");
        }