Esempio n. 1
0
 //Constructor
 internal MemberExpression(ExpNode caller, PropertyInfo property, ExpNode[] args)
     : base(property.Name)
 {
     _caller    = caller;
     _arguments = args;
     _property  = property;
 }
Esempio n. 2
0
 public MemberBindExpression(ExpNode sourceProperty, TypedMemberExpression targetProperty)
     : base("MemberBindExpression")
 {
     SourceProperty = sourceProperty;
     TargetProperty = targetProperty;
     //SourceProperty = new PropertyExpression(
 }
Esempio n. 3
0
        //Overrides
        public override Object Clone()
        {
            //TODO: Override in each derived exp class
            ExpNode clone = (ExpNode)base.Clone();

            return(clone);
        }
Esempio n. 4
0
 //Constructor
 internal MethodExpression(ExpNode caller, MethodInfo method, ExpNode[] args)
     : base(method.Name)
 {
     _caller     = caller;
     _arguments  = args;
     _methodinfo = method;
 }
Esempio n. 5
0
        public override string Build(ExpNode node)
        {
            string serviceName;
            string queryUri = base.Build(node);

            return(this.Workspace.ServiceUri + "/" + queryUri);
        }
Esempio n. 6
0
        public ResourceProperty GetPropertyFromQuery()
        {
            if (!(Query_Internal is ProjectExpression))
            {
                return(null);
            }

            ProjectExpression projection = (ProjectExpression)Query_Internal;

            if (!projection.Projections.Any())
            {
                return(null);
            }

            ExpNode node = projection.Projections.First;

            if (node is NestedPropertyExpression)
            {
                return((node as NestedPropertyExpression).PropertyExpressions.Last().Property as ResourceProperty);
            }

            if (node is PropertyExpression)
            {
                return((node as PropertyExpression).Property as ResourceProperty);
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Implements IDataInserter.AddEntity by creating a POST-based insert request and adding it to the batch queue
        /// </summary>
        /// <param name="key">Key expression for new entity</param>
        /// <param name="entity">Update tree for new entity</param>
        public void AddEntity(KeyExpression key, KeyedResourceInstance entity)
        {
            // build the request
            //
            ExpNode        containerQuery = ContainmentUtil.BuildCanonicalQuery(key, true);
            AstoriaRequest request        = workspace.CreateRequest(containerQuery, entity, RequestVerb.Post);

            // set ETagHeaderExpected appropriately
            if (key.ResourceType.Properties.Any(p => p.Facets.ConcurrencyModeFixed))
            {
                request.ETagHeaderExpected = true;
            }

            // add it to the queue
            //
            queue.Add(request);

            // store the content-id
            //
            contentIDMap[entity] = request.Headers["Content-ID"];

            // fire the event
            //
            if (this.OnAddingEntity != null)
            {
                OnAddingEntity(key, entity);
            }
        }
Esempio n. 8
0
        public virtual void DirectedTests()
        {
            QueryModel  model  = new QueryModel(_workspace, SerializationFormatKind.Atom, null);
            ModelEngine engine = new ModelEngine(model);

            engine.Options.WeightScheme = WeightScheme.Custom;
            engine.Options.Timeout      = 100;

            engine.RunUntil(delegate()
            {
                return(engine.Models.Actions.AllCovered);
            });

            //engine.RunScenario(model.Actions.Find("From", "Where", " Navigation","Select","Expand"));
            //engine.RunUntil(delegate()
            //{
            //    return model.Actions.Accessed > 4;
            //});

            _query     = model.QueryResult;
            _container = model.ResContainer;
            _pType     = model.ResultType;

            if (_query != null || _pType != null)
            {
                VerifyClient(model);
            }
        }
Esempio n. 9
0
        public void VerifyServer(ExpNode q)
        {
            AstoriaTestLog.WriteLineIgnore("Verify server query");
            try
            {
                UriQueryBuilder ub   = new UriQueryBuilder(_workspace, "");
                string          ruri = ub.Build(q);
                AstoriaTestLog.WriteLineIgnore(ruri);


                AstoriaRequest request = _workspace.CreateRequest(q);
                request.Format = _kind;

                if (request.URI.Length > 260)
                {
                    return;
                }

                AstoriaResponse response = request.GetResponse();
                response.Verify();
            }
            catch (Exception e)
            {
                AstoriaTestLog.WriteLineIgnore(e.ToString());
            }
        }
Esempio n. 10
0
 //Constructor
 public NewExpression(ExpNode input, params ExpNode[] arguments)
     : base(input)
 {
     _target    = input;
     _arguments = new Nodes <ExpNode>(this, arguments);
     //_type = target.Type;
 }
Esempio n. 11
0
        public AstoriaRequest EntitySetTopLevel(ResourceContainer container)
        {
            ExpNode q = Query.From(
                Exp.Variable(container))
                        .Select();

            return(_workspace.CreateRequest(q));
        }
Esempio n. 12
0
        protected void Visit(ExpNode caller, ExpNode node, XmlElement parentNode)
        {
            nodeStack.Push(node);
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node is KeyedResourceInstance && (!(node is AssociationResourceInstance)))
            {
                KeyedResourceInstance e = (KeyedResourceInstance)node;
                CreateEntryElement(e, parentNode);
            }
            else if (node is AssociationResourceInstance)
            {
                AssociationResourceInstance e = (AssociationResourceInstance)node;
                if (caller == null)
                {
                    CreateLinkPayload(e, parentNode);
                }
                else
                {
                    CreateBinding(e, parentNode);
                }
            }
            //Below are two special cases
            else if (caller == null && node is ResourceInstanceSimpleProperty)
            {
                this.VisitResourceInstanceSimpleProperty(node as ResourceInstanceSimpleProperty, parentNode);
            }
            else if (caller == null && node is ResourceInstanceComplexProperty)
            {
                this.VisitResourceInstanceComplexProperty(node as ResourceInstanceComplexProperty, parentNode);
            }
            else if (caller == null && node is ResourceInstanceNavRefProperty)
            {
                ResourceInstanceNavRefProperty navRef = node as ResourceInstanceNavRefProperty;
                AssociationResourceInstance    associationResourceInstance = navRef.TreeNode as AssociationResourceInstance;
                if (associationResourceInstance != null && associationResourceInstance.Operation == AssociationOperation.Remove)
                {
                    this.CreateUnBinding(parentNode);
                }
                else
                {
                    throw new Exception("Unknown node type:" + navRef.TreeNode.GetType());
                }
            }
            else if (caller == null && node is ResourceInstanceCollection)
            {
                ResourceInstanceCollection collection = node as ResourceInstanceCollection;
                CreateLinksElement(collection, null);
            }
            else
            {
                throw new Exception("Unknown node type: " + node.GetType());
            }
            nodeStack.Pop();
        }
Esempio n. 13
0
        public AstoriaRequest SingleEntityKeyedTopLevel(ResourceContainer container, KeyExpression keyExp)
        {
            ExpNode q = Query.From(
                Exp.Variable(container))
                        .Where(keyExp)
                        .Select();

            return(_workspace.CreateRequest(q));
        }
Esempio n. 14
0
        public AstoriaRequest SingleEntityKeyedNavProp(ResourceContainer container, KeyExpression keyExp, ResourceProperty property)
        {
            ExpNode q = Query.From(
                Exp.Variable(container))
                        .Where(keyExp)
                        .Select(new PropertyExpression(property, false));

            return(_workspace.CreateRequest(q));
        }
Esempio n. 15
0
        public AstoriaRequest EntitySetNavProp(ResourceContainer container, KeyExpression keyExp, ResourceProperty property)
        {
            ExpNode q = Query.From(
                Exp.Variable(container))
                        .Where(keyExp)
                        .Nav(property.Property());

            return(_workspace.CreateRequest(q));
        }
Esempio n. 16
0
        public AstoriaRequest PrimitivePropertyValue(ResourceContainer container, KeyExpression keyExp, ResourceProperty property)
        {
            ExpNode q = Query.From(
                Exp.Variable(container))
                        .Where(keyExp)
                        .Select(new PropertyExpression(property, true));

            return(_workspace.CreateRequest(q));
        }
Esempio n. 17
0
        public override KeyExpressions GetExistingAssociatedKeys(ResourceContainer resourceContainer, ResourceProperty property, KeyExpression keyExpression)
        {
            bool pageSizeChanged  = false;
            int  originalPageSize = this.DataService.ConfigSettings.GetEntitySetPageSize(resourceContainer.Name);

            if (originalPageSize < 1000)
            {
                pageSizeChanged = true;
                this.DataService.ConfigSettings.SetEntitySetPageSize(resourceContainer.Name, 100000);
            }

            UriQueryBuilder uriQueryBuilder = new UriQueryBuilder(this, this.ServiceUri);
            ExpNode         query           = Query.From(
                Exp.Variable(resourceContainer))
                                              .Where(keyExpression)
                                              //.OfType(property.ResourceType)
                                              .Nav(new PropertyExpression(property))
                                              .Select();

            string uri = uriQueryBuilder.Build(query);

            ResourceType associatedResourceType = property.Type as ResourceType;

            if (property.Type is CollectionType)
            {
                associatedResourceType = (property.Type as CollectionType).SubType as ResourceType;
            }
            Type type = this._resourceTypeToWorkspaceTypeList[associatedResourceType];

            MethodInfo  method    = this.GetType().GetMethod("ClientExecuteWrapper", new Type[] { typeof(string), typeof(ResourceContainer) });
            MethodInfo  genMethod = method.MakeGenericMethod(new Type[] { type });
            IEnumerable o         = (IEnumerable)genMethod.Invoke(this, new object[] { uri, resourceContainer.FindDefaultRelatedContainer(property) });

            KeyExpressions keys = new KeyExpressions();

            //IEnumerator enumerator = o.GetEnumerator();
            foreach (object current in o)
            {
                if (current != null)
                {
                    //Type t = enumerator.Current.GetType();
                    Type t = current.GetType();

                    IEnumerable <ResourceType> typesWithName      = this.ServiceContainer.ResourceTypes.Where(rt => (t.Name.Equals(rt.Name)));
                    IEnumerable <ResourceType> typesWithNamespace = typesWithName.Where(rt2 => rt2.Namespace == t.Namespace).ToList();
                    ResourceType      instanceType     = typesWithNamespace.First();
                    ResourceContainer relatedContainer = resourceContainer.FindDefaultRelatedContainer(property);
                    keys.Add(GetKeyExpression(relatedContainer, instanceType, current));
                }
            }
            if (pageSizeChanged)
            {
                this.DataService.ConfigSettings.SetEntitySetPageSize(resourceContainer.Name, originalPageSize);
            }
            return(keys);
        }
Esempio n. 18
0
 public static void ExecuteLinq(Workspace workspace, ExpNode q, ResourceContainer container)
 {
     try
     {
         ExecuteLinq(workspace, q, container, false, null);
     }
     catch (Exception e)
     {
         AstoriaTestLog.FailAndContinue(e);
     }
 }
Esempio n. 19
0
 public override KeyExpressions GetAllExistingKeys(ExpNode query, ResourceContainer resourceContainer)
 {
     if (DataGenerator.Done)
     {
         return(base.GetAllExistingKeys(query, resourceContainer));
     }
     else
     {
         return(DataGenerator.GetAllGeneratedKeys(resourceContainer, null));
     }
 }
Esempio n. 20
0
        public AstoriaRequest EntitySetTopLevelWithSingleExpand(ResourceContainer container, ResourceProperty property)
        {
            PropertyExpression[] expandValues = new PropertyExpression[] { new PropertyExpression(property) };

            ExpNode q = Query.From(
                Exp.Variable(container))
                        .Expand(expandValues)
                        .Select();

            return(_workspace.CreateRequest(q));
        }
Esempio n. 21
0
        public void Skip()
        {
            int i = NextSkipValue();

            if (_query is OrderByExpression)
            {
                _query = ((OrderByExpression)_query).Skip(i) as SkipExpression;
            }

            bSkip     = true;
            _action   = LastAction.Skip;
            bIsOption = true;
            AstoriaTestLog.WriteLineIgnore(".Skip(" + i.ToString() + ")");
        }
Esempio n. 22
0
        public static MethodExpression Ceiling(this ExpNode arg)
        {
            System.Reflection.MethodInfo methodInfo;

            if (arg.Type is ClrDecimal)
            {
                methodInfo = typeof(Math).GetMethod("Ceiling", new Type[] { typeof(System.Decimal) });
            }
            else
            {
                methodInfo = typeof(Math).GetMethod("Ceiling", new Type[] { typeof(System.Double) });
            }

            return(new MethodExpression(null, methodInfo, new ExpNode[] { arg }));
        }
Esempio n. 23
0
        public virtual void Where()
        {
            AstoriaTestLog.WriteLineIgnore("Calling Where");

            //Sub model - projections
            PredicateModel model  = new PredicateModel(this.Workspace, this.ResContainer, this.property, this.ParentRelKey, this.ResType);
            ModelEngine    engine = new ModelEngine(this.Engine, model);

            engine.Run();

            ExpNode e = model.Result;

            this.ParentRelKey = e as KeyExpression;
            if (null == _parentKey)
            {
                /* no keys for resource type*/
                this.Reload();
                return;
            }

            int i = this.Engine.Options.Random.Next(0, 10);

            if (i % 7 == 0)
            {
                e       = ((KeyExpression)e).Predicate;
                bFilter = true;
            }

            if (e != null)
            {
                if (_query is ScanExpression)
                {
                    _query = ((ScanExpression)_query).Where(e) as PredicateExpression;
                }
                else if (_query is NavigationExpression)
                {
                    _query = ((NavigationExpression)_query).Where(e) as PredicateExpression;
                }

                bWhere  = true;
                IsKey   = true;
                _action = LastAction.Where;
                AstoriaTestLog.WriteLineIgnore(".Where()");
            }
        }
Esempio n. 24
0
        protected virtual string BuildMemberOrMethodExpression(ExpNode node, ExpNode caller, ExpNode[] arguments, string name)
        {
            string instance   = null;
            string args       = "";
            string actualName = null;

            if (caller != null)
            {
                instance = this.Visit(node, caller);
            }

            if (name.ToLowerInvariant() == "contains")
            {
                actualName = "contains";
                args       = this.Visit(node, arguments[0]);
                return(string.Format("{0}({1},{2})", actualName, instance, args));
            }
            else
            {
                actualName = name.ToLowerInvariant();

                if (arguments != null && arguments.Length > 0)
                {
                    for (int i = 0; i < arguments.Length; i++)
                    {
                        args += this.Visit(node, arguments[i]) + ", ";
                    }

                    args = args.Substring(0, args.Length - 2);

                    if (instance == null)
                    {
                        return(string.Format("{0}({1})", actualName, args));
                    }
                    else
                    {
                        return(string.Format("{0}({1},{2})", actualName, instance, args));
                    }
                }
                else
                {
                    return(string.Format("{0}({1})", actualName, instance));
                }
            }
        }
Esempio n. 25
0
        public void Sort(bool bAsc)
        {
            //Sub model - sort
            SortModel   model  = new SortModel(this._workspace, _fromContainer.BaseType);
            ModelEngine engine = new ModelEngine(this.Engine, model);

            engine.Run();

            PropertyExpression[] ordervalues = model.SortResult;

            if (_query is TopExpression)
            {
                _query = ((TopExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }
            else if (_query is SkipExpression)
            {
                _query = ((SkipExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }
            else if (_query is CountExpression)
            {
                _query = ((CountExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }
            else if (_query is ExpandExpression)
            {
                _query = ((ExpandExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }
            else if (_query is NavigationExpression)
            {
                _query = ((NavigationExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }
            else if (_query is PredicateExpression)
            {
                _query = ((PredicateExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }
            else if (_query is ScanExpression)
            {
                _query = ((ScanExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            }

            bSort     = true;
            _action   = LastAction.OrderBy;
            bIsOption = true;
            AstoriaTestLog.WriteLineIgnore(".OrderBy(" + ordervalues.ToString() + ")");
        }
Esempio n. 26
0
        public static void VerifyLinq(Workspace workspace, ExpNode q, IQueryable results)
        {
            //verify if the results are ok before building the URI
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            foreach (object element in results)
            {
                list.Add(element);
            }


            //UriQueryBuilder ub = new UriQueryBuilder(workspace, "");
            // string ruri = ub.Build(q);

            //System.Uri uri = new Uri(workspace.ServiceUri);
            // string uriRel = ruri.Substring(ruri.IndexOf("/") + 1);
            // AstoriaTestLog.WriteLineIgnore(uri.ToString() + uriRel);

            AstoriaRequest request = workspace.CreateRequest(q);

            request.Format = SerializationFormatKind.Atom;

            try
            {
                AstoriaResponse response = request.GetResponse();
                //response.VerifyHttpStatusCodeOk(response.StatusCode);

                CommonPayload payload = response.CommonPayload;
                if (payload.Value != null)
                {
                    payload.CompareValue(results, false, false);
                }
                else
                {
                    payload.Compare(results);
                }

                //AstoriaTestLog.AreEqual(response.ContentType, SerializationFormatKinds.ContentTypeFromKind(response.OriginalRequest.SerializationKind),
                //"Content-Type does not match Accept header request");
            }
            catch (Exception e)
            {
                AstoriaTestLog.FailAndContinue(e);
            }
        }
Esempio n. 27
0
        public void Navigation()
        {
            bool         bfound   = false;
            int          j        = 0;
            ResourceType _navType = null;

            while (!bfound && j < from.Properties.Count)
            {
                int i = this.Engine.Options.Random.Next(0, from.Properties.Count);

                ResourceProperty _property = (ResourceProperty)from.Properties[i];
                if (_property.IsNavigation && _property.Type is CollectionType && this.ResContainer.BaseType.Properties.Contains(_property))
                {
                    if (_query is PredicateExpression)
                    {
                        _query = ((PredicateExpression)_query).Nav(_property.Property()) as NavigationExpression;
                        if (_property.Type is CollectionType)
                        {
                            _navType = (ResourceType)((ResourceCollection)_property.Type).SubType;
                            _pType   = _navType.ClientClrType;
                        }
                        else if (_property.Type is ResourceType)
                        {
                            _navType = (ResourceType)_property.Type;
                            _pType   = _property.Type.ClrType;
                        }

                        this.ResType = _navType;

                        bNav         = true;
                        bfound       = true;
                        _action      = LastAction.Nav;
                        property     = _property;
                        this.ResType = _navType; //update the resourceType

                        AstoriaTestLog.WriteLineIgnore(".Nav(" + _property.Property().Name + ")");
                        IsKey = false;
                    }
                }

                j++;
            }
        }
Esempio n. 28
0
        public static void ExecuteLinq(Workspace workspace, ExpNode q, ResourceContainer container, bool bSingle, ExpNode altq)
        {
            System.Uri uri = new Uri(workspace.ServiceUri);

            WebDataCtxWrapper ctx = new WebDataCtxWrapper(uri);

            ctx.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            ctx.MergeOption = MergeOption.NoTracking;

            Type resType = container.BaseType.ClientClrType;

            ResolveClientType(workspace, ctx, resType);

            Type       cType = typeof(WebDataCtxWrapper);
            MethodInfo mi    = cType.GetMethod("CreateQuery", new Type[] { typeof(string) });

            Type       pType         = container.BaseType.ClientClrType;
            MethodInfo miConstructed = mi.MakeGenericMethod(pType);

            string uri2 = container.Name;

            AstoriaTestLog.WriteLineIgnore(workspace.ServiceUri + "/" + uri2);

            object[] args  = { uri2 };
            object   query = miConstructed.Invoke(ctx, args);

            LinqQueryBuilder lb   = new LinqQueryBuilder(workspace, (IQueryable)query);
            string           uri3 = lb.Build(q);

            AstoriaTestLog.WriteLineIgnore("Linq expression: " + lb.QueryExpression);

            //if (bSingle)
            //{
            //    var single = lb.QueryResultSingle;
            //    VerifyLinqSingle(workspace, altq, single, container);
            //}
            //else
            //{
            var queryable = lb.QueryResult;

            VerifyLinq(workspace, q, (IQueryable)queryable);
            //}
        }
Esempio n. 29
0
        public void Count()
        {
            if (_query is TopExpression)
            {
                _query = ((TopExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is OrderByExpression)
            {
                _query = ((OrderByExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is ScanExpression)
            {
                _query = ((ScanExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is NavigationExpression)
            {
                _query = ((NavigationExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is SkipExpression)
            {
                _query = ((SkipExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is NavigationExpression)
            {
                _query = ((NavigationExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is ExpandExpression)
            {
                _query = ((ExpandExpression)_query).Count(true) as CountExpression;
            }
            else if (_query is PredicateExpression)
            {
                _query = ((PredicateExpression)_query).Count(true) as CountExpression;
            }


            IsCount   = true;
            _action   = LastAction.Count;
            bIsOption = true;
            AstoriaTestLog.WriteLineIgnore(".Count");
        }
Esempio n. 30
0
        public void Top()
        {
            int i = NextTopValue();

            if (_query is OrderByExpression)
            {
                _query = ((OrderByExpression)_query).Top(i) as TopExpression;
            }
            else if (_query is CountExpression)
            {
                _query = ((CountExpression)_query).Top(i) as TopExpression;
            }
            else if (_query is ExpandExpression)
            {
                _query = ((ExpandExpression)_query).Top(i) as TopExpression;
            }
            else if (_query is NavigationExpression)
            {
                _query = ((NavigationExpression)_query).Top(i) as TopExpression;
            }
            else if (_query is SkipExpression)
            {
                _query = ((SkipExpression)_query).Top(i) as TopExpression;
            }
            else if (_query is PredicateExpression)
            {
                _query = ((PredicateExpression)_query).Top(i) as TopExpression;
            }
            else if (_query is ScanExpression)
            {
                _query = ((ScanExpression)_query).Top(i) as TopExpression;
            }

            iTop      = i;
            bTop      = true;
            _action   = LastAction.Top;
            bIsOption = true;
            AstoriaTestLog.WriteLineIgnore(".Top(" + i.ToString() + ")");
        }