Example #1
0
    private async Task <(WeakReference Observer, WeakReference Proxy)> CancelableSubscription_Helper()
    {
        var mockObserver       = new MockObserver <int>();
        var observedValueCount = 0;
        var allValuesObserved  = new AsyncManualResetEvent();

        mockObserver.Next += (s, e) =>
        {
            if (++observedValueCount == 2)
            {
                allValuesObserved.Set();
            }
        };

        IDisposable disposable = await this.client.Subscribe(mockObserver).WithCancellation(this.TimeoutToken);

        await allValuesObserved.WaitAsync(this.TimeoutToken);

        await(this.server.FireAndForgetTask ?? Task.CompletedTask).WithCancellation(this.TimeoutToken);
        disposable.Dispose();

        var weakObserver = new WeakReference(mockObserver);
        var weakProxy    = new WeakReference(this.server.Observer);

        this.server.Observer = null;
        return(weakObserver, weakProxy);
    }
Example #2
0
        public void MultiSubjectProxy_AsObservable()
        {
            Run(client =>
            {
                var env = new TestExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var uri    = new Uri("test://stream");
                var sf     = env.Reactive.GetStreamFactory <int, int>(new Uri("rx://subject/inner"));
                var stream = sf.Create(uri, null);

                var proxy    = new MultiSubjectProxy <int, int>(uri);
                var observer = new MockObserver <int>(client);
                var sub      = ((IObservable <int>)proxy).Subscribe(observer);
                new SubscriptionInitializeVisitor((ISubscription)sub).Initialize(ctx);

                Schedule(client, 10, () => stream.OnNext(1));
                Schedule(client, 20, () => stream.OnNext(2));
                Schedule(client, 30, () => stream.OnNext(3));
                client.Start();

                observer.Messages.AssertEqual(
                    OnNext(10, 1),
                    OnNext(20, 2),
                    OnNext(30, 3)
                    );
            });
        }
Example #3
0
        public void asd()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver <int>(scheduler);

            Observable.Range(0, 3, Scheduler.Immediate)
            .Expand(i => (i < 300) ? Observable.Return(i + 100) : Observable.Empty <int>())
            .Subscribe(observer);

            observer.AssertEqual(
                OnNext(0, 0),
                OnNext(0, 1),
                OnNext(0, 2),
                OnNext(0, 100),
                OnNext(0, 101),
                OnNext(0, 102),
                OnNext(0, 200),
                OnNext(0, 201),
                OnNext(0, 202),
                OnNext(0, 300),
                OnNext(0, 301),
                OnNext(0, 302),
                OnCompleted(0)
                );
        }
Example #4
0
    private async Task <WeakReference> ServerMethodNotFound_ReleasesClientReference_Helper()
    {
        var observer = new MockObserver <int>();
        await Assert.ThrowsAsync <RemoteMethodNotFoundException>(() => Task.Run(() => this.clientRpc.InvokeWithCancellationAsync("non-existing", new object?[] { observer }, new Type[] { typeof(IObserver <int>) }, this.TimeoutToken)).WithCancellation(this.TimeoutToken));

        return(new WeakReference(observer));
    }
Example #5
0
        public void MultiSubjectProxy_AsObserver_OnCompleted()
        {
            Run(client =>
            {
                var env = new TestExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var inputUri     = new Uri("test://stream/input");
                var outputUri    = new Uri("test://stream/output");
                var sf           = env.Reactive.GetStreamFactory <int, int>(new Uri("rx://subject/inner"));
                var inputStream  = sf.Create(inputUri, null);
                var outputStream = sf.Create(outputUri, null);

                var inputProxy  = new MultiSubjectProxy <int, int>(inputUri);
                var outputProxy = new MultiSubjectProxy <int, int>(outputUri);
                var observer    = new MockObserver <int>(client);
                var inputSub    = SubscribeRoot(inputProxy, outputProxy.CreateObserver());
                var outputSub   = SubscribeRoot(outputProxy, observer);
                new SubscriptionInitializeVisitor(inputSub).Initialize(ctx);
                new SubscriptionInitializeVisitor(outputSub).Initialize(ctx);

                Schedule(client, 10, () => inputStream.OnCompleted());
                client.Start();

                observer.Messages.AssertEqual(
                    OnCompleted <int>(10)
                    );
            });
        }
Example #6
0
        public void Finite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted <int>(630),
                OnNext(640, 9),
                OnCompleted <int>(650),
                OnError <int>(660, new MockException(1))
                );

            var subject      = default(Subject <int>);
            var subscription = default(IDisposable);

            var results1      = new MockObserver <int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2      = new MockObserver <int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3      = new MockObserver <int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject      = new Subject <int>(), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7)
                );

            results2.AssertEqual(
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted <int>(630)
                );

            results3.AssertEqual(
                );
        }
Example #7
0
    private async Task <WeakReference> ServerMethodThrows_ReleasesClientReference_Helper()
    {
        var observer = new MockObserver <int>();
        await Assert.ThrowsAsync <RemoteInvocationException>(() => Task.Run(() => this.client.ThrowImmediately(observer)).WithCancellation(this.TimeoutToken));

        return(new WeakReference(observer));
    }
        public void ReliableMultiSubjectProxy_AsObserver()
        {
            Run(client =>
            {
                var env = new TestReliableExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var inputUri      = new Uri("test://stream/input");
                var outputUri     = new Uri("test://stream/output");
                var inputSubject  = new ReliableSubject <int>();
                var outputSubject = new ReliableSubject <int>();
                env.AddArtifact(inputUri, inputSubject);
                env.AddArtifact(outputUri, outputSubject);

                var inputProxy  = new ReliableMultiSubjectProxy <int, int>(inputUri);
                var outputProxy = new ReliableMultiSubjectProxy <int, int>(outputUri);
                var observer    = new MockObserver <int>(client);
                var inputSub    = SubscribeRoot(inputProxy.ToSubscribable(), new ObserverToReliableObserver <int>(outputProxy.CreateObserver()));
                var outputSub   = SubscribeRoot(outputProxy.ToSubscribable(), observer);
                new SubscriptionInitializeVisitor(inputSub).Initialize(ctx);
                new SubscriptionInitializeVisitor(outputSub).Initialize(ctx);

                var subjObsvr = inputSubject.CreateObserver();
                Schedule(client, 10, () => subjObsvr.OnNext(1, 0L));
                Schedule(client, 20, () => subjObsvr.OnNext(2, 1L));
                Schedule(client, 30, () => subjObsvr.OnNext(3, 2L));
                client.Start();

                observer.Messages.AssertEqual(
                    OnNext(10, 1),
                    OnNext(20, 2),
                    OnNext(30, 3)
                    );
            });
        }
Example #9
0
        public void all_streams_are_merged_if_no_concurrent_value_is_supplied()
        {
            var observer = new MockObserver <int>(scheduler);

            Observable.Merge((IObservable <IObservable <int> >)sources.ToObservable())
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(15, 20),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(35, 21),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(55, 22),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(75, 23),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
Example #10
0
        public void asd()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver<int>(scheduler);

            Observable.Range(0, 3, Scheduler.Immediate)
                .Expand(i => (i < 300) ? Observable.Return(i + 100) : Observable.Empty<int>())
                .Subscribe(observer);

            observer.AssertEqual(
                OnNext(0, 0),
                OnNext(0, 1),
                OnNext(0, 2),
                OnNext(0, 100),
                OnNext(0, 101),
                OnNext(0, 102),
                OnNext(0, 200),
                OnNext(0, 201),
                OnNext(0, 202),
                OnNext(0, 300),
                OnNext(0, 301),
                OnNext(0, 302),
                OnCompleted(0)
            );
        }
        public void ReliableMultiSubjectProxy_AsReliableObservable_Dispose()
        {
            Run(client =>
            {
                var env = new TestReliableExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var uri     = new Uri("test://stream");
                var subject = new ReliableSubject <int>();
                env.AddArtifact(uri, subject);

                var proxy    = new ReliableMultiSubjectProxy <int, int>(uri);
                var observer = new MockObserver <int>(client);
                var sub      = proxy.ToSubscribable().Subscribe(observer);
                new SubscriptionInitializeVisitor(sub).Initialize(ctx);
                sub.Dispose();

                // Reliable subscriptions must be ack'd before they can be disposed
                // Unfortunately, this acking must be done on the implicit interface.
                SubscriptionVisitor.Do <ReliableSubscriptionBase>(s => ((IReliableSubscription)s).AcknowledgeRange(0)).Apply(sub);
                sub.Dispose();

                var isDisposed = false;
                SubscriptionVisitor.Do <ReliableSubcription <int> >(s => isDisposed |= s.IsDisposed).Apply(sub);

                Assert.IsTrue(isDisposed);
            });
        }
Example #12
0
        public void MultiSubjectProxy_Untyped_AsObserver()
        {
            Run(client =>
            {
                var env = new TestExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var inputUri     = new Uri("test://stream/input");
                var outputUri    = new Uri("test://stream/output");
                var sf           = env.Reactive.GetStreamFactory <int, int>(new Uri("rx://subject/inner/untyped"));
                var inputStream  = sf.Create(inputUri, null);
                var outputStream = sf.Create(outputUri, null);

                var inputProxy  = new MultiSubjectProxy(inputUri);
                var outputProxy = new MultiSubjectProxy(outputUri);
                var observer    = new MockObserver <int>(client);
                var inputSub    = SubscribeRoot(inputProxy.GetObservable <int>(), outputProxy.GetObserver <int>());
                var outputSub   = SubscribeRoot(outputProxy.GetObservable <int>(), observer);
                new SubscriptionInitializeVisitor(inputSub).Initialize(ctx);
                new SubscriptionInitializeVisitor(outputSub).Initialize(ctx);

                Schedule(client, 10, () => inputStream.OnNext(1));
                Schedule(client, 20, () => inputStream.OnNext(2));
                Schedule(client, 30, () => inputStream.OnNext(3));
                client.Start();

                observer.Messages.AssertEqual(
                    OnNext(10, 1),
                    OnNext(20, 2),
                    OnNext(30, 3)
                    );
            });
        }
Example #13
0
    public async Task GiveObserverTest()
    {
        var observer = new MockObserver();
        await Task.Run(() => this.client.GiveObserver(observer)).WithCancellation(this.TimeoutToken);

        await observer.Completion.WithCancellation(this.TimeoutToken);
    }
Example #14
0
        public void all_streams_are_merged_if_no_concurrent_value_is_supplied()
        {
            var observer = new MockObserver<int>(scheduler);

            Observable.Merge((IObservable<IObservable<int>>)sources.ToObservable())
                .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(15, 20),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(35, 21),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(55, 22),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(75, 23),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
        public void SetUp()
        {
            // Setup the observer.
            _resultObserver = new MockObserver();
            NotificationListener.Subscribe(_resultObserver);

            _listnerToTest = new Notifications.iOS.NotificationListener();
        }
Example #16
0
    public async Task PushThenCompleteThenError()
    {
        var observer = new MockObserver <int>();
        await Task.Run(() => this.client.PushThenCompleteThenError(observer)).WithCancellation(this.TimeoutToken);

        await observer.Completion.WithCancellation(this.TimeoutToken);

        Assert.Equal(new[] { 1 }, observer.ReceivedValues);
    }
Example #17
0
    public async Task GiveObserverContainerTest()
    {
        var observer = new MockObserver();
        await Task.Run(() => this.client.GiveObserverContainer(new Container <IObserver <int> > {
            Field = observer
        })).WithCancellation(this.TimeoutToken);

        await observer.Completion.WithCancellation(this.TimeoutToken);
    }
Example #18
0
    public async Task CompleteTwice()
    {
        var observer = new MockObserver <int>();
        await Task.Run(() => this.client.CompleteTwice(observer)).WithCancellation(this.TimeoutToken);

        await observer.Completion.WithCancellation(this.TimeoutToken);

        Assert.Empty(observer.ReceivedValues);
    }
Example #19
0
        public void Should_push_initial_state()
        {
            var sut = new Store<int>(1, Reducers.PassThrough);
            var mockObserver = new MockObserver<int>();

            sut.Subscribe(mockObserver);

            CollectionAssert.AreEqual(new[] { 1 }, mockObserver.Values);
        }
Example #20
0
        public void HundredQeWithThousandSubscriptions()
        {
            const int NumberOfEngines       = 100;
            const int NumberOfSubscriptions = 1000;

            // Creating engines.
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var engines = new List <ICheckpointingQueryEngine>();
            var tasks   = new List <Task>();
            var sources = new ConcurrentQueue <MockObservable <int> >();

            for (int i = 0; i < NumberOfEngines; ++i)
            {
                var engine = CreateQueryEngine();
                engines.Add(engine);
                tasks.Add(new TaskFactory().StartNew(() => AddSubscriptions(engine, sources, NumberOfSubscriptions)));
            }
            Task.WaitAll(tasks.ToArray());
            stopwatch.Stop();

            Trace.WriteLine(
                string.Format("Time for creation of '{0}' engines with '{1}' subscriptions each: '{2}' milliseconds.",
                              NumberOfEngines,
                              NumberOfSubscriptions,
                              stopwatch.ElapsedMilliseconds));

            // Sending events.
            var inputs = sources.ToArray();

            stopwatch.Restart();
            for (int j = 0; j < 100; j++)
            {
                foreach (var source in inputs)
                {
                    source.OnNext(j);
                }
            }

            foreach (var input in inputs)
            {
                var result = MockObserver.Get <int>(input.Id);
                if (result == null || !result.WaitForCount(100, TimeSpan.FromSeconds(100)))
                {
                    Assert.Fail("Not everything was received.");
                }
                result.Clear();
            }
            stopwatch.Stop();

            Trace.WriteLine(
                string.Format("Time for processing '{0}' events: '{1}' milliseconds.",
                              100 * inputs.Length,
                              stopwatch.ElapsedMilliseconds));
        }
Example #21
0
    public async Task ReturnThenPushSequence()
    {
        var observer = new MockObserver <int>();
        await Task.Run(() => this.client.ReturnThenPushSequence(observer)).WithCancellation(this.TimeoutToken);

        var result = await observer.Completion.WithCancellation(this.TimeoutToken);

        await(this.server.FireAndForgetTask ?? Task.CompletedTask).WithCancellation(this.TimeoutToken);
        Assert.Equal(Enumerable.Range(1, 3), result);
    }
Example #22
0
        public static bool IsCompleted <T>(this MockObserver <T> source)
        {
            if (source.Count == 0)
            {
                return(false);
            }

            return(source.Last().Value is
                   Notification <T> .OnCompleted);
        }
Example #23
0
        public void Should_only_push_the_last_state_before_subscription()
        {
            var sut = new Store<int>(1, Reducers.Replace);
            var mockObserver = new MockObserver<int>();

            sut.Dispatch(new FakeAction<int>(2));
            sut.Subscribe(mockObserver);

            CollectionAssert.AreEqual(new[] { 2 }, mockObserver.Values);
        }
Example #24
0
    public async Task FaultImmediately()
    {
        var observer = new MockObserver <int>();
        await Task.Run(() => this.client.FaultImmediately(observer)).WithCancellation(this.TimeoutToken);

        var ex = await Assert.ThrowsAnyAsync <ApplicationException>(() => observer.Completion);

        Assert.Equal(ExceptionMessage, ex.Message);
        Assert.Empty(observer.ReceivedValues);
    }
Example #25
0
    public async Task PushThenThrowImmediately()
    {
        var observer = new MockObserver <int>();
        await Assert.ThrowsAsync <RemoteInvocationException>(() => Task.Run(() => this.client.PushThenThrowImmediately(observer)).WithCancellation(this.TimeoutToken));

        Assert.False(observer.Completion.IsCompleted);
        await observer.ItemReceived.WaitAsync(this.TimeoutToken);

        Assert.Equal(new[] { 1 }, observer.ReceivedValues);
    }
Example #26
0
        public void Infinite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8),
                OnNext(710, 9),
                OnNext(870, 10),
                OnNext(940, 11),
                OnNext(1020, 12)
                );

            var subject      = default(AsyncSubject <int>);
            var subscription = default(IDisposable);

            var results1      = new MockObserver <int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2      = new MockObserver <int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3      = new MockObserver <int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject      = new AsyncSubject <int>(scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                );

            results2.AssertEqual(
                );

            results3.AssertEqual(
                );
        }
Example #27
0
        public void Infinite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8),
                OnNext(710, 9),
                OnNext(870, 10),
                OnNext(940, 11),
                OnNext(1020, 12)
                );

            var subject = default(AsyncSubject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new AsyncSubject<int>(scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                );

            results2.AssertEqual(
                );

            results3.AssertEqual(
                );
        }
Example #28
0
        public void queued_streams_are_subscribed_to_when_a_merged_stream_completes()
        {
            var observer = new MockObserver<int>(scheduler);

            Observable.Merge(sources.ToObservable(), 2)
                .Subscribe(observer);

            scheduler.Run();

            Assert.AreEqual(85, sources[2].Subscriptions[0].Subscribe);
        }
Example #29
0
        public void queued_streams_are_subscribed_to_when_a_merged_stream_completes()
        {
            var observer = new MockObserver <int>(scheduler);

            Observable.Merge(sources.ToObservable(), 2)
            .Subscribe(observer);

            scheduler.Run();

            Assert.AreEqual(85, sources[2].Subscriptions[0].Subscribe);
        }
Example #30
0
        public void Session_invokes_observer_after_save()
        {
            var o  = new MockObserver();
            var sx = _cx.CreateSession("relax-observer-tests");

            sx.Observers.Add(o);
            var w = new Widget();

            sx.Save(w);
            Assert.That(o.TimesAfterSaveCalled, Is.EqualTo(1));
        }
Example #31
0
    private async Task <WeakReference> PushCompleteAndReturn_Helper()
    {
        var observer = new MockObserver <int>();
        await Task.Run(() => this.client.PushCompleteAndReturn(observer)).WithCancellation(this.TimeoutToken);

        await observer.Completion.WithCancellation(this.TimeoutToken);

        ImmutableList <int> result = await observer.Completion;

        Assert.Equal(Enumerable.Range(1, 3), result);
        return(new WeakReference(observer));
    }
        public void OnCompletedIsSentToAllNewSubscribersAfterItWasCompleted()
        {
            using (var subject = new EventEntrySubject())
            {
                subject.OnCompleted();

                var observer = new MockObserver <int>();
                subject.CreateSubscription(observer, entry => entry.EventId);

                Assert.IsTrue(observer.OnCompletedCalled);
            }
        }
        public void CanUnsubscribeNewSubscribersAfterItWasCompleted()
        {
            using (var subject = new EventEntrySubject())
            {
                subject.OnCompleted();

                var observer     = new MockObserver <int>();
                var subscription = subject.CreateSubscription(observer, entry => entry.EventId);

                subscription.Dispose();
            }
        }
        public void OnCompletedIsSentToAllNewSubscribersAfterItWasCompleted()
        {
            using (var subject = new EventEntrySubject())
            {
                subject.OnCompleted();

                var observer = new MockObserver <EventEntry>();
                subject.Subscribe(observer);

                Assert.IsTrue(observer.OnCompletedCalled);
            }
        }
        public void CanUnsubscribeNewSubscribersAfterItWasCompleted()
        {
            using (var subject = new EventEntrySubject())
            {
                subject.OnCompleted();

                var observer     = new MockObserver <EventEntry>();
                var subscription = subject.Subscribe(observer);

                subscription.Dispose();
            }
        }
Example #36
0
        public static T GetValue <T>(this MockObserver <T> source, int index)
        {
            if (index > source.Count - 1 ||
                !(source[index].Value is Notification <T> .OnNext))
            {
                throw new ArgumentOutOfRangeException("index");
            }

            var next = (Notification <T> .OnNext)source[index].Value;

            return(next.Value);
        }
Example #37
0
        public void Should_push_state_to_end_of_queue_on_nested_dispatch()
        {
            var sut = new Store<int>(1, Reducers.Replace);
            var mockObserver = new MockObserver<int>();
            sut.Subscribe(val =>
            {
                if (val < 5)
                {
                    sut.Dispatch(new FakeAction<int>(val + 1));
                }
                mockObserver.OnNext(val);
            });

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, mockObserver.Values);
        }
        public void DataVertex_AddCommand_Test()
        {
            var observer = new MockObserver();

            var vertex = new DataVertex();

            vertex.Subscribe(observer);

            vertex.AddCommand.Execute();

            Assert.AreEqual(observer.Operations.Count, 1);

            vertex.AddCommand.Execute();

            Assert.AreEqual(observer.Operations.Count, 2);
        }
Example #39
0
        public void Middleware_should_be_called_for_each_action_dispatched()
        {
            var numberOfCalls = 0;
            Middleware<int> spyMiddleware = store => next => action =>
            {
                numberOfCalls++;
                return next(action);
            };

            var sut = new Store<int>(1, Reducers.Replace, spyMiddleware);
            var mockObserver = new MockObserver<int>();
            
            sut.Subscribe(mockObserver);
            sut.Dispatch(new FakeAction<int>(2));

            Assert.AreEqual(1, numberOfCalls);
            CollectionAssert.AreEqual(new[] { 1, 2 }, mockObserver.Values);
        }
Example #40
0
        public void recursively_expands_values_and_merges()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver<int>(scheduler);

            scheduler.CreateColdObservable(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(15, 2),
                OnCompleted(15)
            )
            .Expand(i => (i < 300)
                ? scheduler.CreateColdObservable(
                    OnNext(5, i + 100),
                    OnCompleted(5))
                : Observable.Empty<int>()
            )
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(10, 100),
                OnNext(15, 2),
                OnNext(15, 101),
                OnNext(15, 200),
                OnNext(20, 102),
                OnNext(20, 201),
                OnNext(20, 300),
                OnNext(25, 202),
                OnNext(25, 301),
                OnNext(30, 302),
                OnCompleted(30)
            );
        }
Example #41
0
        public void concurrent_messages_are_merged()
        {
            var observer = new MockObserver<int>(scheduler);

            Observable.Merge(sources.ToObservable(), 2)
                .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
Example #42
0
        public void Bug_1381()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext( 90, 1),
                OnNext(110, 2),
                OnNext(250, 3),
                OnNext(270, 4),
                OnNext(280, 5),
                OnNext(301, 6),
                OnNext(302, 7),
                OnNext(400, 8),
                OnNext(401, 9),
                OnNext(510, 10)
                );

            var results = new MockObserver<int>(scheduler);
            var ys = default(IConnectableObservable<int>);
            var connection = default(IDisposable);
            var subscription = default(IDisposable);

            scheduler.Schedule(() => ys = xs.Replay(scheduler), 100);
            scheduler.Schedule(() => connection = ys.Connect(), 200);
            scheduler.Schedule(() => subscription = ys.Subscribe(results), 300);
            scheduler.Schedule(() => subscription.Dispose(), 500);
            scheduler.Schedule(() => connection.Dispose(), 600);

            scheduler.Run();

            results.AssertEqual(
                OnNext(301, 3),
                OnNext(302, 4),
                OnNext(303, 5),
                OnNext(304, 6),
                OnNext(305, 7),
                OnNext(400, 8),
                OnNext(401, 9)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 600)
                );
        }
        public HttpServerTransactionDelegate CreateTransaction()
        {
            responseDelegate = new MockResponseDelegate();
            var tx = new HttpServerTransactionDelegate(
                new MockResponseFactory()
                {
                    OnCreate = (head, shouldKeepAlive, end) =>
                    {
                        closeConnectionAction = end;
                        ShouldKeepAlive = shouldKeepAlive;
                        return responseDelegate;
                    }
                },
                new MockRequestDelegate()
                {
                    OnRequestAction = (head, body, response) =>
                    {
                        Assert.That(response, Is.SameAs(responseDelegate));

                        requestBody = body;

                        if (callbacks.OnRequest != null)
                            callbacks.OnRequest();
                    }
                });

            messageObserver = new MockObserver<IDataProducer>();
            messageObserverDisposable = tx.Subscribe(messageObserver);

            return tx;
        }
 public void Session_invokes_observer_after_load()
 {
     var o = new MockObserver();
     var sx1 = _cx.CreateSession("relax-observer-tests");
     var sx2 = _cx.CreateSession("relax-observer-tests");
     sx2.Observers.Add(o);
     var w = new Widget();
     var d = sx1.Save(w);
     var x = sx2.Load<Widget>(d.Id);
     Assert.That(o.TimesAfterLoadCalled, Is.EqualTo(1));
 }
 public void Session_invokes_observer_after_delete()
 {
     var o = new MockObserver();
     var sx = _cx.CreateSession("relax-observer-tests");
     sx.Observers.Add(o);
     var w = new Widget();
     sx.Save(w);
     sx.Delete(w);
     Assert.That(o.TimesAfterDeleteCalled, Is.EqualTo(1));
 }
Example #46
0
        public void latest_value_is_sampled_at_next_sample_time_after_completion()
        {
            var subject = new Subject<int>();

            var scheduler = new TestScheduler();

            var observer = new MockObserver<int>(scheduler);

            scheduler.CreateColdObservable(
                new Recorded<Notification<int>>(5, new Notification<int>.OnNext(0)),
                new Recorded<Notification<int>>(6, new Notification<int>.OnCompleted())
                )
                .Sample(new TimeSpan(15), scheduler)
                .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                new Recorded<Notification<int>>(15, new Notification<int>.OnNext(0)),
                new Recorded<Notification<int>>(15, new Notification<int>.OnCompleted())
                );
        }
 public void Session_respects_observer_before_delete_disposition()
 {
     var o = new MockObserver();
     o.BeforeDeleteDisposition = Disposition.Decline;
     var sx = _cx.CreateSession("relax-observer-tests");
     sx.Observers.Add(o);
     var w = new Widget();
     var d = sx.Save(w);
     Assert.Throws<Exception>(() => sx.Delete(w));
     Assert.That(o.TimesAfterDeleteCalled, Is.EqualTo(0));
 }
Example #48
0
        public void Finite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted<int>(630),
                OnNext(640, 9),
                OnCompleted<int>(650),
                OnError<int>(660, new MockException(1))
                );

            var subject = default(Subject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new Subject<int>(), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7)
                );

            results2.AssertEqual(
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted<int>(630)
                );

            results3.AssertEqual(
                );
        }
 public void Session_invokes_observer_before_save()
 {
     var o = new MockObserver();
     var sx = _cx.CreateSession("relax-observer-tests");
     sx.Observers.Add(o);
     var w = new Widget();
     sx.Save(w);
     Assert.That(o.TimesBeforeSaveCalled, Is.EqualTo(1));
     Assert.That(o.LastEntity, Is.SameAs(w));
 }
Example #50
0
        public void Canceled()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnCompleted<int>(630),
                OnNext(640, 9),
                OnCompleted<int>(650),
                OnError<int>(660, new MockException(1))
                );

            var subject = default(ReplaySubject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new ReplaySubject<int>(3, TimeSpan.FromTicks(100), scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                );

            results2.AssertEqual(
                OnCompleted<int>(630)
                );

            results3.AssertEqual(
                );
        }