Beispiel #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);
            }
        }
Beispiel #2
0
        public static void GetAndVerifyStatusCode(Workspace w, QueryNode query)
        {
            AstoriaRequest  request  = w.CreateRequest(query);
            AstoriaResponse response = request.GetResponse();

            ResponseVerification.VerifyStatusCode(response);
        }
Beispiel #3
0
        public BatchResponse(BatchRequest request, AstoriaResponse response)
            : base(request)
        {
            if (request.ExpectedStatusCode == HttpStatusCode.Accepted)
            {
                try
                {
                    ResponseVerification.VerifyStatusCode(response);
                }
                catch (Exception e)
                {
                    ResponseVerification.LogFailure(response, e);
                }
            }

            Responses = new List <AstoriaResponse>();

            this.Headers          = response.Headers;
            this.Payload          = response.Payload;
            this.ETagHeaderFound  = response.ETagHeaderFound;
            this.ActualStatusCode = response.ActualStatusCode;
            this.Exception        = response.Exception;

            if (request.ExpectedStatusCode == HttpStatusCode.Accepted)
            {
                BatchReader.ParseBatchResponse(this);
            }
        }
Beispiel #4
0
        public static void Verify(APICallLogBuilder callLogBuilder, AstoriaResponse response, Func <APICallLogEntry, APICallLogEntry, bool> compare, params ComplexType[] types)
        {
            if (!AstoriaTestProperties.IsLabRun)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("------------------------------------");
                builder.AppendLine("");
                builder.AppendLine("Verifying call order");
                builder.AppendLine("");

                if (types.Length > 0)
                {
                    builder.AppendLine("Metadata:");
                    WriteTypesToLog(builder, types);
                    builder.AppendLine("");
                }

                builder.AppendLine("Request:");
                response.Request.LogRequest(builder, true, true);
                builder.AppendLine("");
                builder.AppendLine("Response:");
                response.LogResponse(builder, true, true);
                builder.AppendLine("");
                AstoriaTestLog.WriteLineIgnore(builder.ToString());
            }

            try
            {
                Verify(callLogBuilder.Entries, response.Request.APICallLogEntries, compare);
            }
            catch (Exception ex)
            {
                if (types.Length > 0)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.AppendLine("Metadata:");
                    WriteTypesToLog(builder, types);
                    builder.AppendLine("");
                    AstoriaTestLog.WriteLineIgnore(builder.ToString());
                }

                ResponseVerification.LogFailure(response, ex);
            }
        }
Beispiel #5
0
        protected override void Verify()
        {
            if (!Applies(Response))
            {
                return;
            }

            // build a common payload for the insert
            //
            CommonPayload insertPayload = Response.Request.CommonPayload;

            // get the entity that was inserted
            PayloadObject inserted;

            if (!TryGetSingleObjectFromPayload(insertPayload, out inserted))
            {
                ResponseVerification.LogFailure(Response, new Exception("Insert request payload did not contain a single entity"));
            }

            // determine the type based on what was inserted
            ResourceType type = Response.Workspace.ServiceContainer.ResourceTypes.Single(rt => inserted.Type.Equals(rt.Namespace + "." + rt.Name));

            // get the entity that was returned
            PayloadObject returned;

            if (!TryGetSingleObjectFromPayload(Response.CommonPayload, out returned))
            {
                if (Versioning.Server.SupportsLiveFeatures)
                {
                    string preferHeader;
                    if (Response.Request.Headers.TryGetValue("prefer", out preferHeader) && preferHeader == "return=minimal")
                    {
                        return;
                    }
                }

                ResponseVerification.LogFailure(Response, new Exception("Insert response payload did not contain a single entity"));
            }

            // verify that the inserted and returned entities are equivalent
            VerifyInsertResponse(type, inserted, returned);

            // re-query the entity
            Workspace      workspace    = Response.Workspace;
            AstoriaRequest queryRequest = workspace.CreateRequest();

            if (type.Properties.Any(p => p.Facets.ConcurrencyModeFixed))
            {
                queryRequest.ETagHeaderExpected = true;
            }

            if (type.Key.Properties.Any(p => p.Type == Clr.Types.DateTime))
            {
                // this will blow up for MEST, but we don't currently have any datetime key + MEST types
                ResourceContainer container = Response.Workspace.ServiceContainer.ResourceContainers.Single(rc => !(rc is ServiceOperation) && rc.ResourceTypes.Contains(type));
                queryRequest.Query = ContainmentUtil.BuildCanonicalQuery(ConcurrencyUtil.ConstructKey(container, returned));
            }
            else
            {
                queryRequest.URI = Uri.UnescapeDataString(returned.AbsoluteUri);
                if (queryRequest.URI.Contains("E+"))
                {
                    queryRequest.URI = queryRequest.URI.Replace("E+", "E");
                }
                if (queryRequest.URI.Contains("e+"))
                {
                    queryRequest.URI = queryRequest.URI.Replace("e+", "e");
                }
            }

            AstoriaResponse queryResponse = queryRequest.GetResponse();

            if (queryResponse.ActualStatusCode == HttpStatusCode.BadRequest)
            {
                // try it as a filter instead (possibly caused by the URI being too long)
                // this will blow up for MEST
                ResourceContainer container = Response.Workspace.ServiceContainer.ResourceContainers
                                              .Single(rc => !(rc is ServiceOperation) && rc.ResourceTypes.Contains(type));
                KeyExpression key = ConcurrencyUtil.ConstructKey(container, returned);
                queryRequest  = workspace.CreateRequest(Query.From(Exp.Variable(container)).Where(key.Predicate));
                queryResponse = queryRequest.GetResponse();
            }
            queryResponse.Verify();

            // get the entity from the query
            PayloadObject queried;

            if (!TryGetSingleObjectFromPayload(queryResponse.CommonPayload, out queried))
            {
                ResponseVerification.LogFailure(queryResponse, new Exception("Query response payload did not contain a single entity"));
            }

            // ensure that the entity did not change between the insert and the re-query
            VerifyQueryResponse(type, returned, queried);
        }
 public static void Verify(this AstoriaResponse response)
 {
     ResponseVerification.Verify(response, false);
 }