public void Mapper_Crash()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.CombineLatest(a =>
            {
                int v = 0;
                foreach (var e in a)
                {
                    v += e;
                }
                if (v == 22)
                {
                    throw new InvalidOperationException();
                }
                return(v);
            }, us1, us2).Test();

            to.AssertEmpty();

            us1.OnNext(1);
            us2.OnNext(10);

            us1.OnNext(2);
            us2.OnNext(20);

            Assert.False(us1.HasObserver());
            Assert.False(us2.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException), 11, 12);
        }
Beispiel #2
0
        public void OnNext_OnError_Race()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var to = new TestObserver <int>();

                var s = ReactiveExtensions.ToSerialized(to);

                var ex = new InvalidOperationException();

                Action emit = () => {
                    for (int j = 0; j < 500; j++)
                    {
                        s.OnNext(j);
                    }
                };

                Action complete = () =>
                {
                    for (int j = 0; j < 250; j++)
                    {
                        s.OnNext(j);
                    }

                    s.OnError(ex);
                };

                TestHelper.Race(emit, complete);

                Assert.True(to.ItemCount >= 250);

                to.AssertError(typeof(InvalidOperationException))
                .AssertNotCompleted();
            }
        }
        public void Error_Delayed()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.CombineLatest(a =>
            {
                int v = 0;
                foreach (var e in a)
                {
                    v += e;
                }
                return(v);
            }, true, us1, us2).Test();

            to.AssertEmpty();

            us1.OnNext(1);
            us1.OnError(new InvalidOperationException());

            Assert.True(us2.HasObserver());

            us2.EmitAll(10, 20, 30, 40, 50);

            to.AssertFailure(typeof(InvalidOperationException), 11, 21, 31, 41, 51);
        }
Beispiel #4
0
        public void Error_Delayed()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.Zip(a =>
            {
                int s = 0;
                foreach (var v in a)
                {
                    s += v;
                }
                return(s);
            }, true,
                                            us1,
                                            us2
                                            ).Test();

            us1.EmitError(new InvalidOperationException(), 1, 2, 3);

            Assert.True(us2.HasObserver(), "us2: No observers!");

            us2.Emit(10, 20, 30, 40);

            Assert.False(us2.HasObserver(), "us2: Observers present!");

            to.AssertFailure(typeof(InvalidOperationException), 11, 22, 33);
        }
        public void No_Combinations_Complete_After_All()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.CombineLatest(a =>
            {
                int v = 0;
                foreach (var e in a)
                {
                    v += e;
                }
                return(v);
            }, us1, us2).Test();

            to.AssertEmpty();

            us1.OnCompleted();

            Assert.True(us2.HasObserver(), "Other source disposed?");

            us2.EmitAll(1, 2, 3, 4, 5);

            to.AssertResult();
        }
Beispiel #6
0
        public void Mapper_Crashes()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.Zip(a =>
            {
                int s = 0;
                foreach (var v in a)
                {
                    s += v;
                }

                if (s == 33)
                {
                    throw new InvalidOperationException();
                }
                return(s);
            },
                                            us1,
                                            us2
                                            ).Test();

            us1.Emit(1, 2, 3);

            Assert.True(us1.HasObserver());
            Assert.True(us2.HasObserver());

            us2.Emit(10, 20, 30, 40);

            Assert.False(us1.HasObserver());
            Assert.False(us2.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException), 11, 22);
        }
        public void ObserveCommand_should_register_a_delegate_command_handler()
        {
            Mock <IBusBuilder> mockBusBuilder = new Mock <IBusBuilder>();

            var observable = ReactiveExtensions.ObserveCommand <TestCommand>(mockBusBuilder.Object);

            mockBusBuilder.Verify(p => p.SubscribeToCommand(It.IsAny <Func <CommandContext <TestCommand>, Task> >()), Times.Once);
        }
        public void ObserveEvent_should_register_a_delegate_event_handler()
        {
            Mock <IBusBuilder> mockBusBuilder = new Mock <IBusBuilder>();

            var observable = ReactiveExtensions.ObserveEvent <TestEvent>(mockBusBuilder.Object);

            mockBusBuilder.Verify(p => p.SubscribeToEvent(It.IsAny <Func <EventContext <TestEvent>, Task> >()), Times.Once);
        }
Beispiel #9
0
        public void Basic_With_Error()
        {
            var up = new UnicastSubject <int>();

            var to = new TestObserver <int>();

            up.Subscribe(ReactiveExtensions.ToSerialized(to));

            up.EmitError(new InvalidOperationException(), 1, 2, 3, 4, 5);

            to.AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);
        }
Beispiel #10
0
        public void Basic()
        {
            var up = new UnicastSubject <int>();

            var to = new TestObserver <int>();

            up.Subscribe(ReactiveExtensions.ToSerialized(to));

            up.EmitAll(1, 2, 3, 4, 5);

            to.AssertResult(1, 2, 3, 4, 5);
        }
        public override void Execute(object parameter)
        {
            SearchForIssuesDialog dlg = new SearchForIssuesDialog();

            dlg.Owner = SD.Workbench.MainWindow;
            if (dlg.ShowDialog() == true)
            {
                string title     = "Issue Search";
                var    providers = dlg.SelectedProviders.ToList();
                var    fileNames = GetFilesToSearch(dlg.Target).ToList();
                if (dlg.FixIssues)
                {
                    int fixedIssueCount = 0;
                    IReadOnlyList <SearchResultMatch> remainingIssues = null;
                    AsynchronousWaitDialog.RunInCancellableWaitDialog(
                        title, null,
                        monitor => {
                        remainingIssues = FindAndFixIssues(fileNames, providers, monitor, out fixedIssueCount);
                    });
                    if (remainingIssues == null)
                    {
                        return;                         // can happen if issue search is cancelled
                    }
                    string message = string.Format(
                        "{0} issues were fixed automatically." +
                        "{1} issues are remaining (no automatic fix available).",
                        fixedIssueCount, remainingIssues.Count);
                    SearchResultsPad.Instance.ShowSearchResults(title, remainingIssues);
                    MessageService.ShowMessage(message, title);
                }
                else if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift))
                {
                    // Ctrl+Alt+Shift => run issue search on main thread,
                    // this helps debugging as exceptions don't get caught and passed from one thread to another
                    List <SearchResultMatch> issues = new List <SearchResultMatch>();
                    AsynchronousWaitDialog.RunInCancellableWaitDialog(
                        title, null,
                        monitor => SearchForIssues(fileNames, providers, f => issues.AddRange(f.Matches), monitor)
                        );
                    SearchResultsPad.Instance.ShowSearchResults(title, issues);
                }
                else
                {
                    var monitor    = SD.StatusBar.CreateProgressMonitor();
                    var observable = ReactiveExtensions.CreateObservable <SearchedFile>(
                        (m, c) => SearchForIssuesAsync(fileNames, providers, c, m),
                        monitor);
                    SearchResultsPad.Instance.ShowSearchResults(title, observable);
                }
            }
        }
        public void Disposed_Serialized()
        {
            var sad = new SingleAssignmentDisposable();

            ReactiveExtensions.Create <int>(emitter =>
            {
                emitter.SetResource(sad);
            }, true)
            .Test()
            .Cancel()
            .AssertEmpty();

            Assert.True(sad.IsDisposed());
        }
Beispiel #13
0
        public DragPanel()
        {
            CanBeFocused = false;

            // Update layout when the width or height is changed.
            ReactiveExtensions.MergeEvents(
                WidthChanged,
                HeightChanged
                ).Subscribe(_ => UpdateLayout());

            // Update layout when a child changes its preferred width or height.
            ReactiveExtensions.MergeEvents(
                Children.ObserveEach(child => child.PreferredWidthChanged),
                Children.ObserveEach(child => child.PreferredHeightChanged)
                ).Subscribe(_ => UpdateLayout());

            Children.ObserveEach(c => c.MouseEventOccured).Subscribe(e =>
            {
                if (e.Value.Id == MouseEvent.MOUSE_PRESSED)
                {
                    // Start drag
                    StartDrag(e.Element, e.Element.TranslatePointTo(this, e.Value.MousePosition));
                }
                else if (e.Value.Id == MouseEvent.MOUSE_DRAGGED)
                {
                    // Apply drag
                    var mousePosition = e.Element.TranslatePointTo(this, e.Value.MousePosition);
                    double deltaX     = mousePosition.X - _previousCursorPosition.X;
                    double deltaY     = mousePosition.Y - _previousCursorPosition.Y;
                    ApplyDrag(e.Element, deltaX, deltaY);
                    _previousCursorPosition = mousePosition;

                    e.Value.IsHandled = true;
                }
                else if (e.Value.Id == MouseEvent.MOUSE_RELEASED)
                {
                    if (_childBeingDragged != null)
                    {
                        // Finish drag
                        _childBeingDragged.ReleaseMouseAtRoot();
                        _onDragFinished.OnNext(_childBeingDragged);
                        _childBeingDragged = null;

                        e.Value.IsHandled = true;
                    }
                }
            });
        }
Beispiel #14
0
 public void Second_Shorter()
 {
     ReactiveExtensions.Zip(a =>
     {
         int s = 0;
         foreach (var v in a)
         {
             s += v;
         }
         return(s);
     },
                            Observable.Range(1, 5),
                            Observable.Range(10, 4)
                            ).Test()
     .AssertResult(10 + 1, 11 + 2, 12 + 3, 13 + 4);
 }
Beispiel #15
0
 public void Basic_DelayErrors()
 {
     ReactiveExtensions.Zip(a =>
     {
         int s = 0;
         foreach (var v in a)
         {
             s += v;
         }
         return(s);
     }, true,
                            Observable.Range(1, 5),
                            Observable.Range(10, 5)
                            ).Test()
     .AssertResult(10 + 1, 11 + 2, 12 + 3, 13 + 4, 14 + 5);
 }
        public void Basic()
        {
            var ts = new TestScheduler();

            var to = ReactiveExtensions
                     .IntervalRange(0, 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), ts)
                     .Test();

            to.AssertEmpty();

            ts.RunAll();

            to.AssertResult(0, 1, 2, 3, 4);

            Assert.False(ts.HasTasks());
        }
        public void Race()
        {
            for (int j = 0; j < TestHelper.RACE_LOOPS; j++)
            {
                var sad = new SingleAssignmentDisposable();

                var to = ReactiveExtensions.Create <int>(emitter =>
                {
                    emitter.SetResource(sad);

                    TestHelper.Race(() =>
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            if (emitter.IsDisposed())
                            {
                                return;
                            }
                            emitter.OnNext(i);
                        }
                        emitter.OnCompleted();
                    },
                                    () =>
                    {
                        for (int i = 1000; i < 2000; i++)
                        {
                            if (emitter.IsDisposed())
                            {
                                return;
                            }
                            emitter.OnNext(i);
                        }
                        emitter.OnCompleted();
                    });
                }, true)
                         .Test()
                ;

                Assert.True(to.ItemCount >= 500, "" + to.ItemCount);
                to.AssertCompleted()
                .AssertNoError();

                Assert.True(sad.IsDisposed());
            }
        }
        public void Basic()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.CombineLatest(a =>
            {
                int v = 0;
                foreach (var e in a)
                {
                    v += e;
                }
                return(v);
            }, us1, us2).Test();

            to.AssertEmpty();

            us1.OnNext(1);

            to.AssertEmpty();

            us1.OnNext(2);

            to.AssertEmpty();

            us2.OnNext(10);

            to.AssertValuesOnly(12);

            us2.OnNext(20);

            to.AssertValuesOnly(12, 22);

            us2.OnCompleted();

            to.AssertValuesOnly(12, 22);

            us1.OnNext(3);

            to.AssertValuesOnly(12, 22, 23);

            us1.OnCompleted();

            to.AssertResult(12, 22, 23);
        }
        public void Handler_Crash()
        {
            var sad = new SingleAssignmentDisposable();

            ReactiveExtensions.Create <int>(emitter =>
            {
                emitter.SetResource(sad);

                for (int i = 1; i < 6; i++)
                {
                    emitter.OnNext(i);
                }
                throw new InvalidOperationException();
            })
            .Test()
            .AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4, 5);

            Assert.True(sad.IsDisposed());
        }
        public void Basic_Serialized()
        {
            var sad = new SingleAssignmentDisposable();

            ReactiveExtensions.Create <int>(emitter =>
            {
                emitter.SetResource(sad);

                for (int i = 1; i < 6; i++)
                {
                    emitter.OnNext(i);
                }
                emitter.OnCompleted();
            }, true)
            .Test()
            .AssertResult(1, 2, 3, 4, 5);

            Assert.True(sad.IsDisposed());
        }
Beispiel #21
0
        public void OnNext_Race()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var to = new TestObserver <int>();

                var s = ReactiveExtensions.ToSerialized(to);

                Action emit = () => {
                    for (int j = 0; j < 500; j++)
                    {
                        s.OnNext(j);
                    }
                };

                TestHelper.Race(emit, emit);

                to.AssertValueCount(1000);
            }
        }
        public void Basic_Single_Step()
        {
            var ts = new TestScheduler();

            var to = ReactiveExtensions
                     .IntervalRange(0, 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), ts)
                     .Test();

            to.AssertEmpty();

            ts.AdvanceTimeBy(500);

            to.AssertEmpty();

            ts.AdvanceTimeBy(TimeSpan.FromMilliseconds(500));

            to.AssertValuesOnly(0);

            ts.AdvanceTimeBy(TimeSpan.FromMilliseconds(1000));

            to.AssertValuesOnly(0);

            ts.AdvanceTimeBy(TimeSpan.FromMilliseconds(2000));

            to.AssertValuesOnly(0, 1);

            ts.AdvanceTimeBy(2000);

            to.AssertValuesOnly(0, 1, 2);

            ts.AdvanceTimeBy(TimeSpan.FromMilliseconds(2000));

            to.AssertValuesOnly(0, 1, 2, 3);

            ts.AdvanceTimeBy(TimeSpan.FromMilliseconds(2000));

            to.AssertResult(0, 1, 2, 3, 4);

            Assert.False(ts.HasTasks());
        }
        public void Error()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.CombineLatest(a =>
            {
                int v = 0;
                foreach (var e in a)
                {
                    v += e;
                }
                return(v);
            }, us1, us2).Test();

            to.AssertEmpty();

            us1.OnError(new InvalidOperationException());

            Assert.False(us2.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException));
        }
Beispiel #24
0
        public void Error_Second_Source()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.Zip(a =>
            {
                int s = 0;
                foreach (var v in a)
                {
                    s += v;
                }
                return(s);
            },
                                            us1,
                                            us2
                                            ).Test();

            us1.OnNext(1);

            to.AssertEmpty();

            us1.OnNext(2);

            to.AssertEmpty();

            us2.OnNext(10);

            to.AssertValuesOnly(11);

            us2.OnError(new InvalidOperationException());

            Assert.False(us1.HasObserver());

            to.AssertFailure(typeof(InvalidOperationException), 11);
        }
 public static IObservable <SearchedFile> FindReferences(IEntity entity, IProgressMonitor progressMonitor)
 {
     return(ReactiveExtensions.CreateObservable <SearchedFile>(
                (monitor, callback) => FindReferencesAsync(entity, monitor, callback),
                progressMonitor));
 }
 public static IObservable <Error> RenameSymbol(ISymbol symbol, string newName, IProgressMonitor progressMonitor)
 {
     return(ReactiveExtensions.CreateObservable <Error>(
                (monitor, callback) => RenameSymbolAsync(symbol, newName, monitor, callback),
                progressMonitor));
 }
 public static IObservable <SearchedFile> FindLocalReferences(IVariable variable, IProgressMonitor progressMonitor)
 {
     return(ReactiveExtensions.CreateObservable <SearchedFile>(
                (monitor, callback) => FindLocalReferencesAsync(variable, monitor).ContinueWith(t => callback(t.Result)),
                progressMonitor));
 }