-Added JsonDictionaryAttribute
-Added JsonContainerContract -Added support for customizing the JsonConverter, type name handling, reference handling of collection items
This commit is contained in:
@@ -50,70 +50,6 @@ namespace Newtonsoft.Json.Tests
|
||||
[TestFixture]
|
||||
public class JsonConvertTest : TestFixtureBase
|
||||
{
|
||||
#if Entities
|
||||
[Test]
|
||||
public void EntitiesTest()
|
||||
{
|
||||
Purchase purchase = new Purchase() { Id = 1 };
|
||||
purchase.PurchaseLine.Add(new PurchaseLine() { Id = 1, Purchase = purchase });
|
||||
purchase.PurchaseLine.Add(new PurchaseLine() { Id = 2, Purchase = purchase });
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
|
||||
using (JsonWriter jw = new JsonTextWriter(sw))
|
||||
{
|
||||
jw.Formatting = Formatting.Indented;
|
||||
|
||||
serializer.Serialize(jw, purchase);
|
||||
}
|
||||
|
||||
string json = sw.ToString();
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Id"": 1,
|
||||
""PurchaseLine"": [
|
||||
{
|
||||
""Id"": 1,
|
||||
""PurchaseReference"": {
|
||||
""EntityKey"": null,
|
||||
""RelationshipName"": ""EntityDataModel.PurchasePurchaseLine"",
|
||||
""SourceRoleName"": ""PurchaseLine"",
|
||||
""TargetRoleName"": ""Purchase"",
|
||||
""RelationshipSet"": null,
|
||||
""IsLoaded"": false
|
||||
},
|
||||
""EntityState"": 1,
|
||||
""EntityKey"": null
|
||||
},
|
||||
{
|
||||
""Id"": 2,
|
||||
""PurchaseReference"": {
|
||||
""EntityKey"": null,
|
||||
""RelationshipName"": ""EntityDataModel.PurchasePurchaseLine"",
|
||||
""SourceRoleName"": ""PurchaseLine"",
|
||||
""TargetRoleName"": ""Purchase"",
|
||||
""RelationshipSet"": null,
|
||||
""IsLoaded"": false
|
||||
},
|
||||
""EntityState"": 1,
|
||||
""EntityKey"": null
|
||||
}
|
||||
],
|
||||
""EntityState"": 1,
|
||||
""EntityKey"": null
|
||||
}", json);
|
||||
|
||||
Purchase newPurchase = JsonConvert.DeserializeObject<Purchase>(json);
|
||||
Assert.AreEqual(1, newPurchase.Id);
|
||||
|
||||
Assert.AreEqual(2, newPurchase.PurchaseLine.Count);
|
||||
Assert.AreEqual(1, newPurchase.PurchaseLine.ElementAt(0).Id);
|
||||
Assert.AreEqual(2, newPurchase.PurchaseLine.ElementAt(1).Id);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DeserializeObject_EmptyString()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user