Ejemplo n.º 1
0
        public async Task Remoting_SubscribeDo_AsyncToSyncMethodCalls()
        {
            var testObserverName = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var uri = new Uri("reactor://test/subscription");

                var xs         = ctx.GetObservable <int, int>(ReactorConstants.Identifiers.Observable.Range.Uri)(3);
                var observer   = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri)(testObserverName);
                var doObserver = ctx.GetObserver <int>(new Uri(Constants.Observer.Nop));

                await xs
                .Where(x => x > 0)
                .Do(x => doObserver.OnNextAsync(x, CancellationToken.None))
                .SubscribeAsync(observer, uri, null, CancellationToken.None);
            },
                new ObserverState <int>(testObserverName)
            {
                ObserverMessage.OnNext(1),
                ObserverMessage.OnNext(2),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 2
0
        public async Task Remoting_DistinctUntilChanged_KnownType()
        {
            var controlObserverName = new Uri("reactor://control/observer");
            var testObserverName    = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var controlUri = new Uri("reactor://control/subscription");
                var testUri    = new Uri("reactor://test/subscription");
                var io         = ctx.GetObservable <ClientPersonObservableParameters, ClientPerson>(ReactorConstants.Identifiers.Observable.Person.Uri);
                var iv         = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri);
                await io(new ClientPersonObservableParameters {
                    Age = 50
                }).Take(5).Select(p => p.Age).SubscribeAsync(iv(controlObserverName), controlUri, null, CancellationToken.None);
                await io(new ClientPersonObservableParameters {
                    Age = 50
                }).Take(5).DistinctUntilChanged().Select(p => p.Age).SubscribeAsync(iv(testObserverName), testUri, null, CancellationToken.None);
            },
                new ObserverState <int>(controlObserverName)
            {
                ObserverMessage.OnNext(50),
                ObserverMessage.OnNext(50),
                ObserverMessage.OnNext(50),
                ObserverMessage.OnNext(50),
                ObserverMessage.OnNext(50),
                ObserverMessage.OnCompleted <int>()
            },
                new ObserverState <int>(testObserverName)
            {
                ObserverMessage.OnNext(50),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 3
0
        public async Task Remoting_SubscribeWithEnums_ClientTypeToClientType()
        {
            var observerName = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var uri    = new Uri("reactor://test/observable");
                var subUri = new Uri("reactor://test/subscription");

                await ctx.DefineObservableAsync <ClientPerson>(
                    uri,
                    ctx.Empty <ClientPerson>().StartWith(new ClientPerson {
                    LastName = "Smith", Age = 30, Occupation = ClientOccupation.ChiefExecutiveOfficer
                }),
                    null,
                    CancellationToken.None);

                var observable      = ctx.GetObservable <AltClientPerson>(uri);
                var observerFactory = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri);
                var observer        = observerFactory(observerName);

                await observable
                .Where(p => p.Occupation == AltClientOccupation.ChiefExecutiveOfficer)
                .Select(p => p.YearsSinceBirth)
                .SubscribeAsync(observer, new Uri("reactor://test/subscription"), null, CancellationToken.None);
            },
                new ObserverState <int>(observerName)
            {
                ObserverMessage.OnNext(30),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 4
0
        public async Task Remoting_SubscribeWithEnums_ClientTypeToKnownType()
        {
            var observerName = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var uri              = new Uri("reactor://test/observable");
                var subUri           = new Uri("reactor://test/subscription");
                var personObservable = ctx.GetObservable <ClientPersonObservableParameters, ClientPerson>(ReactorConstants.Identifiers.Observable.Person.Uri);

                var observerFactory = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri);
                var observer        = observerFactory(observerName);

                await personObservable(new ClientPersonObservableParameters {
                    Age = 20, Occupation = ClientOccupation.Unemployed
                })
                .Take(1)
                .Where(p => p.Occupation == ClientOccupation.Unemployed).Select(p => p.Age)
                .SubscribeAsync(observer, new Uri("reactor://test/subscription"), null, CancellationToken.None);
            },
                new ObserverState <int>(observerName)
            {
                ObserverMessage.OnNext(20),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 5
0
        public async Task Remoting_DefineObservableAndSubscribe_ClientTypeToClientTypeWithStructuralArray()
        {
            var observerName = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var uri    = new Uri("reactor://test/observable");
                var suburi = new Uri("reactor://test/subscription");

                await ctx.UndefineObservableAsync(uri, CancellationToken.None);
                await ctx.DefineObservableAsync <ClientFamily>(
                    uri,
                    ctx.Empty <ClientFamily>().StartWith(new ClientFamily {
                    Members = { new ClientPerson {
                                    LastName = "Smith", Age = 30
                                } }
                }),
                    null,
                    CancellationToken.None);

                var observable      = ctx.GetObservable <ClientFamily>(uri);
                var observerFactory = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri);
                var observer        = observerFactory(observerName);

                await observable.Select(p => p.Members[0].Age).SubscribeAsync(observer, suburi, null, CancellationToken.None);
            },
                new ObserverState <int>(observerName)
            {
                ObserverMessage.OnNext(30),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 6
0
        public async Task Remoting_Subscribe_HigherArityObservable_ObserverState()
        {
            var uri              = new Uri("rx://test/observable");
            var subUri           = new Uri("rx://test/sub");
            var testObserverName = new Uri("rx://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var range = ctx.GetObservable <int, int>(ReactorConstants.Identifiers.Observable.Range.Uri);
                await ctx.DefineObservableAsync <int, int, int, int>(
                    uri,
                    (x, y, z) => range(x + y - z),
                    null,
                    CancellationToken.None
                    );

                var o        = ctx.GetObservable <int, int, int, int>(uri);
                var observer = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri)(testObserverName);

                await o(1, 2, 1).SubscribeAsync(observer, subUri, null, CancellationToken.None);

                await ctx.UndefineObservableAsync(uri, CancellationToken.None);
            },
                new ObserverState <int>(testObserverName)
            {
                ObserverMessage.OnNext(0),
                ObserverMessage.OnNext(1),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 7
0
        public async Task Remoting_Subscribe_VirtualTime_ObserverState()
        {
            var uri = new Uri("reactor://test/subscription");
            var testObserverName = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                (ctx, scheduler) =>
            {
                var observer = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri)(testObserverName);
                scheduler.ScheduleAbsolute(200, () => ctx.Empty <int>().StartWith(0, 1, 2, 3, 4).SubscribeAsync(observer, uri, null, CancellationToken.None));

                var sub = ctx.GetSubscription(uri);
                scheduler.ScheduleAbsolute(500, () => sub.DisposeAsync(CancellationToken.None));

                scheduler.ScheduleAbsolute(501, async() =>
                {
                    try
                    {
                        await sub.DisposeAsync(CancellationToken.None);
                    }
                    catch (AggregateException ex)
                    {
                        Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentException));
                    }
                });

                return(Task.FromResult(true));
            },
                new ObserverState <int>(testObserverName)
            {
                ObserverMessage.OnNext(201, 0),
                ObserverMessage.OnNext(202, 1),
                ObserverMessage.OnNext(203, 2),
                ObserverMessage.OnNext(204, 3),
                ObserverMessage.OnNext(205, 4),
                ObserverMessage.OnCompleted <int>(206)
            }
                );
        }
Ejemplo n.º 8
0
        public async Task Remoting_SubscribeGetDispose_ObserverState()
        {
            var uri = new Uri("reactor://test/subscription");
            var testObserverName = new Uri("reactor://test/observer");

            await AssertVirtual <ReactiveClientContext, int>(
                async (ctx, _) =>
            {
                var xs       = ctx.GetObservable <int, int>(ReactorConstants.Identifiers.Observable.Range.Uri)(5);
                var observer = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri)(testObserverName);
                await xs.SubscribeAsync(observer, uri, null, CancellationToken.None);
            },
                new ObserverState <int>(testObserverName)
            {
                ObserverMessage.OnNext(0),
                ObserverMessage.OnNext(1),
                ObserverMessage.OnNext(2),
                ObserverMessage.OnNext(3),
                ObserverMessage.OnNext(4),
                ObserverMessage.OnCompleted <int>()
            }
                );
        }
Ejemplo n.º 9
0
        public async Task Remoting_Range_VirtualTime_ObserverState_Schedule()
        {
            var observer         = default(Func <Uri, IAsyncReactiveQbserver <int> >);
            var observable       = default(IAsyncReactiveQbservable <int>);
            var testObserverName = new Uri("reactor://test/observer");
            var subscriptionUri  = new Uri("reactor://test/subscription");

            await AssertVirtual <ReactiveClientContext, int>(
                new VirtualTimeAgenda <ReactiveClientContext>
            {
                { 100L, ctx => { observer = ctx.GetObserver <Uri, int>(TestConstants.Test.TestObserver.Uri); } },
                { 150L, ctx => { observable = ctx.Empty <int>().StartWith(0, 1, 2, 3, 4); } },
                { 200L, ctx => observable.SubscribeAsync(observer(testObserverName), subscriptionUri, null, CancellationToken.None) }
            },
                new ObserverState <int>(testObserverName)
            {
                ObserverMessage.OnNext(201, 0),
                ObserverMessage.OnNext(202, 1),
                ObserverMessage.OnNext(203, 2),
                ObserverMessage.OnNext(204, 3),
                ObserverMessage.OnNext(205, 4),
                ObserverMessage.OnCompleted <int>(206)
            });
        }