Beispiel #1
0
        private void ToString(JsonValue primitive, string expected)
        {
            Assert.Equal(expected, primitive.ToString());

            using (StringWriter textWriter = new StringWriter())
            {
                primitive.Save(textWriter);
                Assert.Equal(expected, textWriter.ToString());
            }

            using (MemoryStream stream = new MemoryStream())
            {
                primitive.Save(stream);
                string result = Encoding.UTF8.GetString(stream.ToArray());
                Assert.Equal(expected, result);
            }
        }
Beispiel #2
0
 public void persist_exp_for_float_json_values()
 {
     var value = new JsonValue(1e100);
     value.ToString().ShouldEqual("1E+100");
 }
Beispiel #3
0
        public void create_boolean_json_value()
        {
            var value = new JsonValue(true);

            value.ToString().ShouldEqual("true");
            value.Kind.ShouldEqual(JsonElement.Boolean);
            value.Value.ShouldEqual(true);
        }
Beispiel #4
0
        public void create_string_json_value()
        {
            var value = new JsonValue("test");

            value.ToString().ShouldEqual("\"test\"");
            value.Kind.ShouldEqual(JsonElement.String);
            value.Value.ShouldEqual("test");
        }
Beispiel #5
0
 public void persist_decimal_point_for_float_json_values()
 {
     var value = new JsonValue(10.000);
     value.ToString().ShouldEqual("10.0");
 }
Beispiel #6
0
        public void create_null_json_value()
        {
            var value = new JsonValue();

            value.ToString().ShouldEqual("null");
            value.Kind.ShouldEqual(JsonElement.Null);
            value.Value.ShouldBeNull();
        }
Beispiel #7
0
        public void create_int_json_value()
        {
            var value = new JsonValue(100);

            value.ToString().ShouldEqual("100");
            value.Kind.ShouldEqual(JsonElement.Number);
            value.Value.ShouldEqual(100L);
        }
Beispiel #8
0
        public void create_float_json_value()
        {
            var value = new JsonValue(1.1);

            value.ToString().ShouldEqual("1.1");
            value.Kind.ShouldEqual(JsonElement.Number);
            value.Value.ShouldEqual(1.1D);
        }
Beispiel #9
0
        public void create_date_json_value()
        {
            var value = new JsonValue(new DateTime(2000, 1, 1));

            value.ToString().ShouldEqual("\"2000-01-01\"");
            value.Kind.ShouldEqual(JsonElement.String);
            value.Value.ShouldEqual(new DateTime(2000, 1, 1));
        }
Beispiel #10
0
        public void create_datetime_offset_json_value()
        {
            var value = new JsonValue(new DateTimeOffset(2000, 1, 1, 12, 59, 59, new TimeSpan(4, 0, 0)));

            value.ToString().ShouldEqual("\"2000-01-01T12:59:59+04:00\"");
            value.Kind.ShouldEqual(JsonElement.String);
            value.Value.ShouldEqual(new DateTimeOffset(2000, 1, 1, 12, 59, 59, new TimeSpan(4, 0, 0)));
        }