public void TestCreateArray_WithObject() { var result = JsonValue.CreateArray() .AddObject(JsonValue.CreateObject().AddString("mystring", "my value")); Assert.AreEqual(JsonValueType.Array, result.ValueType); Assert.AreEqual(JsonValueType.Object, result.Values[0].ValueType); Assert.AreEqual(JsonValueType.String, ((JsonObject)result.Values[0]).Values["mystring"].ValueType); Assert.AreEqual("my value", ((JsonString)((JsonObject)result.Values[0]).Values["mystring"]).Value); }
public void TestGetArray() { var service = this.GetService(); var result = service.ToArray(JsonValue.CreateArray() .AddString("a") .AddNumber(10) .AddBool(true) .AddNullable(null)); Assert.AreEqual("[\"a\",10,true,null]", result); }
public void TestCreateArray_WithArray() { var result = JsonValue.CreateArray() .AddArray(JsonValue.CreateArray().AddString("my value")); Assert.AreEqual(JsonValueType.Array, result.ValueType); Assert.AreEqual(JsonValueType.Array, result.Values[0].ValueType); var innerArray = result.Values[0] as JsonArray; Assert.AreEqual(JsonValueType.String, innerArray.Values[0].ValueType); Assert.AreEqual("my value", ((JsonString)innerArray.Values[0]).Value); }
public void TestCreateArray() { var result = JsonValue.CreateArray() .AddString("my string") .AddNumber(10) .AddBool(true) .AddNullable(null); Assert.AreEqual(JsonValueType.Array, result.ValueType); Assert.AreEqual("my string", ((JsonString)result.Values[0]).Value); Assert.AreEqual(10, ((JsonNumber)result.Values[1]).Value); Assert.AreEqual(true, ((JsonBool)result.Values[2]).Value); Assert.AreEqual(null, ((JsonNullable)result.Values[3]).Value); }
public void TestCreateObject_WithInnerArray() { var result = JsonValue.CreateObject() .AddString("mystring", "my value") .AddArray("myarray", JsonValue.CreateArray().AddString("a").AddString("b")); Assert.AreEqual(JsonValueType.Object, result.ValueType); Assert.AreEqual("my value", ((JsonString)result.Values["mystring"]).Value); Assert.AreEqual(JsonValueType.String, result.Values["mystring"].ValueType); Assert.AreEqual(JsonValueType.Array, result.Values["myarray"].ValueType); Assert.AreEqual(JsonValueType.String, ((JsonArray)result.Values["myarray"]).Values[0].ValueType); Assert.AreEqual("a", ((JsonString)((JsonArray)result.Values["myarray"]).Values[0]).Value); Assert.AreEqual(JsonValueType.String, ((JsonArray)result.Values["myarray"]).Values[1].ValueType); Assert.AreEqual("b", ((JsonString)((JsonArray)result.Values["myarray"]).Values[1]).Value); }