-Tests
This commit is contained in:
+8
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class CustomContractResolver
|
||||
[TestFixture]
|
||||
public class CustomContractResolver : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class DynamicContractResolver : DefaultContractResolver
|
||||
@@ -67,6 +69,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -93,6 +96,10 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "LastName": "Deepwater-Diver"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""LastName"": ""Deepwater-Diver""
|
||||
}", startingWithL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class CustomJsonConverter
|
||||
[TestFixture]
|
||||
public class CustomJsonConverter : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class KeysJsonConverter : JsonConverter
|
||||
@@ -86,6 +88,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -120,6 +123,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(newEmployee.FirstName);
|
||||
// James
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("James", newEmployee.FirstName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,12 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class CustomTraceWriter
|
||||
[TestFixture]
|
||||
public class CustomTraceWriter : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class NLogTraceWriter : ITraceWriter
|
||||
@@ -77,6 +79,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -101,6 +104,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "China"
|
||||
// ]
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
""New Zealand"",
|
||||
""Australia"",
|
||||
""Denmark"",
|
||||
""China""
|
||||
]", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DataContractAndDataMember
|
||||
[TestFixture]
|
||||
public class DataContractAndDataMember : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
[DataContract]
|
||||
@@ -49,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -67,6 +70,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Size": 51200
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""ImportantLegalDocuments.docx"",
|
||||
""Size"": 51200
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DefaultValueAttributeIgnore
|
||||
[TestFixture]
|
||||
public class DefaultValueAttributeIgnore : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Customer
|
||||
@@ -47,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -69,6 +72,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(jsonIgnoreDefaultValues);
|
||||
// {}
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("{}", jsonIgnoreDefaultValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DefaultValueHandlingIgnore
|
||||
[TestFixture]
|
||||
public class DefaultValueHandlingIgnore : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Person
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -65,6 +68,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(jsonIgnoreDefaultValues);
|
||||
// {}
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("{}", jsonIgnoreDefaultValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeAnonymousType
|
||||
[TestFixture]
|
||||
public class DeserializeAnonymousType : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -49,6 +52,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(customer2.Name);
|
||||
// Mike
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Mike", customer2.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeCollection
|
||||
[TestFixture]
|
||||
public class DeserializeCollection : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -42,6 +45,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(string.Join(", ", videogames));
|
||||
// Starcraft, Halo, Legend of Zelda
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Starcraft, Halo, Legend of Zelda", string.Join(", ", videogames));
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeConstructorHandling
|
||||
[TestFixture]
|
||||
public class DeserializeConstructorHandling : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Website
|
||||
@@ -52,6 +54,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -61,7 +64,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
JsonConvert.DeserializeObject<Website>(json);
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
// Value cannot be null.
|
||||
@@ -76,6 +79,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(website.Url);
|
||||
// http://www.google.com
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("http://www.google.com", website.Url);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeCustomCreationConverter
|
||||
[TestFixture]
|
||||
public class DeserializeCustomCreationConverter : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Person
|
||||
@@ -56,6 +58,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -75,8 +78,10 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Employee employee = (Employee)person;
|
||||
|
||||
Console.WriteLine(employee.JobTitle);
|
||||
// Capenter
|
||||
// Carpenter
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Carpenter", employee.JobTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,14 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeDataSet
|
||||
[TestFixture]
|
||||
public class DeserializeDataSet : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -63,6 +66,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// 0 - item 0
|
||||
// 1 - item 1
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(2, dataTable.Rows.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeDictionary
|
||||
[TestFixture]
|
||||
public class DeserializeDictionary : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -48,6 +51,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(htmlAttributes["target"]);
|
||||
// _blank
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("_blank", htmlAttributes["target"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeMissingMemberHandling
|
||||
[TestFixture]
|
||||
public class DeserializeMissingMemberHandling : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -40,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeObject
|
||||
[TestFixture]
|
||||
public class DeserializeObject : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -60,6 +63,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(account.Email);
|
||||
// james@example.com
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("james@example.com", account.Email);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeObjectCreationHandling
|
||||
[TestFixture]
|
||||
public class DeserializeObjectCreationHandling : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class UserViewModel
|
||||
@@ -50,6 +52,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -88,6 +91,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// Wellington
|
||||
// Christchurch
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(3, model2.Offices.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-1
@@ -28,11 +28,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class DeserializeWithJsonSerializerFromFile
|
||||
[TestFixture]
|
||||
public class DeserializeWithJsonSerializerFromFile : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Movie
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -56,5 +59,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class File
|
||||
{
|
||||
public static string ReadAllText(string s)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public static StreamReader OpenText(string s)
|
||||
{
|
||||
return new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("{}")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -29,10 +29,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class ErrorHandlingAttribute
|
||||
[TestFixture]
|
||||
public class ErrorHandlingAttribute : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Employee
|
||||
@@ -64,6 +66,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -84,6 +87,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Title": "Mister Manager"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""George Michael Bluth"",
|
||||
""Age"": 16,
|
||||
""Title"": ""Mister Manager""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class ErrorHandlingEvent
|
||||
[TestFixture]
|
||||
public class ErrorHandlingEvent : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -67,6 +70,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// Unexpected token parsing date. Expected String, got StartArray.
|
||||
// Cannot convert null value to System.DateTime.
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(3, errors.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonConverterAttributeClass
|
||||
[TestFixture]
|
||||
public class JsonConverterAttributeClass : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class UserConverter : JsonConverter
|
||||
@@ -64,6 +66,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -77,6 +80,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(json);
|
||||
// "domain\\username"
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"""domain\\username""", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonConverterAttributeProperty
|
||||
[TestFixture]
|
||||
public class JsonConverterAttributeProperty : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public enum UserStatus
|
||||
@@ -50,6 +52,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -67,6 +70,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Status": "Deleted"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""UserName"": ""domain\\username"",
|
||||
""Status"": ""Deleted""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonObjectAttributeOptIn
|
||||
[TestFixture]
|
||||
public class JsonObjectAttributeOptIn : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
@@ -48,6 +50,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -66,6 +69,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Size": 51200
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""ImportantLegalDocuments.docx"",
|
||||
""Size"": 51200
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonObjectAttributeOverrideIEnumerable
|
||||
[TestFixture]
|
||||
public class JsonObjectAttributeOverrideIEnumerable : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
[JsonObject]
|
||||
@@ -57,6 +59,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -81,6 +84,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// ]
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""My Documents"",
|
||||
""Files"": [
|
||||
""ImportantLegalDocuments.docx"",
|
||||
""WiseFinancalAdvice.xlsx""
|
||||
]
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonPropertyItemLevelSetting
|
||||
[TestFixture]
|
||||
public class JsonPropertyItemLevelSetting : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Business
|
||||
@@ -50,6 +52,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -94,6 +97,24 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// ]
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""Acme Ltd."",
|
||||
""Employees"": [
|
||||
{
|
||||
""$id"": ""1"",
|
||||
""Name"": ""George-Michael"",
|
||||
""Manager"": null
|
||||
},
|
||||
{
|
||||
""$id"": ""2"",
|
||||
""Name"": ""Maeby"",
|
||||
""Manager"": {
|
||||
""$ref"": ""1""
|
||||
}
|
||||
}
|
||||
]
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonPropertyName
|
||||
[TestFixture]
|
||||
public class JsonPropertyName : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Videogame
|
||||
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -60,6 +63,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "release_date": "1998-01-01T00:00:00"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""name"": ""Starcraft"",
|
||||
""release_date"": ""1998-01-01T00:00:00""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonPropertyOrder
|
||||
[TestFixture]
|
||||
public class JsonPropertyOrder : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -53,6 +55,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -78,6 +81,15 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "DeletedDate": "2013-01-25T00:00:00"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""FullName"": ""Aaron Account"",
|
||||
""EmailAddress"": ""aaron@example.com"",
|
||||
""CreatedDate"": ""2010-10-01T00:00:00"",
|
||||
""UpdatedDate"": ""2013-01-25T00:00:00"",
|
||||
""Deleted"": true,
|
||||
""DeletedDate"": ""2013-01-25T00:00:00""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonPropertyPropertyLevelSetting
|
||||
[TestFixture]
|
||||
public class JsonPropertyPropertyLevelSetting : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Vessel
|
||||
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -60,6 +63,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Class": "Typhoon"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""Red October"",
|
||||
""Class"": ""Typhoon""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class JsonPropertyRequired
|
||||
[TestFixture]
|
||||
public class JsonPropertyRequired : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Videogame
|
||||
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
|
||||
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class MaxDepth
|
||||
[TestFixture]
|
||||
public class MaxDepth : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
|
||||
+9
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class NullValueHandlingIgnore
|
||||
[TestFixture]
|
||||
public class NullValueHandlingIgnore : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Person
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -72,6 +75,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Age": 1
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""Nigal Newborn"",
|
||||
""Age"": 1
|
||||
}", jsonIgnoreNullValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class PopulateObject
|
||||
[TestFixture]
|
||||
public class PopulateObject : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -75,6 +78,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(string.Join(", ", account.Roles));
|
||||
// User, Admin, Expired
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("User, Admin, Expired", string.Join(", ", account.Roles));
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class PreserveReferencesHandlingObject
|
||||
[TestFixture]
|
||||
public class PreserveReferencesHandlingObject : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Directory
|
||||
@@ -47,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -122,6 +125,26 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// ]
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""$id"": ""1"",
|
||||
""Name"": ""My Documents"",
|
||||
""Parent"": {
|
||||
""$id"": ""2"",
|
||||
""Name"": ""Root"",
|
||||
""Parent"": null,
|
||||
""Files"": null
|
||||
},
|
||||
""Files"": [
|
||||
{
|
||||
""$id"": ""3"",
|
||||
""Name"": ""ImportantLegalDocument.docx"",
|
||||
""Parent"": {
|
||||
""$ref"": ""1""
|
||||
}
|
||||
}
|
||||
]
|
||||
}", preserveReferenacesObjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class PropertyJsonIgnore
|
||||
[TestFixture]
|
||||
public class PropertyJsonIgnore : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -58,6 +61,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(json);
|
||||
// {"FullName":"Joe User","EmailAddress":"joe@example.com"}
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{""FullName"":""Joe User"",""EmailAddress"":""joe@example.com""}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class ReferenceLoopHandlingIgnore
|
||||
[TestFixture]
|
||||
public class ReferenceLoopHandlingIgnore : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Employee
|
||||
@@ -40,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -61,6 +64,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""Joe User"",
|
||||
""Manager"": {
|
||||
""Name"": ""Mike Manager""
|
||||
}
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializationCallbackAttributes
|
||||
[TestFixture]
|
||||
public class SerializationCallbackAttributes : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class SerializationEventTestObject
|
||||
@@ -86,6 +88,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -127,6 +130,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(obj.Member4);
|
||||
// This value was set after deserialization.
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("This value was set after deserialization.", obj.Member4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeCollection
|
||||
[TestFixture]
|
||||
public class SerializeCollection : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -47,6 +50,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(json);
|
||||
// ["Starcraft","Halo","Legend of Zelda"]
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"[""Starcraft"",""Halo"",""Legend of Zelda""]", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeConditionalProperty
|
||||
[TestFixture]
|
||||
public class SerializeConditionalProperty : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Employee
|
||||
@@ -46,6 +48,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -75,6 +78,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// }
|
||||
// ]
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""Joe Employee"",
|
||||
""Manager"": {
|
||||
""Name"": ""Mike Manager""
|
||||
}
|
||||
},
|
||||
{
|
||||
""Name"": ""Mike Manager""
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeContractResolver
|
||||
[TestFixture]
|
||||
public class SerializeContractResolver : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Person
|
||||
@@ -46,6 +48,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -67,6 +70,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "fullName": "Sarah Security"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""firstName"": ""Sarah"",
|
||||
""lastName"": ""Security"",
|
||||
""fullName"": ""Sarah Security""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,14 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeDataSet
|
||||
[TestFixture]
|
||||
public class SerializeDataSet : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -71,6 +75,19 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// ]
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Table1"": [
|
||||
{
|
||||
""id"": 0,
|
||||
""item"": ""item 0""
|
||||
},
|
||||
{
|
||||
""id"": 1,
|
||||
""item"": ""item 1""
|
||||
}
|
||||
]
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeDateFormatHandling
|
||||
[TestFixture]
|
||||
public class SerializeDateFormatHandling : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -50,6 +53,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(jsonMsDate);
|
||||
// "\/Date(1356044400000+0100)\/"
|
||||
#endregion
|
||||
|
||||
Assert.IsNotNull(jsonMsDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeDateTimeZoneHandling
|
||||
[TestFixture]
|
||||
public class SerializeDateTimeZoneHandling : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Flight
|
||||
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
|
||||
@@ -27,11 +27,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeDictionary
|
||||
[TestFixture]
|
||||
public class SerializeDictionary : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -51,6 +54,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "Jess": 11926
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""James"": 9001,
|
||||
""Jo"": 3474,
|
||||
""Jess"": 11926
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeObject
|
||||
[TestFixture]
|
||||
public class SerializeObject : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -70,6 +73,16 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
|
||||
Console.WriteLine(json);
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Email"": ""james@example.com"",
|
||||
""Active"": true,
|
||||
""CreatedDate"": ""2013-01-20T00:00:00Z"",
|
||||
""Roles"": [
|
||||
""User"",
|
||||
""Admin""
|
||||
]
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeRawJson
|
||||
[TestFixture]
|
||||
public class SerializeRawJson : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class JavaScriptSettings
|
||||
@@ -41,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -58,6 +61,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// "OnUnloadFunction": function(e) { alert(e); }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""OnLoadFunction"": OnLoad,
|
||||
""OnUnloadFunction"": function(e) { alert(e); }
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeSerializationBinder
|
||||
[TestFixture]
|
||||
public class SerializeSerializationBinder : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class KnownTypesBinder : SerializationBinder
|
||||
@@ -57,6 +59,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -93,6 +96,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(newValue.GetType().Name);
|
||||
// Car
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Car", newValue.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeTypeNameHandling
|
||||
[TestFixture]
|
||||
public class SerializeTypeNameHandling : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public abstract class Business
|
||||
@@ -50,6 +52,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -113,6 +116,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(newStockholder.Businesses[0].GetType().Name);
|
||||
// Hotel
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Hotel", newStockholder.Businesses[0].GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -27,10 +27,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeUnindentedJson
|
||||
[TestFixture]
|
||||
public class SerializeUnindentedJson : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -62,6 +65,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
|
||||
Console.WriteLine(json);
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{""Email"":""james@example.com"",""Active"":true,""CreatedDate"":""2013-01-20T00:00:00Z"",""Roles"":[""User"",""Admin""]}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -28,11 +28,14 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeWithJsonConverters
|
||||
[TestFixture]
|
||||
public class SerializeWithJsonConverters : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -59,6 +62,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
Console.WriteLine(string.Join(", ", newStringComparsions.Select(c => c.ToString())));
|
||||
// CurrentCulture, InvariantCulture
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("CurrentCulture, InvariantCulture", string.Join(", ", newStringComparsions.Select(c => c.ToString())));
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -28,11 +28,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class SerializeWithJsonSerializerToFile
|
||||
[TestFixture]
|
||||
public class SerializeWithJsonSerializerToFile : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Movie
|
||||
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
|
||||
@@ -28,10 +28,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
{
|
||||
public class TraceWriter
|
||||
[TestFixture]
|
||||
public class TraceWriter : TestFixtureBase
|
||||
{
|
||||
#region Types
|
||||
public class Account
|
||||
@@ -41,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
@@ -61,7 +64,15 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
// 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
|
||||
// 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
|
||||
// 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
|
||||
// 2013-01-21T01:36:24.450 Verbose Deserialized JSON:
|
||||
// {
|
||||
// "FullName": "Dan Deleted",
|
||||
// "Deleted": true,
|
||||
// "DeletedDate": "2013-01-20T00:00:00"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(4, traceWriter.GetTraceMessages().Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user