Example #1
0
        public void BatchedActionMetadataTest()
        {
            var service = ActionTests.ModelWithActions();

            StringBuilder payloadBuilder = new StringBuilder();
            payloadBuilder.AppendLine("GET /$metadata HTTP/1.1");
            payloadBuilder.AppendLine("Host: host");
            payloadBuilder.AppendLine("Accept: " + UnitTestsUtil.MimeApplicationXml);

            using (TestWebRequest request = service.CreateForInProcess())
            {
                request.HttpMethod = "POST";
                request.RequestUriString = "/$batch";
                request.Accept = UnitTestsUtil.MimeMultipartMixed;

                string queryPayload = payloadBuilder.ToString();
                var batchInfo = new BatchInfo(new BatchQuery(new Operation(queryPayload)));

                const string boundary = "batch-set";
                request.RequestContentType = String.Format("{0}; boundary={1}", UnitTestsUtil.MimeMultipartMixed, boundary);
                request.SetRequestStreamAsText(BatchRequestWritingUtils.GetBatchText(batchInfo, boundary));

                request.SendRequest();
            }
        }
        public static string GetBatchText(BatchInfo info, string batchBoundary)
        {
            StringBuilder builder = new StringBuilder();

            // write each batch item
            foreach (BatchItem item in info.Items)
            {
                builder.Append("--");
                builder.AppendLine(batchBoundary);
                item.Write(builder);
            }

            // close the batch
            builder.AppendLine();
            builder.Append("--");
            builder.Append(batchBoundary);
            builder.AppendLine("--");

            return builder.ToString();
        }