public void FixtureSetup()
        {
            _mockClient = new Mock <IRestClient>();
            _mockClient.SetupGet(x => x.ServiceBase).Returns(new Uri("http://localhost"));
            var memberNameResolver = new MemberNameResolver();

            _provider = new RestGetQueryProvider <FakeItem>(_mockClient.Object, new TestSerializerFactory(memberNameResolver), new ExpressionProcessor(new ExpressionWriter(memberNameResolver, Enumerable.Empty <IValueWriter>(), Enumerable.Empty <IMethodCallWriter>()), memberNameResolver), memberNameResolver, Enumerable.Empty <IValueWriter>(), Enumerable.Empty <IMethodCallWriter>(), typeof(FakeItem));
        }
Exemplo n.º 2
0
        public void FixtureSetup()
        {
            var mockResolver = new MemberNameResolver();

            _mockClient = new Mock <IRestClient>();
            _mockClient.SetupGet(x => x.ServiceBase).Returns(new Uri("http://localhost"));
            _mockClient.Setup(x => x.Get(It.IsAny <Uri>())).Returns("[]".ToStream());
            _getQueryable = new RestGetQueryable <FakeItem>(_mockClient.Object, new TestSerializerFactory(mockResolver), mockResolver, Enumerable.Empty <IValueWriter>(), Enumerable.Empty <IMethodCallWriter>(), typeof(FakeItem));
        }
        public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            var fromExpression     = queryModel.MainFromClause.FromExpression as MemberExpression;
            var memberNameResolver = new MemberNameResolver(fromExpression);

            reqlExpr = memberNameResolver.Resolve(reqlExpr);
            reqlExpr = reqlExpr.Filter(expr => GetWhereReqlAst(expr, ((AllResultOperator)queryModel.ResultOperators[0]).Predicate, queryModel).Not());
            return(reqlExpr.Count().Eq(0));
        }
        public void FixtureSetup()
        {
            _inputData  = "[]".ToStream();
            _mockClient = new Mock <IRestClient>();
            _mockClient.SetupGet(x => x.ServiceBase).Returns(new Uri("http://localhost"));
            _mockClient.Setup(x => x.Post(It.IsAny <Uri>(), It.IsAny <Stream>())).Returns("[]".ToStream());
            var memberNameResolver = new MemberNameResolver();

            _provider = new RestPostQueryProvider <FakeItem>(_mockClient.Object, new TestSerializerFactory(memberNameResolver), new ExpressionProcessor(new ExpressionWriter(memberNameResolver, Enumerable.Empty <IValueWriter>()), memberNameResolver), memberNameResolver, Enumerable.Empty <IValueWriter>(), _inputData, typeof(FakeItem));
        }
        public void FixtureSetup()
        {
            var mockResolver = new MemberNameResolver();
            Expression <Func <FakeItem, bool> > expression = x => true;

            _mockClient = new Mock <IRestClient>();
            _mockClient.SetupGet(x => x.ServiceBase).Returns(new Uri("http://localhost"));
            _mockClient.Setup(x => x.Delete(It.IsAny <Uri>())).Returns("[]".ToStream());
            _deleteQueryable = new RestDeleteQueryable <FakeItem>(_mockClient.Object, new TestSerializerFactory(mockResolver), mockResolver, Enumerable.Empty <IValueWriter>(), expression, typeof(FakeItem));
        }
        public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            var fromExpression = queryModel.MainFromClause.FromExpression as ConstantExpression;
            var array          = RethinkDB.R.Expr(fromExpression.Value as IEnumerable <object>);

            var resultOperator = queryModel.ResultOperators[0] as ContainsResultOperator;

            var memberNameResolver = new MemberNameResolver((MemberExpression)resultOperator.Item);

            return(array.Contains(memberNameResolver.Resolve(reqlExpr)));
        }
        public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel)
        {
            var fromExpression     = queryModel.MainFromClause.FromExpression as MemberExpression;
            var memberNameResolver = new MemberNameResolver(fromExpression);

            reqlExpr = memberNameResolver.Resolve(reqlExpr);
            if (queryModel.BodyClauses.Any())
            {
                reqlExpr = reqlExpr.Filter(expr => GetWhereReqlAst(expr, ((WhereClause)queryModel.BodyClauses[0]).Predicate, queryModel));
            }
            return(BuildReql(reqlExpr, queryModel));
        }
        public void WhenCreatingSelectExpressionFromXmlMemberOnPropertyThenGetsPropertyValue()
        {
            var nameResolver = new MemberNameResolver();
            var factory      = new SelectExpressionFactory <FakeItem>(nameResolver, new RuntimeTypeProvider(nameResolver));
            var items        = new[] { new FakeItem {
                                           IntValue = 2
                                       } };

            var expression = factory.Create("Number");

            dynamic result = items.AsQueryable().Select(expression).First();

            Assert.AreEqual(2, result.Number);
        }
        public void WhenCreatingSelectExpressionFromDataMemberOnFieldThenGetsFieldValue()
        {
            var nameResolver = new MemberNameResolver();
            var factory      = new SelectExpressionFactory <FakeItem>(nameResolver, new RuntimeTypeProvider(nameResolver));
            var items        = new[] { new FakeItem {
                                           StringValue = "test"
                                       } };

            var expression = factory.Create("Text");

            dynamic result = items.AsQueryable().Select(expression).First();

            Assert.AreEqual("test", result.Text);
        }
        protected override Expression VisitMember(MemberExpression expression)
        {
            Visit(expression.Expression);

            var fieldName = expression.Member.Name;

            if (_type.GetTypeInfo().IsGenericType&& _type.GetGenericTypeDefinition() == typeof(IGrouping <,>) && fieldName == "Key")
            {
                _stack.Push(_reqlExpr["group"]);
            }
            else
            {
                var memberNameResolver = new MemberNameResolver(expression);
                _stack.Push(memberNameResolver.Resolve(_reqlExpr));
            }

            return(expression);
        }
        public void FixtureSetup()
        {
            var memberNameResolver = new MemberNameResolver();

            _factory = new SelectExpressionFactory <FakeItem>(memberNameResolver, new RuntimeTypeProvider(memberNameResolver));

            _items = new[]
            {
                new FakeItem {
                    IntValue = 2, DoubleValue = 5
                },
                new FakeItem {
                    IntValue = 1, DoubleValue = 4
                },
                new FakeItem {
                    IntValue = 3, DoubleValue = 4
                }
            };
        }