Exemplo n.º 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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates extra operations for a batch response.
        /// </summary>
        /// <param name="random">Random generator for generating extra payloads.</param>
        /// <param name="model">Model to add any generated types to.</param>
        /// <param name="version">Maximum version of generated types.</param>
        /// <returns></returns>
        public static IMimePart[] ExtraResponseOperations(
            IRandomNumberGenerator random,
            EdmModel model       = null,
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            List <ODataResponse> responses = new List <ODataResponse>();
            ODataResponse        response  = null;

            for (int x = 0; x < 5; ++x)
            {
                response = new ODataResponse(new HttpResponseData()
                {
                    StatusCode = (HttpStatusCode)random.Next(500)
                })
                {
                    RootElement = random.ChooseFrom(new[] { null, RandomPayloadBuilder.GetRandomPayload(random, model, version) })
                };
                response.Headers.Add("ResponseHeader", "ResponseHeaderValue");
                responses.Add(response);
            }

            return(responses.ToArray());
        }