Example #1
0
        public static void GetAndVerifyStatusCode(Workspace w, string uri, HttpStatusCode expectedStatusCode, out AstoriaResponse response, WebHeaderCollection requestHeaders)
        {
            AstoriaRequest request = w.CreateRequest();

            request.URI = uri;
            request.ExpectedStatusCode = expectedStatusCode;
            request.Accept = "*/*";

            if (requestHeaders != null)
            {
                foreach (string header in requestHeaders.AllKeys)
                {
                    request.Headers[header] = requestHeaders[header];
                }
            }
            response = request.GetResponse();
            try
            {
                ResponseVerification.VerifyStatusCode(response);
            }
            catch (Exception e)
            {
                ResponseVerification.LogFailure(response, e);
            }
        }
Example #2
0
 public static void GetAndVerifyStatusCode(Workspace w, QueryNode query, HttpStatusCode expectedStatusCode)
 {
     AstoriaRequest request = w.CreateRequest(query);
     request.ExpectedStatusCode = expectedStatusCode;
     AstoriaResponse response = request.GetResponse();
     ResponseVerification.VerifyStatusCode(response);
 }
Example #3
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);
            }
        }
Example #4
0
        public static AstoriaRequest BuildUpdate(Workspace workspace, KeyExpression modifiedKey, bool replace, HttpStatusCode expectedStatusCode, SerializationFormatKind format)
        {
            if (modifiedKey == null)
                return null;

            ResourceContainer container = modifiedKey.ResourceContainer;
            ResourceType resourceType = modifiedKey.ResourceType;

            if (replace && resourceType.Properties.Any(p => p.Facets.IsIdentity))
                return null;

            string keyString = UriQueryBuilder.CreateKeyString(modifiedKey, false);
            if (expectedStatusCode == HttpStatusCode.NoContent && (keyString.Contains("/") || keyString.Contains(Uri.EscapeDataString("/"))))
                expectedStatusCode = HttpStatusCode.BadRequest;

            QueryNode query = ContainmentUtil.BuildCanonicalQuery(modifiedKey);

            List<ResourceInstanceProperty> properties = new List<ResourceInstanceProperty>();

            string[] propertiesToSkip;
            //Skip because setting the birthdate to a random Datetime won't work due to contraints
            //if (resourceType.Name == "Employees")
            //    propertiesToSkip = new string[] { "BirthDate" };
            ////Skipping because it has some weird constraint on it
            //else if (resourceType.Name == "Order_Details")
            //    propertiesToSkip = new string[] { "Discount" };
            //else
            //    propertiesToSkip = new string[] { };

            foreach (ResourceProperty resourceProperty in resourceType.Properties.OfType<ResourceProperty>()
                .Where(p => !p.IsNavigation
                    && p.PrimaryKey == null
                    && !p.Facets.IsIdentity))
                    //&& !p.IsComplexType
                    //&& !propertiesToSkip.Contains(p.Name)))
            {
                properties.Add(resourceProperty.CreateRandomResourceInstanceProperty());
            }

            if (!properties.Any())
                return null;

            KeyedResourceInstance resourceInstance = new KeyedResourceInstance(
                ResourceInstanceKey.ConstructResourceInstanceKey(modifiedKey),
                properties.ToArray());

            AstoriaRequest request = workspace.CreateRequest();

            request.Verb = replace ? RequestVerb.Put : RequestVerb.Patch;
            request.Query = query;
            request.UpdateTree = resourceInstance;
            request.ExpectedStatusCode = expectedStatusCode;
            request.Format = format;

            if (modifiedKey.ResourceType.Properties.Any(p => p.Facets.ConcurrencyModeFixed))
            {
                request.Headers[ConcurrencyUtil.IfMatchHeader] = modifiedKey.ETag;
                request.ETagHeaderExpected = true;
            }

            return request;
        }
Example #5
0
        public static AstoriaRequest BuildDelete(Workspace workspace, KeyExpression toDelete, HttpStatusCode expectedStatusCode, SerializationFormatKind format)
        {
            QueryNode query = ContainmentUtil.BuildCanonicalQuery(toDelete);

            AstoriaRequest request = workspace.CreateRequest();

            request.Verb = RequestVerb.Delete;
            request.Query = query;
            request.Format = format;
            request.ExpectedStatusCode = expectedStatusCode;

            if (toDelete.ResourceType.Properties.Any(p => p.Facets.ConcurrencyModeFixed))
                request.Headers[ConcurrencyUtil.IfMatchHeader] = toDelete.ETag;

            return request;
        }
Example #6
0
        public static AstoriaRequest BuildInsert(Workspace workspace, ResourceContainer container, ResourceType type,
            HttpStatusCode expectedStatusCode, SerializationFormatKind format, out KeyExpression createdKey)
        {
            KeyedResourceInstance newResource = type.CreateRandomResource(container);
            if (newResource == null)
            {
                newResource = ResourceInstanceUtil.CreateKeyedResourceInstanceByClone(container, type);

                if(newResource == null)
                {
                    createdKey = null;
                    return null;
                }
            }

            QueryNode query;
            if (!type.Key.Properties.Any(p => p.Facets.ServerGenerated) && newResource.ResourceInstanceKey != null)
            {
                createdKey = newResource.ResourceInstanceKey.CreateKeyExpression(container, type);
                query = ContainmentUtil.BuildCanonicalQuery(createdKey, true);
            }
            else
            {
                createdKey = null;
                // the key is unknown, must be server generated
                // in this case, lets hope that containment is a non-issue
                query =
                    Query.From(Exp.Variable(container))
                    .Select();
                if (!container.Facets.TopLevelAccess && expectedStatusCode == HttpStatusCode.Created)
                    expectedStatusCode = HttpStatusCode.BadRequest;
            }

            AstoriaRequest request = workspace.CreateRequest();

            request.Verb = RequestVerb.Post;
            request.Query = query;
            request.UpdateTree = newResource;
            request.ExpectedStatusCode = expectedStatusCode;
            request.Format = format;

            return request;
        }
Example #7
0
        public static AstoriaRequest BuildGet(Workspace workspace, QueryNode query, HttpStatusCode expectedStatusCode, SerializationFormatKind format)
        {
            AstoriaRequest request = workspace.CreateRequest();

            request.Verb = RequestVerb.Get;
            request.Query = query;
            request.ExpectedStatusCode = expectedStatusCode;
            request.Format = format;

            return request;
        }