public void Object_should_be_correct_format() { var data = new SimplePoco { Name = "abc", Id = 999 }; var json = JsonSerializer.ToJson(data); Assert.IsTrue(JsonValidator.IsValid(json)); Assert.AreEqual("{\"Name\":\"abc\",\"Id\":999}", json); //begin-object = ws %x7B ws; { left curly bracket Assert.IsTrue(json.StartsWith("{")); //end-array = ws %x7D ws;} right curly bracket Assert.IsTrue(json.EndsWith("}")); //name-separator = ws %x3A ws; : colon //value - separator = ws % x2C ws; , comma var splitarray = json.Split('\"'); Assert.AreEqual(":", splitarray[2]); Assert.AreEqual(",", splitarray[4]); }
public void Unassigned_object_should_be_serialize_to_correct_format() { var data = new SimplePoco(); var json = JsonSerializer.ToJson(data); Assert.IsTrue(JsonValidator.IsValid(json)); Assert.AreEqual("{\"Name\":null,\"Id\":0}", json); }
public void Assigned_object_should_be_serialize_to_correct_format() { var data = new SimplePoco { Name = "武汉abc", Id = 1 }; var json = JsonSerializer.ToJson(data); Assert.IsTrue(JsonValidator.IsValid(json)); Assert.AreEqual("{\"Name\":\"武汉abc\",\"Id\":1}", json); }
public void Values_null_should_be_an_null() { var obj = new SimplePoco { Name = null, Id = 3 }; var json = JsonSerializer.ToJson(obj); Assert.IsTrue(JsonValidator.IsValid(json)); Assert.AreEqual("{\"Name\":null,\"Id\":3}", json); var newobj = JsonSerializer.ToObject <SimplePoco>(json); Assert.IsTrue(newobj.Name is null); }
public void Values_object_should_be_an_object() { var obj = new SimplePoco { Name = "武汉abc", Id = 2 }; var json = JsonSerializer.ToJson(new { val = obj }); Assert.IsTrue(JsonValidator.IsValid(json)); Assert.AreEqual("{\"val\":{\"Name\":\"武汉abc\",\"Id\":2}}", json); object newobj = JsonSerializer.ToObject <object>(json); var type = ((Json.JObject)newobj)["val"].GetType().Name; Assert.IsTrue(type == "JObject"); }
public void Values_string_should_be_an_string() { var str = "武汉abc"; var obj = new SimplePoco { Name = str, Id = 2 }; var json = JsonSerializer.ToJson(obj); Assert.IsTrue(JsonValidator.IsValid(json)); Assert.AreEqual("{\"Name\":\"武汉abc\",\"Id\":2}", json); var newobj = JsonSerializer.ToObject <SimplePoco>(json); Assert.AreEqual(newobj.Name, str); }
public void Ordering_object_should_not_be_affect_format() { var positivedata = new SimplePoco { Name = "武汉abc", Id = 1 }; var positivejson = JsonSerializer.ToJson(positivedata); Assert.IsTrue(JsonValidator.IsValid(positivejson)); var reversedata = new SimplePoco { Id = 1, Name = "武汉abc" }; var reversejson = JsonSerializer.ToJson(reversedata); Assert.IsTrue(JsonValidator.IsValid(reversejson)); Assert.AreEqual(positivejson, reversejson); }