public void All_Success()
        {
            var success        = 0;
            var afterSuccess   = 0;
            var completed      = 0;
            var error          = 0;
            var terminate      = 0;
            var afterterminate = 0;
            var subscribe      = 0;
            var dispose        = 0;
            var final          = 0;

            MaybeSource.Just(1)
            .DoOnSuccess(v => success++)
            .DoAfterSuccess(v => afterSuccess++)
            .DoOnCompleted(() => completed++)
            .DoOnError(e => error++)
            .DoOnTerminate(() => terminate++)
            .DoAfterTerminate(() => afterterminate++)
            .DoOnSubscribe(d => subscribe++)
            .DoOnDispose(() => dispose++)
            .DoFinally(() => final++)
            .Test()
            .AssertResult(1);

            Assert.AreEqual(1, success);
            Assert.AreEqual(1, afterSuccess);
            Assert.AreEqual(0, completed);
            Assert.AreEqual(0, error);
            Assert.AreEqual(1, terminate);
            Assert.AreEqual(1, afterterminate);
            Assert.AreEqual(1, subscribe);
            Assert.AreEqual(0, dispose);
            Assert.AreEqual(1, final);
        }
Beispiel #2
0
 public void Maybe_Success()
 {
     MaybeSource.Just(1)
     .IgnoreElement()
     .Test()
     .AssertResult();
 }
Beispiel #3
0
        public void Mapper_Crash_DelayErrors()
        {
            var subj = new Subject <int>();

            var to = subj
                     .ConcatMap(v => {
                if (v == 3)
                {
                    throw new InvalidOperationException();
                }
                return(MaybeSource.Just(v + 1));
            }, true)
                     .Test();

            subj.OnNext(1);

            Assert.True(subj.HasObservers);

            subj.OnNext(2);

            Assert.True(subj.HasObservers);

            subj.OnNext(3);

            Assert.False(subj.HasObservers);

            to
            .AssertFailure(typeof(InvalidOperationException), 2, 3);
        }
 public void Maybe_Basic()
 {
     CompletableSource.Empty()
     .AndThen(MaybeSource.Just(1))
     .Test()
     .AssertResult(1);
 }
Beispiel #5
0
 public void Delayed_Basic()
 {
     Observable.Range(1, 5)
     .SwitchMap(v => MaybeSource.Just(v + 1), true)
     .Test()
     .AssertResult(2, 3, 4, 5, 6);
 }
Beispiel #6
0
 public void Maybes_Success()
 {
     MaybeSource.Just(1)
     .SwitchIfEmpty(MaybeSource.Empty <int>(), MaybeSource.Just(2))
     .Test()
     .AssertResult(1);
 }
Beispiel #7
0
 public void Success()
 {
     MaybeSource.Just(1)
     .OnErrorComplete()
     .Test()
     .AssertResult(1);
 }
 public void Handler_Success()
 {
     MaybeSource.Just(1)
     .Retry((e, i) => true)
     .Test()
     .AssertResult(1);
 }
 public void Times_Success()
 {
     MaybeSource.Just(1)
     .Retry()
     .Test()
     .AssertResult(1);
 }
Beispiel #10
0
        public void Enumerable_Limit_Error()
        {
            for (int i = 1; i < 10; i++)
            {
                var to = new List <IMaybeSource <int> >()
                {
                    MaybeSource.Just(1),
                    MaybeSource.Empty <int>(),
                    MaybeSource.Error <int>(new InvalidOperationException())
                }
                .ConcatEager(maxConcurrency: i)
                .Test()
                .WithTag($"maxConcurrency={i}");

                if (i >= 3)
                {
                    // error cuts ahead
                    to.AssertFailure(typeof(InvalidOperationException));
                }
                else
                {
                    to.AssertFailure(typeof(InvalidOperationException), 1);
                }
            }
        }
Beispiel #11
0
        public void Enumerable_Limit_Error_Stop()
        {
            for (int i = 1; i < 10; i++)
            {
                var count = 0;

                var src = MaybeSource.FromFunc(() => ++ count);

                var to = new List <IMaybeSource <int> >()
                {
                    MaybeSource.Just(1),
                    MaybeSource.Error <int>(new InvalidOperationException()),
                    src
                }
                .ConcatEager(maxConcurrency: i)
                .Test();

                if (i >= 2)
                {
                    to.AssertFailure(typeof(InvalidOperationException));
                }
                else
                {
                    to.AssertFailure(typeof(InvalidOperationException), 1);
                }

                Assert.AreEqual(0, count);
            }
        }
Beispiel #12
0
        public void Array_Limit_Null()
        {
            for (int i = 1; i < 10; i++)
            {
                var to = new IMaybeSource <int>[]
                {
                    MaybeSource.Just(1),
                    MaybeSource.Empty <int>(),
                    null
                }
                .ConcatEagerAll(maxConcurrency: i)
                .Test()
                .WithTag($"maxConcurrency={i}");

                if (i >= 3)
                {
                    // error cuts ahead
                    to.AssertFailure(typeof(NullReferenceException));
                }
                else
                {
                    to.AssertFailure(typeof(NullReferenceException), 1);
                }
            }
        }
Beispiel #13
0
 public void Basic_Filtered()
 {
     MaybeSource.Just(1)
     .Filter(v => false)
     .Test()
     .AssertResult();
 }
Beispiel #14
0
 public void Basic()
 {
     MaybeSource.Just(1)
     .Filter(v => true)
     .Test()
     .AssertResult(1);
 }
Beispiel #15
0
 public void Maybes_Fallback_Error()
 {
     MaybeSource.Empty <int>()
     .SwitchIfEmpty(MaybeSource.Error <int>(new InvalidOperationException()), MaybeSource.Just(2))
     .Test()
     .AssertError(typeof(InvalidOperationException));
 }
Beispiel #16
0
 public void Success_To_Just()
 {
     MaybeSource.Just(1)
     .FlatMap(v => Enumerable.Range(v, 1))
     .Test()
     .AssertResult(1);
 }
Beispiel #17
0
 public void Single_Success()
 {
     MaybeSource.Just(1)
     .SwitchIfEmpty(SingleSource.Just(2))
     .Test()
     .AssertResult(1);
 }
        public void Success()
        {
            ISingleSource <int> src = MaybeSource.Just(1)
                                      .ToSingle();

            src.Test().AssertResult(1);
        }
Beispiel #19
0
 public void Maybes_Fallback()
 {
     MaybeSource.Empty <int>()
     .SwitchIfEmpty(MaybeSource.Empty <int>(), MaybeSource.Just(2))
     .Test()
     .AssertResult(2);
 }
 public void Maybe_Error_Inner()
 {
     MaybeSource.Just(1)
     .FlatMap(v => MaybeSource.Error <int>(new InvalidOperationException()))
     .Test()
     .AssertFailure(typeof(InvalidOperationException));
 }
Beispiel #21
0
 public void Maybe_Basic()
 {
     SingleSource.Just(1)
     .FlatMap(v => MaybeSource.Just("" + (v + 1)))
     .Test()
     .AssertResult("2");
 }
 public void Success()
 {
     MaybeSource.Just(1)
     .DefaultIfEmpty(2)
     .Test()
     .AssertResult(1);
 }
 public void Maybe_Main_Error()
 {
     CompletableSource.Error(new InvalidOperationException())
     .AndThen(MaybeSource.Just(1))
     .Test()
     .AssertFailure(typeof(InvalidOperationException));
 }
Beispiel #24
0
 public void Success_To_Empty()
 {
     MaybeSource.Just(1)
     .FlatMap(v => Observable.Empty <int>())
     .Test()
     .AssertResult();
 }
Beispiel #25
0
        public void Eager_Mapper_Crash()
        {
            var subj = new Subject <int>();

            var to = subj
                     .SwitchMap(v => {
                if (v == 3)
                {
                    throw new InvalidOperationException();
                }
                return(MaybeSource.Just(v + 1));
            })
                     .Test();

            subj.OnNext(1);

            to.AssertValuesOnly(2);

            subj.OnNext(2);

            to.AssertValuesOnly(2, 3);

            subj.OnNext(3);

            Assert.False(subj.HasObservers);

            to
            .AssertFailure(typeof(InvalidOperationException), 2, 3);
        }
Beispiel #26
0
 public void Success_To_Range()
 {
     MaybeSource.Just(1)
     .FlatMap(v => Observable.Range(v, 5))
     .Test()
     .AssertResult(1, 2, 3, 4, 5);
 }
Beispiel #27
0
 public void Basic()
 {
     Observable.Range(1, 5)
     .ConcatMap(v => MaybeSource.Just(v + 1))
     .Test()
     .AssertResult(2, 3, 4, 5, 6);
 }
Beispiel #28
0
 public void Error_Other()
 {
     MaybeSource.Just(1)
     .FlatMap(v => Observable.Throw <int>(new InvalidOperationException()))
     .Test()
     .AssertFailure(typeof(InvalidOperationException));
 }
Beispiel #29
0
 public void Basic_Main_Error()
 {
     Observable.Range(1, 5).ConcatError(new InvalidOperationException())
     .ConcatMap(v => MaybeSource.Just(v + 1))
     .Test()
     .AssertFailure(typeof(InvalidOperationException), 2, 3, 4, 5, 6);
 }
Beispiel #30
0
 public void Mapper_Crash()
 {
     MaybeSource.Just(1)
     .Map <int, string>(v => { throw new InvalidOperationException(); })
     .Test()
     .AssertFailure(typeof(InvalidOperationException));
 }