Exemple #1
0
        public async Task Basic()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, new[] { typeof(Qbservable2) }, Observable.Range(0, 5));
            var results = await service.QueryAsync(xs => xs.WhereEven(x => x));

            QactiveAssert.AreEqual(results, OnNext(0), OnNext(2), OnNext(4), OnCompleted <int>());
        }
Exemple #2
0
        public async Task Select()
        {
            var service = TcpTestService.Create(Observable.Range(0, 5));
            var results = await service.QueryAsync(xs => from x in xs
                                                   select x * 5);

            QactiveAssert.AreEqual(results, OnNext(0), OnNext(5), OnNext(10), OnNext(15), OnNext(20), OnCompleted <int>());
        }
Exemple #3
0
        public async Task Duplex()
        {
            var local = Observable.Range(100, 5);

            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, new[] { typeof(Qbservable2) }, Observable.Range(50, 5));
            var results = await service.QueryAsync(xs => xs.Add(x => x, local));

            QactiveAssert.AreEqual(results, OnNext(150), OnNext(152), OnNext(154), OnNext(156), OnNext(158), OnCompleted <int>());
        }
Exemple #4
0
        public async Task ContextualMethod()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Return(new TestContext()));

            var results = await service.QueryAsync(source => from context in source
                                                   select context.Value);

            QactiveAssert.AreEqual(results, OnNext(123), OnCompleted <int>());
        }
Exemple #5
0
        public async Task Where()
        {
            var service = TcpTestService.Create(Observable.Range(0, 5));
            var results = await service.QueryAsync(xs => from x in xs
                                                   where x % 2 == 0
                                                   select x);

            QactiveAssert.AreEqual(results, OnNext(0), OnNext(2), OnNext(4), OnCompleted <int>());
        }
Exemple #6
0
        public async Task ContextualEnumerable()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Return(new TestContext()));

            var results = await service.QueryAsync(source => from context in source
                                                   from serverValue in context.SingletonEnumerable
                                                   select serverValue);

            QactiveAssert.AreEqual(results, OnNext(1000), OnCompleted <int>());
        }
Exemple #7
0
        public async Task SelectClosure()
        {
            Func <int, int> selector = x => x * 5;

            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Range(0, 5));
            var results = await service.QueryAsync(xs => from x in xs
                                                   select selector(x));

            QactiveAssert.AreEqual(results, OnNext(0), OnNext(5), OnNext(10), OnNext(15), OnNext(20), OnCompleted <int>());
        }
Exemple #8
0
        public async Task Primitive()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Return(new TestContext()));
            var results = await service.QueryAsync(source => from context in source
                                                   from value in context.PrimitiveQuery
                                                   where value == 123
                                                   select value);

            QactiveAssert.AreEqual(results, OnNext(123), OnCompleted <int>());
        }
Exemple #9
0
        public async Task WhereClosure()
        {
            Func <int, bool> predicate = x => x % 2 == 0;

            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Range(0, 5));
            var results = await service.QueryAsync(xs => from x in xs
                                                   where predicate(x)
                                                   select x);

            QactiveAssert.AreEqual(results, OnNext(0), OnNext(2), OnNext(4), OnCompleted <int>());
        }
Exemple #10
0
        public async Task NestedQueriesAreAppliedToTheOuterProvider()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Return(new TestContext()));
            var results = await service.QueryAsync(source => from context in source
                                                   from value in from value in context.CustomQuery
                                                   where value == 123
                                                   select value
                                                   select value);

            QactiveAssert.AreEqual(results, OnNext(123), OnCompleted <int>());
        }
Exemple #11
0
        public async Task DuplexObservableWithNonSerializablePayload()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, new[] { typeof(NonSerializableObject) }, Observable.Return(new TestContext()));

            var local = Observable.Return(new NonSerializableObject());

            var results = await service.QueryAsync(source => from context in source
                                                   from value in local
                                                   select value);

            QactiveAssert.AreEqual(results, OnError <NonSerializableObject>(new SerializationException(Any.Message)));
        }
Exemple #12
0
        public async Task Join()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Range(0, 6));

            var results = await service.QueryAsync(source => from x in source
                                                   join y in Observable.Range(3, 7)
                                                   on Observable.Never <Unit>() equals Observable.Never <Unit>()
                                                   where x == y
                                                   select x + y);

            QactiveAssert.AreEqual(results, OnNext(6), OnNext(8), OnNext(10), OnCompleted <int>());
        }
Exemple #13
0
        public async Task DuplexEnumerable()
        {
            var service = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Return(new TestContext()));

            var local = Enumerable.Range(1, 5);

            var results = await service.QueryAsync(source => from context in source
                                                   from clientValue in local
                                                   where clientValue % 2 == 0
                                                   select clientValue);

            QactiveAssert.AreEqual(results, OnNext(2), OnNext(4), OnCompleted <int>());
        }
Exemple #14
0
        public async Task JoinClosureWithContext()
        {
            var service   = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Return(new TestContext()));
            var range3To7 = Observable.Range(3, 5);

            var results = await service.QueryAsync(source => from context in source
                                                   from x in context.Range0To5
                                                   join y in range3To7
                                                   on Observable.Never <Unit>() equals Observable.Never <Unit>()
                                                   where x == y
                                                   select x + y);

            QactiveAssert.AreEqual(results, OnNext(6), OnNext(8), OnNext(10), OnCompleted <int>());
        }
Exemple #15
0
        public async Task GroupJoinClosure()
        {
            var service   = TcpTestService.Create(TcpTestService.UnrestrictedOptions, Observable.Range(0, 6));
            var range3To7 = Observable.Range(3, 5);

            var results = await service.QueryAsync(source => from x in source
                                                   join y in range3To7
                                                   on Observable.Never <Unit>() equals Observable.Never <Unit>()
                                                   into ys
                                                   from y in ys.Take(3)
                                                   where x == y
                                                   select x + y);

            QactiveAssert.AreEqual(results, OnNext(6), OnNext(8), OnNext(10), OnCompleted <int>());
        }
Exemple #16
0
        public async Task SimpleVisitor()
        {
            var visitor = new TestExpressionVisitor();
            var service = TcpTestService.Create(QbservableServiceOptions.Default.Add(visitor), Observable.Range(1, 5));

            var results = await service.QueryAsync(source => from value in source
                                                   where value % 2 == 0
                                                   select value);

            QactiveAssert.AreEqual(results, OnNext(2), OnNext(4), OnCompleted <int>());
            QactiveAssert.AreEqual(visitor.Visited,
                                   Call <int>(typeof(Qbservable), "Where", Any.ExpressionOfType <IQbservable <int> >(), Any.LambdaExpression <Func <int, bool> >(Any.ParameterExpression <int>())),
                                   Any.ExpressionOfType <IQbservable <int> >(ExpressionType.Constant),
                                   Any.QuotedLambdaExpression <Func <int, bool> >(Any.ParameterExpression <int>()),
                                   Any.LambdaExpression <Func <int, bool> >(Any.ParameterExpression <int>()),
                                   Any.ExpressionOfType(ExpressionType.Equal),
                                   Any.ExpressionOfType(ExpressionType.Modulo),
                                   Any.ParameterExpression <int>(),
                                   Expression.Constant(2),
                                   Expression.Constant(0),
                                   Any.ParameterExpression <int>());
        }
Exemple #17
0
        public async Task ComplexTest1()
        {
            var rootIds = new[] { "C", "A" };
            var rootIdsLocal = rootIds.Do(v => Debug.WriteLine("RootObject: " + v));
            var nodeIds = new[] { new[] { "2", "4" } }.ToObservable().Do(p => p.ForEach(id => Debug.WriteLine("Node: " + id)));

            var service = TcpTestService.Create(
                TcpTestService.UnrestrictedOptions,
                new[] { typeof(RootObject), typeof(Node), typeof(Leaf), typeof(EnumerableEx) },
                Observable.Return(new ServiceContext(new[] { new RootObject("A", 1), new RootObject("B", 10), new RootObject("C", 100), new RootObject("D", 1000) })));

            var results = await service.QueryAsync(source =>
                                                   from leafPackResult in
                                                   from leaf in
                                                   (from context in source
                                                    from ids in nodeIds
                                                    select from root in context.RootObjects.ToObservable()
                                                    where rootIdsLocal.Contains(root.Id)
                                                    from node in root[ids]
                                                    from leaf in node.Leaves
                                                    select leaf)
                                                   .Switch()
                                                   group leaf by leaf.Node into leavesByNode
                                                   from leaves in leavesByNode.Buffer(leafCountPerNode *rootIds.Length)
                                                   select new
            {
                Node     = leavesByNode.Key,
                LeafPack = (from leaf in leaves
                            orderby leaf.Tick descending
                            select leaf)
                           .Distinct(leaf => leaf.Id)
                           .Memoize(memoized => new[]
                {
                    new
                    {
                        Greens = (from leaf in memoized
                                  where leaf.IsGreen
                                  orderby leaf.Size ascending
                                  select leaf)
                                 .ToList()
                                 .AsReadOnly(),
                        Browns = (from leaf in memoized
                                  where !leaf.IsGreen
                                  orderby leaf.Size descending
                                  select leaf)
                                 .ToList()
                                 .AsReadOnly()
                    }
                })
                           .First()
            }
                                                   select new
            {
                Node          = leafPackResult.Node,
                SmallestGreen = leafPackResult.LeafPack.Greens.FirstOrDefault(),
                LargestBrown  = leafPackResult.LeafPack.Browns.FirstOrDefault()
            });

            QactiveAssert.AreEqual(results,
                                   OnNext(new { Node = new Node("2"), SmallestGreen = new Leaf("2", 6), LargestBrown = new Leaf("5", 9) }),
                                   OnNext(new { Node = new Node("4"), SmallestGreen = new Leaf("2", 6), LargestBrown = new Leaf("5", 9) }),
                                   OnCompleted(new { Node = default(Node), SmallestGreen = default(Leaf), LargestBrown = default(Leaf) }));
        }