Exemplo n.º 1
0
        private static bool UpdateQuery(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
        {
            switch (suffix)
            {
            case ContainmentQuerySuffix.SingleNavigationTwice:
                return(ApplyNavigationProperties(query, Multiplicity.One, Multiplicity.One));

            case ContainmentQuerySuffix.SingleNavigation:
                return(ApplyNavigationProperties(query, Multiplicity.One));

            case ContainmentQuerySuffix.MultipleNavigation:
                return(ApplyNavigationProperties(query, Multiplicity.Many));

            case ContainmentQuerySuffix.LinkedSingleNavigation:
                return(ApplyLink(query, Multiplicity.One));

            case ContainmentQuerySuffix.LinkedMultipleNavigation:
                return(ApplyLink(query, Multiplicity.Many));

            case ContainmentQuerySuffix.SimpleType:
                return(ApplySimpleType(query));

            case ContainmentQuerySuffix.None:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 2
0
 private static bool ApplyNavigationProperties(ContainmentQuery query, params Multiplicity[] multiplicities)
 {
     foreach (Multiplicity mult in multiplicities)
     {
         if (!ApplyNavigationProperty(query, mult, false))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        private static bool ApplyNavigationProperty(ContainmentQuery query, Multiplicity mult, bool isLink)
        {
            ResourceProperty property = getRandomNavigationProperty(query.Type, mult);

            if (property == null)
            {
                return(false);
            }

            query.Type      = property.OtherAssociationEnd.ResourceType;
            query.Container = query.Container.FindDefaultRelatedContainer(property);
            query.Query     = query.Query.Nav(property.Property(), isLink);
            return(true);
        }
Exemplo n.º 4
0
        private static bool MethodAllowed(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
        {
            if (query.SetExpected)
            {
                if (suffix != ContainmentQuerySuffix.None)
                {
                    AstoriaTestLog.FailAndThrow("Only the NONE suffix can be used when a set is expected");
                }

                return(verb == RequestVerb.Get || verb == RequestVerb.Post);
            }
            else
            {
                return(VerbMap.Valid(suffix, verb));
            }
        }
Exemplo n.º 5
0
 private static void UpdateErrorState(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
 {
     if (!MethodAllowed(query, suffix, verb))
     {
         // TODO: set error identifier?
         query.ExpectedStatusCode = HttpStatusCode.MethodNotAllowed;
         switch (verb)
         {
         case RequestVerb.Post:
             query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.BadRequest_InvalidUriForPostOperation;
             UriQueryBuilder builder = new UriQueryBuilder(query.Workspace, query.Workspace.ServiceEndPoint);
             query.ExpectedErrorArgs = new object[] { builder.Build(query.Query) };
             break;
         }
     }
 }
Exemplo n.º 6
0
        private static bool ApplySimpleType(ContainmentQuery query)
        {
            ResourceProperty property = getRandomProperty(query.Type,
                                                          (p) => (!p.IsComplexType && !p.IsNavigation &&
                                                                  p.ForeignKeys.Count() == 0 && !p.ResourceType.Key.Contains(p)));

            if (property == null)
            {
                return(false);
            }

            query.Type      = null;
            query.Container = null;
            query.Query     = query.Query.Select(property.Property());
            return(true);
        }
Exemplo n.º 7
0
        public IEnumerable <ContainmentQuery> GetRandomRootQueries(bool setOnly)
        {
            //UriQueryBuilder uriBuilder = new UriQueryBuilder(serviceContainer.Workspace, serviceContainer.Workspace.ServiceEndPoint);
            foreach (ContainmentQueryPath path in rootQueryPaths)
            {
                // if we're just looking at the set, then only return the unabreviated version (to avoid duplicate uris)
                if (setOnly && path.FinalSetAbbreviated)
                {
                    continue;
                }

                //KeyExpressions keys = serviceContainer.Workspace.GetAllExistingKeys(path.FinalContainer);
                //KeyExpression keyExpression = keys.First;
                KeyExpression keyExpression = serviceContainer.Workspace.GetRandomExistingKey(path.FinalContainer);

                ContainmentQuery query = path.ToQuery(keyExpression, setOnly);

                //string uri = uriBuilder.Build(query.Query).Replace(serviceContainer.Workspace.ServiceEndPoint, "");
                //string pathString = path.ToString().PadRight(40, ' ');
                //AstoriaTestLog.WriteLineIgnore(list.Count + ". " + pathString + ":     " + uri);

                yield return(query);
            }
        }
Exemplo n.º 8
0
        private static bool ApplySimpleType(ContainmentQuery query)
        {
            ResourceProperty property = getRandomProperty(query.Type,
                            (p) => (!p.IsComplexType && !p.IsNavigation &&
                                    p.ForeignKeys.Count() == 0 && !p.ResourceType.Key.Contains(p)));
            if (property == null)
                return false;

            query.Type = null;
            query.Container = null;
            query.Query = query.Query.Select(property.Property());
            return true;
        }
Exemplo n.º 9
0
            public ContainmentQuery ToQuery(KeyExpression keyExpression, bool setOnly)
            {
                ResourceContainer finalContainer = FinalContainer;

                AstoriaTestLog.AreEqual(keyExpression.ResourceContainer, finalContainer,
                                        "ToQuery given a KeyExpression to an unexpected resource container");

                List <KeyExpression>     keys = GetContainingKeys(keyExpression);
                List <ResourceContainer> omittedContainers =
                    segments.Where(s => s.omitParent).Select(s => s.attribute.ParentContainer).ToList();

                ContainmentQuery query = new ContainmentQuery();

                query.Query       = null;
                query.Container   = finalContainer;
                query.Type        = query.Container.BaseType;
                query.Workspace   = query.Container.Workspace;
                query.SetExpected = setOnly;

                ResourceContainer parentContainer = null;

                foreach (KeyExpression key in keys)
                {
                    if (omittedContainers.Contains(key.ResourceContainer))
                    {
                        continue;
                    }

                    bool omitKey = (setOnly && key == keyExpression);

                    if (parentContainer == null)
                    {
                        if (!query.ErrorExpected && !key.ResourceContainer.BaseType.Facets.TopLevelAccess)
                        {
                            SetTopLevelAccessError(query, key.ResourceType);
                        }

                        if (!omitKey)
                        {
                            if (!query.ErrorExpected && key.IncludeInUri.Contains(false))
                            {
                                SetMissingKeysError(query, key.ResourceType);
                            }
                        }

                        query.Query = Query.From(Exp.Variable(key.ResourceContainer));
                    }
                    else
                    {
                        ResourceProperty navProp = segments
                                                   .Where(s => s.attribute.ParentContainer == parentContainer)
                                                   .Select(s => s.attribute.ParentNavigationProperty)
                                                   .FirstOrDefault();

                        query.Query = query.Query.Nav(navProp.Property());
                    }

                    parentContainer = key.ResourceContainer;

                    // if we just want the set, leave off the last where clause
                    if (!omitKey)
                    {
                        query.Query = query.Query.Where(key);
                    }
                }

                return(query);
            }
Exemplo n.º 10
0
 private static void SetMissingKeysError(ContainmentQuery query, ResourceType type)
 {
     query.ExpectedStatusCode = System.Net.HttpStatusCode.BadRequest;
     query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.BadRequest_KeyCountMismatch;
     query.ExpectedErrorArgs = new string[] { type.ClrType.FullName };
 }
Exemplo n.º 11
0
 public static bool AppendSuffix(this ContainmentQuery query, ContainmentQuerySuffix suffix)
 {
     return(query.AppendSuffix(suffix, RequestVerb.Get));
 }
Exemplo n.º 12
0
            public ContainmentQuery ToQuery(KeyExpression keyExpression, bool setOnly)
            {
                ResourceContainer finalContainer = FinalContainer;
                AstoriaTestLog.AreEqual(keyExpression.ResourceContainer, finalContainer,
                    "ToQuery given a KeyExpression to an unexpected resource container");

                List<KeyExpression> keys = GetContainingKeys(keyExpression);
                List<ResourceContainer> omittedContainers =
                    segments.Where(s => s.omitParent).Select(s => s.attribute.ParentContainer).ToList();

                ContainmentQuery query = new ContainmentQuery();
                query.Query = null;
                query.Container = finalContainer;
                query.Type = query.Container.BaseType;
                query.Workspace = query.Container.Workspace;
                query.SetExpected = setOnly;

                ResourceContainer parentContainer = null;
                foreach (KeyExpression key in keys)
                {
                    if (omittedContainers.Contains(key.ResourceContainer))
                        continue;

                    bool omitKey = (setOnly && key == keyExpression);

                    if (parentContainer == null)
                    {
                        if (!query.ErrorExpected && !key.ResourceContainer.BaseType.Facets.TopLevelAccess)
                            SetTopLevelAccessError(query, key.ResourceType);

                        if (!omitKey)
                        {
                            if (!query.ErrorExpected && key.IncludeInUri.Contains(false))
                                SetMissingKeysError(query, key.ResourceType);
                        }
                        
                        query.Query = Query.From(Exp.Variable(key.ResourceContainer));
                    }
                    else
                    {
                        ResourceProperty navProp = segments
                            .Where(s => s.attribute.ParentContainer == parentContainer)
                            .Select(s => s.attribute.ParentNavigationProperty)
                            .FirstOrDefault();
                        
                        query.Query = query.Query.Nav(navProp.Property());
                    }

                    parentContainer = key.ResourceContainer;

                    // if we just want the set, leave off the last where clause
                    if(!omitKey)
                        query.Query = query.Query.Where(key);
                }

                return query;
            }
Exemplo n.º 13
0
 private static bool ApplyLink(ContainmentQuery query, Multiplicity mult)
 {
     return ApplyNavigationProperty(query, mult, true);
 }
Exemplo n.º 14
0
 private static bool ApplyNavigationProperties(ContainmentQuery query, params Multiplicity[] multiplicities)
 {
     foreach (Multiplicity mult in multiplicities)
     {
         if (!ApplyNavigationProperty(query, mult, false))
             return false;
     }
     return true;
 }
Exemplo n.º 15
0
        private static bool ApplyNavigationProperty(ContainmentQuery query, Multiplicity mult, bool isLink)
        {
            ResourceProperty property = getRandomNavigationProperty(query.Type, mult);
            if (property == null)
                return false;

            query.Type = property.OtherAssociationEnd.ResourceType;
            query.Container = query.Container.FindDefaultRelatedContainer(property);
            query.Query = query.Query.Nav(property.Property(), isLink);
            return true;
        }
Exemplo n.º 16
0
 private static void UpdateErrorState(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
 {
     if (!MethodAllowed(query, suffix, verb))
     {
         // TODO: set error identifier?
         query.ExpectedStatusCode = HttpStatusCode.MethodNotAllowed;
         switch (verb)
         {
             case RequestVerb.Post:
                 query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.BadRequest_InvalidUriForPostOperation;
                 UriQueryBuilder builder = new UriQueryBuilder(query.Workspace, query.Workspace.ServiceEndPoint);
                 query.ExpectedErrorArgs = new object[] { builder.Build(query.Query) };
                 break;
         }
     }
 }
Exemplo n.º 17
0
        private static bool MethodAllowed(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
        {
            if (query.SetExpected)
            {
                if (suffix != ContainmentQuerySuffix.None)
                {
                    AstoriaTestLog.FailAndThrow("Only the NONE suffix can be used when a set is expected");
                }

                return verb == RequestVerb.Get || verb == RequestVerb.Post;
            }
            else
            {
                return VerbMap.Valid(suffix, verb);
            }
        }
Exemplo n.º 18
0
 private static bool ApplyLink(ContainmentQuery query, Multiplicity mult)
 {
     return(ApplyNavigationProperty(query, mult, true));
 }
Exemplo n.º 19
0
        private static bool UpdateQuery(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
        {
            switch (suffix)
            {
                case ContainmentQuerySuffix.SingleNavigationTwice:
                    return ApplyNavigationProperties(query, Multiplicity.One, Multiplicity.One);

                case ContainmentQuerySuffix.SingleNavigation:
                    return ApplyNavigationProperties(query, Multiplicity.One);

                case ContainmentQuerySuffix.MultipleNavigation:
                    return ApplyNavigationProperties(query, Multiplicity.Many);

                case ContainmentQuerySuffix.LinkedSingleNavigation:
                    return ApplyLink(query, Multiplicity.One);

                case ContainmentQuerySuffix.LinkedMultipleNavigation:
                    return ApplyLink(query, Multiplicity.Many);

                case ContainmentQuerySuffix.SimpleType:
                    return ApplySimpleType(query);

                case ContainmentQuerySuffix.None:
                    return true;

                default:
                    return false;
            }
        }
Exemplo n.º 20
0
 private static void SetTopLevelAccessError(ContainmentQuery query, ResourceType type)
 {
     query.ExpectedStatusCode = System.Net.HttpStatusCode.NotFound;
     //query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.CreateFirstSegment_NoTopLevelAccess;
     query.ExpectedErrorArgs = new string[] { type.ClrType.Name }; // TODO: error?, for missing keys it is full name
 }
Exemplo n.º 21
0
 private static void SetMissingKeysError(ContainmentQuery query, ResourceType type)
 {
     query.ExpectedStatusCode      = System.Net.HttpStatusCode.BadRequest;
     query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.BadRequest_KeyCountMismatch;
     query.ExpectedErrorArgs       = new string[] { type.ClrType.FullName };
 }
Exemplo n.º 22
0
 public static bool AppendSuffix(this ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb)
 {
     UpdateErrorState(query, suffix, verb);
     return(UpdateQuery(query, suffix, verb));
 }
Exemplo n.º 23
0
 private static void SetTopLevelAccessError(ContainmentQuery query, ResourceType type)
 {
     query.ExpectedStatusCode = System.Net.HttpStatusCode.NotFound;
     //query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.CreateFirstSegment_NoTopLevelAccess;
     query.ExpectedErrorArgs = new string[] { type.ClrType.Name }; // TODO: error?, for missing keys it is full name
 }