Beispiel #1
0
        /// <summary>
        /// Generates extra operations to go into a request changeset
        /// </summary>
        /// <param name="random">For generating the payloads to go in the extra operations</param>
        /// <param name="requestManager">For building the operations</param>
        /// <param name="model">To add any new types to.</param>
        /// <param name="baseUri">Base uri for the extra operations.</param>
        /// <param name="version">Maximum version for </param>
        /// <returns>An array of extra request operations.</returns>
        public static IHttpRequest[] ExtraRequestChangesetOperations(
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            EdmModel model,
            ODataUri baseUri,
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
            ExceptionUtilities.CheckArgumentNotNull(baseUri, "baseUri");
            var headers = new Dictionary <string, string> {
                { "RequestHeader", "RequestHeaderValue" }
            };
            string mergeContentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);

            List <IHttpRequest> requests = new List <IHttpRequest>();
            ODataRequest        request  = null;

            for (int i = 0; i < 4; i++)
            {
                request      = requestManager.BuildRequest(baseUri, HttpVerb.Post, headers);
                request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
                requests.Add(request);
                request      = requestManager.BuildRequest(baseUri, HttpVerb.Put, headers);
                request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
                requests.Add(request);
                request      = requestManager.BuildRequest(baseUri, HttpVerb.Patch, headers);
                request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
                requests.Add(request);
                request = requestManager.BuildRequest(baseUri, HttpVerb.Delete, headers);
                requests.Add(request);
            }

            return(requests.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// Generates extra operations to go into a request changeset
        /// </summary>
        /// <param name="random">For generating the payloads to go in the extra operations</param>
        /// <param name="requestManager">For building the operations</param>
        /// <param name="model">To add any new types to.</param>
        /// <param name="baseUri">Base uri for the extra operations.</param>
        /// <param name="version">Maximum version for </param>
        /// <returns>An array of extra request operations.</returns>
        public static IHttpRequest[] ExtraRequestChangesetOperations(
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            EdmModel model,
            ODataUri baseUri,
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
            ExceptionUtilities.CheckArgumentNotNull(baseUri, "baseUri");
            var headers = new Dictionary<string, string> { { "RequestHeader", "RequestHeaderValue" } };
            string mergeContentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);

            List<IHttpRequest> requests = new List<IHttpRequest>();
            ODataRequest request = null;
            for (int i = 0; i < 4; i++)
            {
                request = requestManager.BuildRequest(baseUri, HttpVerb.Post, headers);
                request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
                requests.Add(request);
                request = requestManager.BuildRequest(baseUri, HttpVerb.Put, headers);
                request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
                requests.Add(request);
                request = requestManager.BuildRequest(baseUri, HttpVerb.Patch, headers);
                request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
                requests.Add(request);
                request = requestManager.BuildRequest(baseUri, HttpVerb.Delete, headers);
                requests.Add(request);
            }

            return requests.ToArray();
        }
        /// <summary>
        /// Puts given payload in an operation for a changeset.
        /// </summary>
        /// <typeparam name="T"> Must be a PayloadTestDescriptor.</typeparam>
        /// <param name="payload">Payload to be put into changeset operation.</param>
        /// <param name="verb">Verb associated with payload.</param>
        /// <param name="baseUri">Baseuri for operation.</param>
        /// <param name="requestManager">RequestManager to build the request</param>
        /// <param name="contentType">The (optional) content type to be used for the operation content.</param>
        /// <returns>IHttpRequest containing payload with specified verb and uri</returns>
        public static ODataRequest InRequestOperation <T>(
            this T payload,
            HttpVerb verb,
            ODataUri baseUri,
            IODataRequestManager requestManager,
            string contentType = null) where T : PayloadTestDescriptor
        {
            ExceptionUtilities.CheckArgumentNotNull(payload, "payload");
            ExceptionUtilities.CheckArgumentNotNull(verb, "verb");
            ExceptionUtilities.CheckArgumentNotNull(baseUri, "baseUri");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");

            var headers = new Dictionary <string, string> {
                { "GivenPayloadRequestHeader", "PayloadHeaderValue" }
            };

            var request = requestManager.BuildRequest(baseUri, verb, headers);

            if (payload.PayloadElement != null)
            {
                if (string.IsNullOrEmpty(contentType))
                {
                    contentType = payload.PayloadElement.GetDefaultContentType();
                }

                contentType = HttpUtilities.BuildContentType(contentType, Encoding.UTF8.WebName, null);
                request.Headers.Add(Microsoft.OData.Core.ODataConstants.ContentTypeHeader, contentType);
                request.Body = requestManager.BuildBody(contentType, baseUri, payload.PayloadElement);
            }

            return(request);
        }
        /// <summary>
        /// Puts payload in a response operation with given status code.
        /// </summary>
        /// <typeparam name="T">Must be a PayloadTestDescriptor.</typeparam>
        /// <param name="payload">Payload to put in operation.</param>
        /// <param name="statusCode">Status code for response.</param>
        /// <param name="requestManager">Used to construct the body of the response.</param>
        /// <param name="contentType">The (optional) content type to be used for the operation content.</param>
        /// <returns>The response encapsulating the <paramref name="payload"/>.</returns>
        public static ODataResponse InResponseOperation <T>(
            this T payload,
            int statusCode,
            IODataRequestManager requestManager,
            string contentType = null) where T : PayloadTestDescriptor
        {
            ExceptionUtilities.CheckArgumentNotNull(payload, "payload");
            ExceptionUtilities.CheckArgumentNotNull(statusCode, "statusCode");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");

            var httpResponseData = new HttpResponseData
            {
                StatusCode = (HttpStatusCode)statusCode
            };

            httpResponseData.Headers.Add("GivenPayloadResponseHeader", "ResponseHeaderValue");

            if (payload.PayloadElement != null)
            {
                if (string.IsNullOrEmpty(contentType))
                {
                    contentType = payload.PayloadElement.GetDefaultContentType();
                }

                httpResponseData.Headers.Add(Microsoft.OData.Core.ODataConstants.ContentTypeHeader, contentType);

                // Convert the payload element to the byte[] representation
                httpResponseData.Body = requestManager.BuildBody(contentType, /*ODataUri*/ null, payload.PayloadElement).SerializedValue;
            }

            return(new ODataResponse(httpResponseData)
            {
                RootElement = payload.PayloadElement
            });
        }
Beispiel #5
0
        internal static void SetupProtocolRequest(QueryExpression expression, IODataRequestManager requestManager, IQueryToODataPayloadConverter queryToPayloadConverter, ODataUri uri, HttpHeaderCollection headers, string actionContentType, out Contracts.OData.ODataRequest request)
        {
            HttpVerb requestVerb = HttpVerb.Get;

            if (uri.IsAction())
            {
                requestVerb = HttpVerb.Post;
            }

            if (uri.IsWebInvokeServiceOperation())
            {
                requestVerb = HttpVerb.Post;
            }

            request = requestManager.BuildRequest(uri, requestVerb, headers);
            if (uri.IsAction())
            {
                var procedurePayload = queryToPayloadConverter.ComputePayload(expression) as ComplexInstance;

                if (procedurePayload != null)
                {
                    request.Headers.Add(HttpHeaders.ContentType, actionContentType);

                    FixupAddingResultWrappers(actionContentType, procedurePayload);

                    // TODO: Need to understand if product allow an Html form even if no parameters specified
                    request.Body = requestManager.BuildBody(actionContentType, uri, procedurePayload);
                }
            }
        }
        internal static void SetupProtocolRequest(QueryExpression expression, IODataRequestManager requestManager, IQueryToODataPayloadConverter queryToPayloadConverter, ODataUri uri, HttpHeaderCollection headers, string actionContentType, out Contracts.OData.ODataRequest request)
        {
            HttpVerb requestVerb = HttpVerb.Get;
            if (uri.IsAction())
            {
                requestVerb = HttpVerb.Post;
            }

            if (uri.IsWebInvokeServiceOperation())
            {
                requestVerb = HttpVerb.Post;
            }

            request = requestManager.BuildRequest(uri, requestVerb, headers);
            if (uri.IsAction())
            {
                var procedurePayload = queryToPayloadConverter.ComputePayload(expression) as ComplexInstance;

                if (procedurePayload != null)
                {
                    request.Headers.Add(HttpHeaders.ContentType, actionContentType);

                    FixupAddingResultWrappers(actionContentType, procedurePayload);

                    // TODO: Need to understand if product allow an Html form even if no parameters specified
                    request.Body = requestManager.BuildBody(actionContentType, uri, procedurePayload);
                }
            }
        }