예제 #1
0
        public void JsonWriter_WithSimpleInteger_ShouldCreateCorrectJson()
        {
            var writer = new Core.Services.JsonWriter();

            writer.SetValue("age", 34);
            var json = writer.ToJson();
            var root = JsonDocument.Parse(json).RootElement;

            Assert.Equal(34, root.GetProperty("age").GetInt32());
        }
예제 #2
0
        public void JsonWriter_WithNestedObject_ShouldCreateCorrectJson()
        {
            var writer = new Core.Services.JsonWriter();

            writer.SetValue("addr.area.city", "Tabriz");
            var json = writer.ToJson();
            var root = JsonDocument.Parse(json).RootElement;

            Assert.Equal("Tabriz", root.GetProperty("addr").GetProperty("area").GetProperty("city").GetString());
        }
예제 #3
0
        public void JsonWriter_WithSimpleString_ShouldCreateCorrectJson()
        {
            var writer = new Core.Services.JsonWriter();

            writer.SetValue("name", "Yashar");
            var json = writer.ToJson();
            var root = JsonDocument.Parse(json).RootElement;

            Assert.Equal("Yashar", root.GetProperty("name").GetString());
        }
예제 #4
0
        public void JsonWriter_WithArray_ShouldCreateCorrectJson()
        {
            var writer = new Core.Services.JsonWriter();

            writer.AddItemToArray("items", new Core.Models.JsonValue {
                Name = "name", Value = "\"Item1\""
            });
            writer.AddItemToArray("items", new Core.Models.JsonValue {
                Name = "name", Value = "\"Item2\""
            });
            var json = writer.ToJson();
            var root = JsonDocument.Parse(json).RootElement;

            Assert.Equal(2, root.GetProperty("items").GetArrayLength());
            Assert.Equal("Item1", root.GetProperty("items").EnumerateArray().ToList().First().GetProperty("name").GetString());
            Assert.Equal("Item2", root.GetProperty("items").EnumerateArray().ToList()[1].GetProperty("name").GetString());
        }