Exemplo n.º 1
0
            public void ReturnsFalseWhileExecuting()
            {
                var testScheduler = new TestScheduler();
                var observer      = testScheduler.CreateObserver <bool>();
                var observable    = testScheduler.CreateColdObservable(
                    OnNext(10, "1"),
                    OnNext(20, "2"),
                    OnCompleted <string>(30)
                    );

                var action = new RxAction <Unit, string>(_ => observable, testScheduler);

                action.Enabled.Subscribe(observer);

                testScheduler.Schedule(TimeSpan.FromTicks(300), () =>
                {
                    action.Execute(Unit.Default);
                });
                testScheduler.Start();

                observer.Messages.AssertEqual(
                    OnNext(0, true),
                    OnNext(300, false),
                    OnNext(331, true)
                    );
            }
Exemplo n.º 2
0
            public void ForwardsErrorsInTheExecution()
            {
                var testScheduler = new TestScheduler();
                var exception     = new Exception("This is an error");

                var action = new RxAction <int, string>(
                    i => Observable.Throw <string>(exception)
                    );

                var observer = testScheduler.CreateObserver <Exception>();

                action.Errors.Subscribe(observer);

                testScheduler.Sleep(3);
                action.Execute(2);
                testScheduler.Start();

                observer.Messages.AssertEqual(
                    OnNext(3, exception)
                    );
            }
Exemplo n.º 3
0
            public void ReturnsTheResultsOfTheOperation()
            {
                var testScheduler = new TestScheduler();
                var observer      = testScheduler.CreateObserver <string>();
                var observable    = testScheduler.CreateColdObservable(
                    OnNext(10, "0"),
                    OnNext(20, "1"),
                    OnCompleted <string>(30)
                    );

                var action = new RxAction <Unit, string>(_ => observable, testScheduler);

                testScheduler.Schedule(TimeSpan.FromTicks(300), () => action.Execute(Unit.Default).Subscribe(observer));
                testScheduler.Start();

                observer.Messages.AssertEqual(
                    OnNext(311, "0"),
                    OnNext(321, "1"),
                    OnCompleted <string>(331)
                    );
            }
Exemplo n.º 4
0
            public void ForwardsErrorsInTheExecution()
            {
                var testScheduler = new TestScheduler();
                var exception     = new Exception("This is an error");

                var observable = testScheduler.CreateColdObservable(
                    OnError <string>(10, exception)
                    );

                var action = new RxAction <Unit, string>(_ => observable, testScheduler);

                var observer = testScheduler.CreateObserver <Exception>();

                action.Errors.Subscribe(observer);

                testScheduler.Schedule(TimeSpan.FromTicks(300), () => action.Execute(Unit.Default));
                testScheduler.Start();

                observer.Messages.AssertEqual(
                    OnNext(311, exception)
                    );
            }
Exemplo n.º 5
0
            public void ReturnsTheResultsOfTheOperation()
            {
                var testScheduler = new TestScheduler();

                var action = new RxAction <int, string>(
                    i => Observable.Interval(TimeSpan.FromTicks(1), testScheduler)
                    .Take(i)
                    .Select(l => l.ToString())
                    );

                var observer = testScheduler.CreateObserver <string>();

                testScheduler.Sleep(3);
                action.Execute(2).Subscribe(observer);
                testScheduler.Start();

                observer.Messages.AssertEqual(
                    OnNext(4, "0"),
                    OnNext(5, "1"),
                    OnCompleted <string>(5)
                    );
            }
Exemplo n.º 6
0
            public void ReturnsFalseWhileExecuting()
            {
                var testScheduler = new TestScheduler();

                var action = new RxAction <int, string>(
                    i => Observable.Interval(TimeSpan.FromTicks(1), testScheduler)
                    .Take(i)
                    .Select(l => l.ToString())
                    );

                var observer = testScheduler.CreateObserver <bool>();

                action.Enabled.Subscribe(observer);

                testScheduler.Sleep(3);
                action.Execute(2);
                testScheduler.Start();

                observer.Messages.AssertEqual(
                    OnNext(0, true),
                    OnNext(3, false),
                    OnNext(5, true)
                    );
            }