-Tests
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -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"": ""<h3>Title!</h3>\r\n <p>Content!</p>""
|
||||
}
|
||||
]", 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
|
||||
|
||||
Reference in New Issue
Block a user