public static void PopulateObjectWithHeaderComment() { string json = @"{""prop"": 1.0}"; PopulateTestObject o = new PopulateTestObject(); JsonConvert.PopulateObject(json, o); Assert.True(1m == o.Prop, "Decimal property from deserialized json reflected into object."); }
public void PopulateObjectWithNoContentThrows() { Assert.Throws <JsonSerializationException>(Test, "No JSON content found. Path '', line 0, position 0."); void Test() { const string json = @""; var o = new PopulateTestObject(); JsonConvert.PopulateObject(json, o); } }
public void PopulateObjectWithHeaderCommentSucceeds() { const string json = @"// file header { ""prop"": 1.0 }"; var o = new PopulateTestObject(); JsonConvert.PopulateObject(json, o); Assert.AreEqual(1m, o.Prop); }
public void PopulateObjectWithOnlyCommentThrows() { var ex = Assert.Throws <JsonSerializationException>(Test, "No JSON content found. Path '', line 1, position 14."); Assert.AreEqual(1, ex.LineNumber); Assert.AreEqual(14, ex.LinePosition); Assert.AreEqual(string.Empty, ex.Path); void Test() { const string json = @"// file header"; var o = new PopulateTestObject(); JsonConvert.PopulateObject(json, o); } }