Exemplo n.º 1
0
 private static void AdvanceReaderToFirstProperty(BufferingJsonReader bufferingJsonReader)
 {
     // Read start and then over the object start.
     bufferingJsonReader.Read();
     bufferingJsonReader.Read();
     bufferingJsonReader.NodeType.Should().Be(JsonNodeType.Property);
 }
Exemplo n.º 2
0
        public void StartBufferingAndTryToReadInStreamErrorPropertyValue_Works()
        {
            // Arrange
            const string payload =
                @"{""code"":"""",""message"":"""",""target"":""any target"","
                + @"""details"":[{""code"":""500"",""target"":""another target"",""message"":""any msg""}]}";
            var        stringReader = new StringReader(payload);
            var        innerReader  = new JsonReader(stringReader, false);
            var        jsonReader   = new BufferingJsonReader(innerReader, "any", 0);
            ODataError error;

            // Act
            jsonReader.Read();
            var result = jsonReader.StartBufferingAndTryToReadInStreamErrorPropertyValue(out error);

            // Assert
            Assert.True(result);
            Assert.Equal("any target", error.Target);
            Assert.Equal(1, error.Details.Count);
            var detail = error.Details.Single();

            Assert.Equal("500", detail.ErrorCode);
            Assert.Equal("another target", detail.Target);
            Assert.Equal("any msg", detail.Message);
        }
        private static void AdvanceReaderToFirstPropertyValue(BufferingJsonReader bufferingJsonReader)
        {
            AdvanceReaderToFirstProperty(bufferingJsonReader);

            // Read over property name
            bufferingJsonReader.Read();
        }
Exemplo n.º 4
0
            /// <summary>
            /// Peeks and collects a raw annotation value from BufferingJsonReader.
            /// </summary>
            /// <param name="jsonReader">The BufferingJsonReader.</param>
            /// <param name="propertyName">The property name.</param>
            /// <param name="annotationName">The annotation name.</param>
            private void PeekAndCollectAnnotationRawJson(
                BufferingJsonReader jsonReader,
                string propertyName,
                string annotationName)
            {
                if (jsonReader.IsBuffering)
                {
                    return; // only need to collect annotation for not-buffering pass reading.
                }

                try
                {
                    jsonReader.StartBuffering();
                    if (jsonReader.NodeType == JsonNodeType.Property)
                    {
                        jsonReader.Read(); // read over annotation name
                    }

                    StringBuilder builder = new StringBuilder();
                    jsonReader.SkipValue(builder);
                    string annotationRawJson = builder.ToString();
                    this.AddPropertyAnnotationRawJson(propertyName, annotationName, annotationRawJson);
                }
                finally
                {
                    jsonReader.StopBuffering();
                }
            }