Esempio n. 1
0
        public void ReadBinaryValue_ForNonSeekableStream()
        {
            var bufferSize = 4097;
            var bytes      = new byte[bufferSize];

            for (var i = 0; i < bufferSize; i++)
            {
                bytes[i] = (byte)(i % 10);
            }

            var payload = Encoding.UTF8.GetString(bytes);

            var encoding    = MediaTypeUtils.EncodingUtf8NoPreamble;
            var messageInfo = new ODataMessageInfo
            {
                MessageStream = new NonSeekableStream(new MemoryStream(encoding.GetBytes(payload))),
                MediaType     = new ODataMediaType(MimeConstants.MimeTextType, MimeConstants.MimePlainSubType),
                Encoding      = encoding,
                IsResponse    = true,
                IsAsync       = false,
                Model         = EdmCoreModel.Instance
            };

            using (var rawInputContext = new ODataRawInputContext(
                       ODataFormat.RawValue,
                       messageInfo,
                       this.messageReaderSettings))
            {
                var binaryValue = rawInputContext.ReadValue(EdmCoreModel.Instance.GetBinary(false));

                Assert.Equal(bytes, binaryValue);
            }
        }
 private static ODataBatchReaderStream CreateBatchReaderStream(string inputString)
 {
     var underlyingStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString));
     var inputContext = new ODataRawInputContext(
         ODataFormat.Batch, 
         underlyingStream, 
         Encoding.UTF8, 
         new ODataMessageReaderSettings(),
         false, 
         true, 
         null, 
         null, 
         ODataPayloadKind.Batch);
     var batchStream = new ODataBatchReaderStream(inputContext, "batch_862fb28e-dc50-4af1-aad5-9608647761d1", Encoding.UTF8);
     return batchStream;
 }
        private static ODataBatchReaderStream CreateBatchReaderStream(string inputString)
        {
            var underlyingStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString));
            var inputContext     = new ODataRawInputContext(
                ODataFormat.Batch,
                underlyingStream,
                Encoding.UTF8,
                new ODataMessageReaderSettings(),
                false,
                true,
                null,
                null,
                ODataPayloadKind.Batch);
            var batchStream = new ODataBatchReaderStream(inputContext, "batch_862fb28e-dc50-4af1-aad5-9608647761d1", Encoding.UTF8);

            return(batchStream);
        }
Esempio n. 4
0
        private static ODataBatchReaderStream CreateBatchReaderStream(string inputString)
        {
            var messageInfo = new ODataMessageInfo
            {
                Encoding      = Encoding.UTF8,
                IsResponse    = false,
                IsAsync       = false,
                PayloadKind   = ODataPayloadKind.Batch,
                MessageStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString))
            };
            var inputContext = new ODataRawInputContext(
                ODataFormat.Batch,
                messageInfo,
                new ODataMessageReaderSettings());
            var batchStream = new ODataBatchReaderStream(inputContext, "batch_862fb28e-dc50-4af1-aad5-9608647761d1", Encoding.UTF8);

            return(batchStream);
        }
Esempio n. 5
0
        private async Task SetupRawInputContextAndRunTestAsync(
            string payload,
            Func <ODataRawInputContext, Task> func)
        {
            var encoding    = MediaTypeUtils.EncodingUtf8NoPreamble;
            var messageInfo = new ODataMessageInfo
            {
                MessageStream = new MemoryStream(encoding.GetBytes(payload)),
                MediaType     = new ODataMediaType(MimeConstants.MimeTextType, MimeConstants.MimePlainSubType),
                Encoding      = encoding,
                IsResponse    = true,
                IsAsync       = true,
                Model         = EdmCoreModel.Instance
            };

            using (var rawInputContext = new ODataRawInputContext(
                       ODataFormat.RawValue,
                       messageInfo,
                       this.messageReaderSettings))
            {
                await func(rawInputContext);
            }
        }