Ejemplo n.º 1
0
        public async Task SerializeToStreamAsync_WritesODataBatchResponseItems()
        {
            HttpContext okContext = new DefaultHttpContext();

            okContext.Response.StatusCode = (int)HttpStatusCode.OK;
            HttpContext acceptedContext = new DefaultHttpContext();

            acceptedContext.Response.StatusCode = (int)HttpStatusCode.Accepted;
            HttpContext badRequestContext = new DefaultHttpContext();

            badRequestContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;

            ODataBatchContent batchContent = CreateBatchContent(new ODataBatchResponseItem[]
            {
                new OperationResponseItem(okContext),
                new ChangeSetResponseItem(new HttpContext[]
                {
                    acceptedContext,
                    badRequestContext
                })
            });

            MemoryStream stream = new MemoryStream();
            await batchContent.SerializeToStreamAsync(stream);

            stream.Position = 0;
            string responseString = await new StreamReader(stream).ReadToEndAsync();

            Assert.Contains("changesetresponse", responseString);
            Assert.Contains("OK", responseString);
            Assert.Contains("Accepted", responseString);
            Assert.Contains("Bad Request", responseString);
        }
Ejemplo n.º 2
0
        public async Task SerializeToStreamAsync_WritesODataBatchResponseItems()
        {
            // Arrange
            HttpContext okContext = new DefaultHttpContext();

            okContext.Response.StatusCode = StatusCodes.Status200OK;

            HttpContext acceptedContext = new DefaultHttpContext();

            acceptedContext.Response.StatusCode = StatusCodes.Status202Accepted;

            HttpContext badRequestContext = new DefaultHttpContext();

            badRequestContext.Response.StatusCode = StatusCodes.Status400BadRequest;

            // Act
            ODataBatchContent batchContent = new ODataBatchContent(new ODataBatchResponseItem[]
            {
                new OperationResponseItem(okContext),
                new ChangeSetResponseItem(new HttpContext[]
                {
                    acceptedContext,
                    badRequestContext
                })
            },
                                                                   new MockServiceProvider());

            MemoryStream stream = new MemoryStream();
            await batchContent.SerializeToStreamAsync(stream);

            stream.Position = 0;
            string responseString = await new StreamReader(stream).ReadToEndAsync();

            // Assert
            Assert.Contains("changesetresponse", responseString);
            Assert.Contains("OK", responseString);
            Assert.Contains("Accepted", responseString);
            Assert.Contains("Bad Request", responseString);
        }