public void Ctor_IEnumerable_Works() { // Workaround xunit/xunit#987: InvalidOperationException thrown if this is in MemberData JsonValue[] items = new JsonValue[] { new JsonPrimitive(true) }; JsonArray array = new JsonArray((IEnumerable<JsonValue>)items); Assert.Equal(1, array.Count); Assert.Same(items[0], array[0]); }
private static void VerifyJsonArray(JsonArray array, JsonValue[] values) { Assert.Equal(values.Length, array.Count); for (int i = 0; i < values.Length; i++) { Assert.Equal(values[i], array[i]); } }
public void convert_large_number_to_json() { var obj = new JsonObject(); obj["value"] = new JsonValue(long.MaxValue); var json = obj.ToString(); obj = JsonObject.Parse(json); ((JsonValue)obj["value"]).Value.ShouldEqual(long.MaxValue); }
public JsonArray(JsonValue[] array, int line, int column) : base(line, column) { if (array == null) { throw new ArgumentNullException(nameof(array)); } _array = array; }
public void general_case() { var jobject = new JsonObject(); jobject["name"] = new JsonValue("test"); jobject["value"] = new JsonValue(1); jobject["list"] = new JsonArray { new JsonValue(5), new JsonValue("test") }; var json = jobject.ToString(); json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}"); }
public void compare_string_and_data_json_values() { JsonValue value1 = new JsonValue("2000-01-01"), value2 = new JsonValue(new DateTime(2000, 1, 1)); value1.ShouldEqual(value2); }
public void compare_string_json_values() { JsonValue value1 = new JsonValue("test"), value2 = new JsonValue("test"); value1.ShouldEqual(value2); }
public void compare_int_json_values() { JsonValue value1 = new JsonValue(100), value2 = new JsonValue(100); value1.ShouldEqual(value2); }
public void compare_null_json_values() { JsonValue value1 = new JsonValue(), value2 = new JsonValue(); value1.ShouldEqual(value2); }
public void compare_diff_float_and_int_json_values() { JsonValue value1 = new JsonValue(10.1), value2 = new JsonValue(10); value1.ShouldNotEqual(value2); }
public void CopyTo(int arrayIndex) { JsonArray array = new JsonArray(new JsonPrimitive(true)); JsonValue[] copy = new JsonValue[array.Count + arrayIndex]; array.CopyTo(copy, arrayIndex); for (int i = 0; i < arrayIndex; i++) { Assert.Null(copy[i]); } for (int i = arrayIndex; i < copy.Length; i++) { Assert.Same(array[i - arrayIndex], copy[i]); } }
public void crete_json_with_properties() { var jobject = new JsonObject(); jobject["test"] = new JsonValue("test"); jobject["my_val"] = new JsonValue(10); jobject.ToString().ShouldEqual("{\"test\":\"test\",\"my_val\":10}"); }
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); } }
public void create_int_json_value() { var value = new JsonValue(100); value.ToString().ShouldEqual("100"); value.Kind.ShouldEqual(JsonElement.Number); value.Value.ShouldEqual(100L); }
public void create_null_json_value() { var value = new JsonValue(); value.ToString().ShouldEqual("null"); value.Kind.ShouldEqual(JsonElement.Null); value.Value.ShouldBeNull(); }
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); }
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)); }
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))); }
public void Ctor(JsonValue[] items) { VerifyJsonArray(new JsonArray(items), items); VerifyJsonArray(new JsonArray((IEnumerable<JsonValue>)items), items); }
public void create_json_object_with_false_property() { var jobject = new JsonObject(); jobject["test"] = new JsonValue(false); jobject.ToString().ShouldEqual("{\"test\":false}"); }
public void create_boolean_json_value() { var value = new JsonValue(true); value.ToString().ShouldEqual("true"); value.Kind.ShouldEqual(JsonElement.Boolean); value.Value.ShouldEqual(true); }
public void create_json_object_with_string_type_property() { var jobject = new JsonObject(); jobject["test"] = new JsonValue("test"); jobject.ToString().ShouldEqual("{\"test\":\"test\"}"); }
public void create_string_json_value() { var value = new JsonValue("test"); value.ToString().ShouldEqual("\"test\""); value.Kind.ShouldEqual(JsonElement.String); value.Value.ShouldEqual("test"); }
public void RemoveAt() { JsonValue[] items = new JsonValue[] { new JsonPrimitive(true) }; JsonArray array = new JsonArray((IEnumerable<JsonValue>)items); array.RemoveAt(0); Assert.Equal(0, array.Count); }
public void create_json_object_with_date_type_property() { var jobject = new JsonObject(); jobject["test"] = new JsonValue(new DateTime(2012, 3, 1)); jobject.ToString().ShouldEqual("{\"test\":\"2012-03-01\"}"); }
public void persist_decimal_point_for_float_json_values() { var value = new JsonValue(10.000); value.ToString().ShouldEqual("10.0"); }
public void create_json_object_with_float_type_property() { var jobject = new JsonObject(); jobject["test"] = new JsonValue(10F); jobject.ToString().ShouldEqual("{\"test\":10.0}"); }
public void persist_exp_for_float_json_values() { var value = new JsonValue(1e100); value.ToString().ShouldEqual("1E+100"); }
public void compare_float_json_values() { JsonValue value1 = new JsonValue(1.1), value2 = new JsonValue(1.1); value1.ShouldEqual(value2); }
public void Contains() { JsonValue[] items = new JsonValue[] { new JsonPrimitive(true) }; JsonArray array = new JsonArray((IEnumerable<JsonValue>)items); Assert.True(array.Contains(items[0])); Assert.False(array.Contains(new JsonPrimitive(false))); }