Exemplo n.º 1
0
        public void WriteNestedEmptyMap()
        {
            var outputStream = new MemoryStream();
            var writer       = new JsonParseNodeWriter(outputStream);

            writer.WriteStartDocument();
            writer.WriteStartMap();
            writer.WritePropertyName("intro");
            writer.WriteStartMap();
            writer.WriteEndMap();

            writer.WritePropertyName("outro");
            writer.WriteStartMap();
            writer.WriteStringProperty("good", "bye");
            writer.WriteEndMap();

            writer.WriteEndMap();
            writer.WriteEndDocument();
            writer.Flush();

            outputStream.Position = 0;
            var json    = new StreamReader(outputStream).ReadToEnd();
            var jObject = JObject.Parse(json);

            Assert.Equal("bye", jObject["outro"]["good"]);
        }
Exemplo n.º 2
0
        public void WriteList()
        {
            var outputStream = new MemoryStream();
            var writer       = new JsonParseNodeWriter(outputStream);

            writer.WriteStartDocument();
            writer.WriteStartList();
            writer.WriteListItem("hello", (w, s) => w.WriteValue(s));
            writer.WriteListItem("world", (w, s) => w.WriteValue(s));
            writer.WriteEndList();
            writer.WriteEndDocument();
            writer.Flush();

            outputStream.Position = 0;
            var json   = new StreamReader(outputStream).ReadToEnd();
            var jarray = JArray.Parse(json);

            Assert.Equal(2, jarray.Count);
        }
Exemplo n.º 3
0
        public void WriteMap()
        {
            var outputStream = new MemoryStream();
            var writer       = new JsonParseNodeWriter(outputStream);

            writer.WriteStartDocument();
            writer.WriteStartMap();
            writer.WriteStringProperty("hello", "world");
            writer.WriteStringProperty("good", "bye");
            writer.WriteEndMap();
            writer.WriteEndDocument();
            writer.Flush();

            outputStream.Position = 0;
            var json    = new StreamReader(outputStream).ReadToEnd();
            var jObject = JObject.Parse(json);

            Assert.Equal("world", jObject["hello"]);
        }