Exemple #1
0
        public async Task WriteResponse_SynchronouslyWritesChangeSet()
        {
            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     = writer.CreateODataBatchWriter();

            batchWriter.WriteStartBatch();

            // For backward compatibility, default is to assume a synchronous batch writer
            await responseItem.WriteResponseAsync(batchWriter, CancellationToken.None);

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

            Assert.Contains("changesetresponse", responseString);
            Assert.Contains("Accepted", responseString);
            Assert.Contains("No Content", responseString);
        }
Exemple #2
0
        public void 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     = writer.CreateODataBatchWriter();

            batchWriter.WriteStartBatch();

            responseItem.WriteResponseAsync(batchWriter, CancellationToken.None).Wait();

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

            Assert.Contains("changesetresponse", responseString);
            Assert.Contains("Accepted", responseString);
            Assert.Contains("No Content", 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);
        }
Exemple #4
0
        public void WriteResponseAsync_NullWriter_Throws()
        {
            ChangeSetResponseItem responseItem = new ChangeSetResponseItem(new HttpResponseMessage[0]);

            Assert.ThrowsArgumentNull(
                () => responseItem.WriteResponseAsync(null, CancellationToken.None).Wait(),
                "writer");
        }
Exemple #5
0
        public async Task WriteResponseAsync_NullWriter_Throws()
        {
            ChangeSetResponseItem responseItem = new ChangeSetResponseItem(new HttpResponseMessage[0]);

            await ExceptionAssert.ThrowsArgumentNullAsync(
                () => responseItem.WriteResponseAsync(null, CancellationToken.None),
                "writer");
        }
        public async Task WriteResponseAsync_NullWriter_Throws()
        {
            // Arrange & Act
            HttpContext[]         contexts     = Array.Empty <HttpContext>();
            ChangeSetResponseItem responseItem = new ChangeSetResponseItem(contexts);

            await ExceptionAssert.ThrowsArgumentNullAsync(() => responseItem.WriteResponseAsync(null), "writer");
        }
        public void WriteResponse_SynchronouslyWritesChangeSet_Throws()
        {
            // 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 = writer.CreateODataBatchWriter();

            batchWriter.WriteStartBatch();

            // Assert
            Action         test      = () => responseItem.WriteResponseAsync(batchWriter).Wait();
            ODataException exception = ExceptionAssert.Throws <ODataException>(test);

            Assert.Equal("An asynchronous operation was called on a synchronous batch writer. Calls on a batch writer instance must be either all synchronous or all asynchronous.",
                         exception.Message);
        }