This commit is contained in:
James Newton-King
2015-04-07 17:36:41 +12:00
parent d2d097172e
commit 765bfbf1b4
102 changed files with 855 additions and 129 deletions
@@ -57,4 +57,4 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.1.18405")]
[assembly: AssemblyFileVersion("7.0.1.18407")]
@@ -63,7 +63,7 @@ namespace Newtonsoft.Json.Tests.Documentation
public static StreamWriter CreateText(string path)
{
return null;
return new StreamWriter(new MemoryStream());
}
public static void WriteAllText(string path, string contents)
@@ -29,10 +29,12 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Bson;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
{
public class DeserializeFromBson
[TestFixture]
public class DeserializeFromBson : TestFixtureBase
{
#region Types
public class Event
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -29,10 +29,12 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Bson;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
{
public class DeserializeFromBsonCollection
[TestFixture]
public class DeserializeFromBsonCollection : TestFixtureBase
{
#region Types
public class Event
@@ -42,23 +44,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
}
#endregion
[Test]
public void Example()
{
//IList<Event> e = new List<Event>
// {
// new Event {StartDate = new DateTime(2013, 3, 31), Name = "Easter"}
// };
//MemoryStream ms1 = new MemoryStream();
//using (BsonWriter writer = new BsonWriter(ms1))
//{
// JsonSerializer serializer = new JsonSerializer();
// serializer.Serialize(writer, e);
//}
//string ss = Convert.ToBase64String(ms1.ToArray());
//Console.WriteLine(ss);
#region Usage
string s = "MQAAAAMwACkAAAACTmFtZQAHAAAARWFzdGVyAAlTdGFydERhdGUAgDf0uj0BAAAAAA==";
byte[] data = Convert.FromBase64String(s);
@@ -30,10 +30,12 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
{
public class SerializeToBson
[TestFixture]
public class SerializeToBson : TestFixtureBase
{
#region Types
public class Event
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -64,6 +67,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
Console.WriteLine(data);
// MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAMDgKWE8AQAAAA==
#endregion
Assert.AreEqual("MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAMDgKWE8AQAAAA==", data);
}
}
}
@@ -245,8 +245,10 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
}
#endregion
public class CustomJsonReader
[TestFixture]
public class CustomJsonReader : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -31,6 +31,7 @@ using System.Linq;
using System.Text;
using System.Xml;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{
@@ -300,8 +301,10 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
}
#endregion
public class CustomJsonWriter
[TestFixture]
public class CustomJsonWriter : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{
public class ReadJsonWithJsonTextReader
[TestFixture]
public class ReadJsonWithJsonTextReader : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -43,7 +43,8 @@ using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{
public class ReadMultipleContentWithJsonReader
[TestFixture]
public class ReadMultipleContentWithJsonReader : TestFixtureBase
{
#region Types
public class Role
@@ -52,6 +53,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{
public class WriteJsonWithJsonTextWriter
[TestFixture]
public class WriteJsonWithJsonTextWriter : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -70,6 +73,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
// ]
// }
#endregion
Assert.AreEqual(@"{
""CPU"": ""Intel"",
""PSU"": ""500W"",
""Drives"": [
""DVD read/writer""
/*(broken)*/,
""500 gigabyte hard drive"",
""200 gigabype hard drive""
]
}", sb.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class Clone
[TestFixture]
public class Clone : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -68,6 +71,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(Object.ReferenceEquals(o1, o2));
// false
#endregion
Assert.IsTrue(JToken.DeepEquals(o1, o2));
Assert.IsFalse(Object.ReferenceEquals(o1, o2));
}
}
}
@@ -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.Linq
{
public class CreateJsonAnonymousObject
[TestFixture]
public class CreateJsonAnonymousObject : TestFixtureBase
{
#region Types
public class Post
@@ -43,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -101,6 +104,25 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// }
// }
#endregion
Assert.AreEqual(@"{
""channel"": {
""title"": ""Star Wars"",
""link"": ""http://www.starwars.com"",
""description"": ""Star Wars blog."",
""item"": [
{
""title"": ""Episode VII"",
""description"": ""Episode VII production"",
""link"": ""episode-vii-production.aspx"",
""category"": [
""episode-vii"",
""movie""
]
}
]
}
}", o.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class CreateJsonCollectionInitializer
[TestFixture]
public class CreateJsonCollectionInitializer : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -59,6 +62,15 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// ]
// }
#endregion
Assert.AreEqual(@"{
""Cpu"": ""Intel"",
""Memory"": 32,
""Drives"": [
""DVD"",
""SSD""
]
}", o.ToString());
}
}
}
@@ -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.Linq
{
public class CreateJsonDeclaratively
[TestFixture]
public class CreateJsonDeclaratively : TestFixtureBase
{
#region Types
public class Post
@@ -45,7 +47,19 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
private List<Post> GetPosts()
{
return null;
return new List<Post>
{
new Post
{
Title = "Title!",
Categories = new List<string>
{
"Category1"
},
Description = "Description!",
Link = "Link!"
}
};
}
public void Example()
@@ -103,6 +117,24 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// }
// }
#endregion
Assert.AreEqual(@"{
""channel"": {
""title"": ""James Newton-King"",
""link"": ""http://james.newtonking.com"",
""description"": ""James Newton-King's blog."",
""item"": [
{
""title"": ""Title!"",
""description"": ""Description!"",
""link"": ""Link!"",
""category"": [
""Category1""
]
}
]
}
}", rss.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class CreateJsonDynamic
[TestFixture]
public class CreateJsonDynamic : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -57,6 +60,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// ]
// }
#endregion
Assert.AreEqual(@"{
""ProductName"": ""Elbow Grease"",
""Enabled"": true,
""Price"": 4.90,
""StockCount"": 9000,
""StockValue"": 44100,
""Tags"": [
""Real"",
""OnSale""
]
}", product.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class CreateJsonJTokenWriter
[TestFixture]
public class CreateJsonJTokenWriter : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -58,6 +61,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// ]
// }
#endregion
Assert.AreEqual(@"{
""name1"": ""value1"",
""name2"": [
1,
2
]
}", o.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class CreateJsonManually
[TestFixture]
public class CreateJsonManually : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class CreateReader
[TestFixture]
public class CreateReader : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -71,6 +74,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// EndArray
// EndObject
#endregion
Assert.IsFalse(reader.Read());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class CreateWriter
[TestFixture]
public class CreateWriter : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -59,6 +62,15 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// ]
// }
#endregion
Assert.AreEqual(@"{
""name1"": ""value1"",
""name2"": ""value2"",
""name3"": [
1,
2
]
}", o.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class DeepEquals
[TestFixture]
public class DeepEquals : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -66,6 +69,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(JToken.DeepEquals(s1, o1["String"]));
// true
#endregion
Assert.IsTrue(JToken.DeepEquals(o1, o2));
Assert.IsTrue(JToken.DeepEquals(s1, o1["String"]));
}
}
}
@@ -29,10 +29,12 @@ using System.Linq;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class DeserializeWithLinq
[TestFixture]
public class DeserializeWithLinq : TestFixtureBase
{
#region Types
public class BlogPost
@@ -45,6 +47,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -76,6 +79,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// <h3>Title!</h3>
// <p>Content!</p>
#endregion
Assert.AreEqual(@"<h3>Title!</h3>
<p>Content!</p>", blogPosts[0].Body);
}
}
}
@@ -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.Linq
{
public class FromObject
[TestFixture]
public class FromObject : TestFixtureBase
{
#region Types
public class Computer
@@ -42,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -90,6 +93,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// "SSD"
// ]
#endregion
Assert.AreEqual(@"[
""DVD"",
""SSD""
]", a.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class JObjectProperties
[TestFixture]
public class JObjectProperties : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -56,6 +59,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// name1 - value1
// name2 - value2
#endregion
Assert.AreEqual(2, o.Count);
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class JValueCast
[TestFixture]
public class JValueCast : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -77,6 +80,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine((dt != null) ? dt.ToString() : "{null}");
// {null}
#endregion
Assert.AreEqual("01/21/2013 00:00:00", s);
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class JValueValue
[TestFixture]
public class JValueValue : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -50,6 +53,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(u.Value);
// http://www.google.com/
#endregion
Assert.AreEqual(new Uri("http://www.google.com/"), u.Value);
}
}
}
@@ -23,19 +23,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Runtime.Serialization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Autofac;
using Newtonsoft.Json.Tests.Serialization;
using LogService = Newtonsoft.Json.Tests.Serialization.LogManager;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
[TestFixture]
public class MergeJson : TestFixtureBase
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ModifyJson
[TestFixture]
public class ModifyJson : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -75,6 +78,19 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// }
// }
#endregion
Assert.AreEqual(@"{
""channel"": {
""title"": ""STAR WARS"",
""link"": ""http://www.starwars.com"",
""description"": ""STAR WARS BLOG."",
""new"": ""New value"",
""item"": [
""Item 1"",
""Item 2""
]
}
}", rss.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ParseJsonAny
[TestFixture]
public class ParseJsonAny : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -56,6 +59,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(t4.Type);
// String
#endregion
Assert.AreEqual(JTokenType.String, t4.Type);
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ParseJsonArray
[TestFixture]
public class ParseJsonArray : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -51,6 +54,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// "Large"
// ]
#endregion
Assert.AreEqual(@"[
""Small"",
""Medium"",
""Large""
]", a.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ParseJsonObject
[TestFixture]
public class ParseJsonObject : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -55,6 +58,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// ]
// }
#endregion
Assert.AreEqual(@"{
""CPU"": ""Intel"",
""Drives"": [
""DVD read/writer"",
""500 gigabyte hard drive""
]
}", o.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class QueryJson
[TestFixture]
public class QueryJson : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -89,6 +92,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(string.Join(", ", categoriesText));
// Json.NET, CodePlex
#endregion
Assert.AreEqual("Json.NET, CodePlex", string.Join(", ", categoriesText));
}
}
}
@@ -29,11 +29,14 @@ using System.Linq;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class QueryJsonDynamic
[TestFixture]
public class QueryJsonDynamic : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -69,6 +72,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(postDate);
// 23/01/2013 7:30:00 p.m.
#endregion
Assert.AreEqual("Json.NET is awesome!", title);
}
}
}
@@ -28,11 +28,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class QueryJsonLinq
[TestFixture]
public class QueryJsonLinq : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -92,6 +95,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
//LINQ - Count: 1
//CodePlex - Count: 1
#endregion
Assert.AreEqual(3, categories.Count());
}
}
}
@@ -28,11 +28,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class QueryJsonSelectToken
[TestFixture]
public class QueryJsonSelectToken : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -82,6 +85,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(productName);
// Elbow Grease
#endregion
Assert.AreEqual("Elbow Grease", productName);
}
}
}
@@ -28,11 +28,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class QueryJsonSelectTokenWithLinq
[TestFixture]
public class QueryJsonSelectTokenWithLinq : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -83,6 +86,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(totalPrice);
// 149.95
#endregion
Assert.AreEqual(149.95m, totalPrice);
}
}
}
@@ -30,11 +30,14 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ReadJTokenFromBson
[TestFixture]
public class ReadJTokenFromBson : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -52,6 +55,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(value);
// value1
#endregion
Assert.AreEqual("value1", value);
}
}
}
@@ -29,11 +29,14 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ReadJson
[TestFixture]
public class ReadJson : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -47,5 +50,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
}
#endregion
}
public static class File
{
public static StreamReader OpenText(string path)
{
return new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("{}")));
}
public static string ReadAllText(string path)
{
return "{}";
}
}
}
}
@@ -29,10 +29,12 @@ using System.Linq;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class SerializeWithLinq
[TestFixture]
public class SerializeWithLinq : TestFixtureBase
{
#region Types
public class BlogPost
@@ -45,6 +47,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -57,7 +60,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
AuthorTwitter = "JamesNK",
PostedDate = new DateTime(2013, 1, 23, 19, 30, 0),
Body = @"<h3>Title!</h3>
<p>Content!</p>"
<p>Content!</p>"
}
};
@@ -90,6 +93,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
// }
// ]
#endregion
Assert.AreEqual(@"[
{
""Title"": ""Json.NET is awesome!"",
""Author"": {
""Name"": ""James Newton-King"",
""Twitter"": ""JamesNK""
},
""Date"": ""2013-01-23T19:30:00"",
""BodyHtml"": ""&lt;h3&gt;Title!&lt;/h3&gt;\r\n &lt;p&gt;Content!&lt;/p&gt;""
}
]", blogPostsArray.ToString());
}
}
}
@@ -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.Linq
{
public class ToObjectComplex
[TestFixture]
public class ToObjectComplex : TestFixtureBase
{
#region Types
public class Person
@@ -40,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
}
#endregion
[Test]
public void Example()
{
#region Usage
@@ -66,6 +69,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(person[1].Name);
// Mike Smith
#endregion
Assert.AreEqual("John Smith", person[0].Name);
Assert.AreEqual("Mike Smith", person[1].Name);
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ToObjectGeneric
[TestFixture]
public class ToObjectGeneric : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -53,6 +56,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(s);
// "True"
#endregion
Assert.AreEqual("True", s);
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ToObjectType
[TestFixture]
public class ToObjectType : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -53,6 +56,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(s);
// "True"
#endregion
Assert.AreEqual("True", s);
}
}
}
@@ -29,11 +29,14 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ToString
[TestFixture]
public class ToString : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -52,6 +55,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(o.ToString(Formatting.None, new JavaScriptDateTimeConverter()));
// {"string1":"value","integer2":99,"datetime3":new Date(959032800000)}
#endregion
Assert.IsNotNull(o.ToString(Formatting.None, new JavaScriptDateTimeConverter()));
}
}
}
@@ -29,11 +29,14 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class ToStringJsonConverter
[TestFixture]
public class ToStringJsonConverter : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -42,6 +45,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(o.ToString(Formatting.None, new JavaScriptDateTimeConverter()));
// {"string1":"value","integer2":99,"datetime3":new Date(959032800000)}
#endregion
Assert.IsNotNull(o.ToString(Formatting.None, new JavaScriptDateTimeConverter()));
}
}
}
@@ -30,11 +30,14 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class WriteJTokenToBson
[TestFixture]
public class WriteJTokenToBson : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -55,6 +58,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
Console.WriteLine(data);
// KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=
#endregion
Assert.AreEqual("KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=", data);
}
}
}
@@ -29,11 +29,14 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{
public class WriteToJsonFile
[TestFixture]
public class WriteToJsonFile : TestFixtureBase
{
[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 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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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));
}
}
}
@@ -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);
}
}
}
@@ -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"]);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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("{}")));
}
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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
@@ -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));
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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())));
}
}
}
@@ -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());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Xml
{
public class ConvertJsonToXml
[TestFixture]
public class ConvertJsonToXml : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -67,6 +70,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Xml
// </Team>
// </Root>
#endregion
Assert.AreEqual(@"<Root Id=""1"">
<Email>james@example.com</Email>
<Active>true</Active>
<CreatedDate>2013-01-20T00:00:00Z</CreatedDate>
<Roles>User</Roles>
<Roles>Admin</Roles>
<Team Id=""2"">
<Name>Software Developers</Name>
<Description>Creators of fine software products and services.</Description>
</Team>
</Root>", node.ToString());
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Xml
{
public class ConvertXmlToJson
[TestFixture]
public class ConvertXmlToJson : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -75,6 +78,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Xml
// }
// }
#endregion
Assert.AreEqual(@"{""?xml"":{""@version"":""1.0"",""@standalone"":""no""},""root"":{""person"":[{""@id"":""1"",""name"":""Alan"",""url"":""http://www.google.com""},{""@id"":""2"",""name"":""Louis"",""url"":""http://www.yahoo.com""}]}}", json);
}
}
}
@@ -28,11 +28,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using NUnit.Framework;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Xml
{
public class ConvertXmlToJsonForceArray
[TestFixture]
public class ConvertXmlToJsonForceArray : TestFixtureBase
{
[Test]
public void Example()
{
#region Usage
@@ -80,6 +83,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Xml
// }
// }
#endregion
Assert.AreEqual(@"{""person"":{""@id"":""1"",""name"":""Alan"",""url"":""http://www.google.com"",""role"":[""Admin""]}}", json);
}
}
}
@@ -80,6 +80,31 @@ namespace Newtonsoft.Json.Tests.Linq
}
#endif
[Test]
public void ReadWithSupportMultipleContent()
{
string json = @"{ 'name': 'Admin' }{ 'name': 'Publisher' }";
IList<JObject> roles = new List<JObject>();
JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.SupportMultipleContent = true;
while (true)
{
JObject role = (JObject)JToken.ReadFrom(reader);
roles.Add(role);
if (!reader.Read())
break;
}
Assert.AreEqual(2, roles.Count);
Assert.AreEqual("Admin", (string)roles[0]["name"]);
Assert.AreEqual("Publisher", (string)roles[1]["name"]);
}
[Test]
public void JObjectWithComments()
{
@@ -76,4 +76,4 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.1.18405")]
[assembly: AssemblyFileVersion("7.0.1.18407")]
+2
View File
@@ -2,5 +2,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>

Some files were not shown because too many files have changed in this diff Show More