public void TopBatchReturingODataError()
        {
            const string payload = @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
<error xmlns=""http://docs.oasis-open.org/odata/ns/metadata"">
  <code></code>
  <message xml:lang=""en-US"">This error must show up in the error returned below</message>
</error>";

            IODataRequestMessage requestMessage = new ODataTestMessage();
            var responseMessage = new ODataTestMessage();

            responseMessage.SetHeader("Content-Type", "application\atom+xml");
            responseMessage.SetHeader("OData-Version", "4.0");
            responseMessage.StatusCode = 400;
            responseMessage.WriteToStream(payload);
            responseMessage.SetHeader("Content-Length", "0");

            var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, requestMessage, responseMessage);

            context.AddObject("Products", new SimpleNorthwind.Product()
            {
                ID = 1
            });
            Action test = () => context.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            // we should be returning an ODataErrorException instead of the full contents
            test.ShouldThrow <DataServiceRequestException>()
            .WithInnerException <DataServiceClientException>()
            .And.InnerException.Message.Should().Be("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">\r\n  <code></code>\r\n  <message xml:lang=\"en-US\">This error must show up in the error returned below</message>\r\n</error>");
        }
        public void TopBatchReturingODataError()
        {
            const string payload = @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
<error xmlns=""http://docs.oasis-open.org/odata/ns/metadata"">
  <code></code>
  <message xml:lang=""en-US"">This error must show up in the error returned below</message>
</error>";

            IODataRequestMessage requestMessage = new ODataTestMessage();
            var responseMessage = new ODataTestMessage();
            responseMessage.SetHeader("Content-Type", "application\atom+xml");
            responseMessage.SetHeader("OData-Version", "4.0");
            responseMessage.StatusCode = 400;
            responseMessage.WriteToStream(payload);
            responseMessage.SetHeader("Content-Length", "0");

            var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, requestMessage, responseMessage);
            context.AddObject("Products", new SimpleNorthwind.Product() { ID = 1 });
            Action test = () => context.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);

            // we should be returning an ODataErrorException instead of the full contents
            test.ShouldThrow<DataServiceRequestException>()
                .WithInnerException<DataServiceClientException>()
                .And.InnerException.Message.Should().Be("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">\r\n  <code></code>\r\n  <message xml:lang=\"en-US\">This error must show up in the error returned below</message>\r\n</error>");
        }
        private DataServiceContextWithCustomTransportLayer CreateTransportLayerContext(string payload, string odataVersion)
        {
            IODataRequestMessage requestMessage = new ODataTestMessage();
            var responseMessage = new ODataTestMessage();

            responseMessage.SetHeader("Content-Type", "application/json");
            responseMessage.SetHeader("OData-Version", odataVersion);
            responseMessage.StatusCode = 200;
            responseMessage.WriteToStream(payload);
            responseMessage.SetHeader("Content-Length", responseMessage.MemoryStream.Length.ToString());

            var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, requestMessage, responseMessage);

            context.ResolveName = ResolveName;
            context.ResolveType = ResolveType;
            context.Format.UseJson(Model);
            return(context);
        }
        private DataServiceContextWithCustomTransportLayer CreateTransportLayerContext(string payload, string odataVersion)
        {
            IODataRequestMessage requestMessage = new ODataTestMessage();
            var responseMessage = new ODataTestMessage();
            responseMessage.SetHeader("Content-Type", "application/json");
            responseMessage.SetHeader("OData-Version", odataVersion);
            responseMessage.StatusCode = 200;
            responseMessage.WriteToStream(payload);
            responseMessage.SetHeader("Content-Length", responseMessage.MemoryStream.Length.ToString());

            var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, requestMessage, responseMessage);
            context.ResolveName = ResolveName;
            context.ResolveType = ResolveType;
            context.Format.UseJson(Model);
            return context;
        }