示例#1
0
        public void op_Boolean_string_whenTrue()
        {
            const string name = "name";

            var document = new JsonObject
                               {
                                   new JsonPair(name, new JsonTrue())
                               };

            Assert.True(document.Boolean(name));
        }
示例#2
0
        public void op_ReadJson_JsonReader(string json)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(json);
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new JsonReader(stream))
                    {
                        reader.Read();

                        var obj = new JsonObject();
                        obj.ReadJson(reader);

                        Assert.Equal("value", obj.String("name").Value);
                        Assert.Equal("1", obj.Array("range").Number(0).Value);
                        Assert.Equal("2", obj.Array("range").Number(1).Value);
                        Assert.Equal("3", obj.Array("range").Number(2).Value);
                        Assert.Equal("123", obj.Number("id").Value);
                        Assert.True(obj.Boolean("visible"));
                        Assert.False(obj.Boolean("enabled"));
                        Assert.Null(obj.String("check"));
                        Assert.Equal("1.23", obj.Object("child").Number("value").Value);
                    }
                }
            }
        }
示例#3
0
        public void op_Boolean_string_whenInvalidCastException()
        {
            const string name = "name";

            var document = new JsonObject
                               {
                                   new JsonPair(name, new JsonNull())
                               };

            Assert.Throws<InvalidCastException>(() => document.Boolean(name));
        }