Example #1
0
        public async Task WriteResponseAsync_WritesChangeSet()
        {
            HttpResponseMessage[] responses = new HttpResponseMessage[]
            {
                new HttpResponseMessage(HttpStatusCode.Accepted),
                new HttpResponseMessage(HttpStatusCode.NoContent)
            };
            ChangeSetResponseItem responseItem    = new ChangeSetResponseItem(responses);
            MemoryStream          memoryStream    = new MemoryStream();
            IODataResponseMessage responseMessage = new ODataMessageWrapper(memoryStream);
            ODataMessageWriter    writer          = new ODataMessageWriter(responseMessage);
            ODataBatchWriter      batchWriter     = await writer.CreateODataBatchWriterAsync();

            await batchWriter.WriteStartBatchAsync();

            await responseItem.WriteResponseAsync(batchWriter, CancellationToken.None, /*asyncWriter*/ true);

            await batchWriter.WriteEndBatchAsync();

            memoryStream.Position = 0;
            string responseString = new StreamReader(memoryStream).ReadToEnd();

            Assert.Contains("changesetresponse", responseString);
            Assert.Contains("Accepted", responseString);
            Assert.Contains("No Content", responseString);
        }
Example #2
0
        public async Task WriteResponseAsync_AsynchronouslyWritesOperation()
        {
            // Arrange
            HttpContext context = HttpContextHelper.Create(StatusCodes.Status202Accepted);

            OperationResponseItem responseItem    = new OperationResponseItem(context);
            MemoryStream          memoryStream    = new MemoryStream();
            IODataResponseMessage responseMessage = new ODataMessageWrapper(memoryStream);
            ODataMessageWriter    writer          = new ODataMessageWriter(responseMessage);

            // Act
            ODataBatchWriter batchWriter = await writer.CreateODataBatchWriterAsync();

            await batchWriter.WriteStartBatchAsync();

            await responseItem.WriteResponseAsync(batchWriter);

            await batchWriter.WriteEndBatchAsync();

            memoryStream.Position = 0;
            string responseString = new StreamReader(memoryStream).ReadToEnd();

            // Assert
            Assert.Contains("Accepted", responseString);
        }
        public async Task WriteResponseAsync_WritesChangeSet()
        {
            // Arrange
            HttpContext context1 = HttpContextHelper.Create(StatusCodes.Status202Accepted);
            HttpContext context2 = HttpContextHelper.Create(StatusCodes.Status204NoContent);

            ChangeSetResponseItem responseItem    = new ChangeSetResponseItem(new[] { context1, context2 });
            MemoryStream          memoryStream    = new MemoryStream();
            IODataResponseMessage responseMessage = new ODataMessageWrapper(memoryStream);
            ODataMessageWriter    writer          = new ODataMessageWriter(responseMessage);

            // Act
            ODataBatchWriter batchWriter = await writer.CreateODataBatchWriterAsync();

            await batchWriter.WriteStartBatchAsync();

            await responseItem.WriteResponseAsync(batchWriter);

            await batchWriter.WriteEndBatchAsync();

            memoryStream.Position = 0;
            string responseString = new StreamReader(memoryStream).ReadToEnd();

            // Assert
            Assert.Contains("changesetresponse", responseString);
            Assert.Contains("Accepted", responseString);
            Assert.Contains("No Content", responseString);
        }
 public override async Task StartBatchAsync()
 {
     _requestMessage = new ODataRequestMessage() { Url = _session.Settings.BaseUri };
     _messageWriter = new ODataMessageWriter(_requestMessage);
     _batchWriter = await _messageWriter.CreateODataBatchWriterAsync();
     await _batchWriter.WriteStartBatchAsync();
     this.HasOperations = true;
 }
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage()
            {
                Url = new Uri(_session.Settings.UrlBase)
            };
            _messageWriter = new ODataMessageWriter(_requestMessage);
            _batchWriter   = await _messageWriter.CreateODataBatchWriterAsync();

            await _batchWriter.WriteStartBatchAsync();
        }
#pragma warning disable 1998
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage() { Url = _session.Settings.BaseUri };
            _messageWriter = new ODataMessageWriter(_requestMessage);
#if SILVERLIGHT
            _batchWriter = _messageWriter.CreateODataBatchWriter();
            _batchWriter.WriteStartBatch();
#else
            _batchWriter = await _messageWriter.CreateODataBatchWriterAsync();
            await _batchWriter.WriteStartBatchAsync();
#endif
        }
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage()
            {
                Url = _session.Settings.BaseUri
            };
            _messageWriter = new ODataMessageWriter(_requestMessage);
            _batchWriter   = await _messageWriter.CreateODataBatchWriterAsync();

            await _batchWriter.WriteStartBatchAsync();

            this.HasOperations = true;
        }
Example #8
0
        public async Task Write(Stream stream, OeBatchMessage batchMessage)
        {
            IODataResponseMessage responseMessage = new Infrastructure.OeInMemoryMessage(stream, batchMessage.ContentType);

            using (var messageWriter = new ODataMessageWriter(responseMessage, _settings))
            {
                ODataBatchWriter writer = await messageWriter.CreateODataBatchWriterAsync().ConfigureAwait(false);

                await writer.WriteStartBatchAsync().ConfigureAwait(false);
                await WriteBatch(writer, batchMessage).ConfigureAwait(false);

                await writer.WriteEndBatchAsync().ConfigureAwait(false);
            }
        }
Example #9
0
        /// <summary>
        ///  Serialize the batch responses to an <see cref="IODataResponseMessage"/>.
        /// </summary>
        /// <param name="responseMessage">The response message.</param>
        /// <returns></returns>
        private async Task WriteToResponseMessageAsync(IODataResponseMessage responseMessage)
        {
            ODataMessageWriter messageWriter = new ODataMessageWriter(responseMessage, _writerSettings);
            ODataBatchWriter   writer        = await messageWriter.CreateODataBatchWriterAsync();

            await writer.WriteStartBatchAsync();

            foreach (ODataBatchResponseItem response in Responses)
            {
                await response.WriteResponseAsync(writer, /*asyncWriter*/ true);
            }

            await writer.WriteEndBatchAsync();
        }
Example #10
0
    public async override Task StartBatchAsync()
    {
        _requestMessage = new ODataRequestMessage()
        {
            Url = _session.Settings.BaseUri
        };
        _messageWriter = new ODataMessageWriter(_requestMessage, new ODataMessageWriterSettings {
            BaseUri = _session.Settings.BaseUri
        });
        _batchWriter = await _messageWriter.CreateODataBatchWriterAsync().ConfigureAwait(false);

        await _batchWriter.WriteStartBatchAsync().ConfigureAwait(false);

        HasOperations = true;
    }
Example #11
0
        private async Task WriteToResponseMessageAsync(IODataResponseMessage responseMessage)
        {
            // how to dispose it?
            ODataMessageWriter messageWriter = new ODataMessageWriter(responseMessage, _writerSettings);

            ODataBatchWriter writer = await messageWriter.CreateODataBatchWriterAsync().ConfigureAwait(false);

            await writer.WriteStartBatchAsync().ConfigureAwait(false);

            foreach (ODataBatchResponseItem response in Responses)
            {
                await response.WriteResponseAsync(writer).ConfigureAwait(false);
            }

            await writer.WriteEndBatchAsync().ConfigureAwait(false);
        }
#pragma warning disable 1998
        public override async Task StartBatchAsync()
        {
            _requestMessage = new ODataRequestMessage()
            {
                Url = _session.Settings.BaseUri
            };
            _messageWriter = new ODataMessageWriter(_requestMessage);
#if SILVERLIGHT
            _batchWriter = _messageWriter.CreateODataBatchWriter();
            _batchWriter.WriteStartBatch();
#else
            _batchWriter = await _messageWriter.CreateODataBatchWriterAsync().ConfigureAwait(false);

            await _batchWriter.WriteStartBatchAsync().ConfigureAwait(false);
#endif
            this.HasOperations = true;
        }
        public async Task WriteResponseAsync_AsynchronouslyWritesOperation()
        {
            OperationResponseItem responseItem    = new OperationResponseItem(new HttpResponseMessage(HttpStatusCode.Accepted));
            MemoryStream          memoryStream    = new MemoryStream();
            IODataResponseMessage responseMessage = new ODataMessageWrapper(memoryStream);
            ODataMessageWriter    writer          = new ODataMessageWriter(responseMessage);
            ODataBatchWriter      batchWriter     = await writer.CreateODataBatchWriterAsync();

            await batchWriter.WriteStartBatchAsync();

            await responseItem.WriteResponseAsync(batchWriter, CancellationToken.None, /*writeAsync*/ true);

            await batchWriter.WriteEndBatchAsync();

            memoryStream.Position = 0;
            string responseString = new StreamReader(memoryStream).ReadToEnd();

            Assert.Contains("Accepted", responseString);
        }