-Documentation
This commit is contained in:
+3
-3
@@ -2,7 +2,7 @@
|
||||
$zipFileName = "Json80r4.zip"
|
||||
$majorVersion = "8.0"
|
||||
$majorWithReleaseVersion = "8.0.4"
|
||||
$nugetPrelease = "beta4"
|
||||
$nugetPrerelease = "beta4"
|
||||
$version = GetVersion $majorWithReleaseVersion
|
||||
$packageId = "Newtonsoft.Json"
|
||||
$signAssemblies = $false
|
||||
@@ -262,9 +262,9 @@ function NUnitTests($build)
|
||||
function GetNuGetVersion()
|
||||
{
|
||||
$nugetVersion = $majorWithReleaseVersion
|
||||
if ($nugetPrelease -ne $null)
|
||||
if ($nugetPrerelease -ne $null)
|
||||
{
|
||||
$nugetVersion = $nugetVersion + "-" + $nugetPrelease
|
||||
$nugetVersion = $nugetVersion + "-" + $nugetPrerelease
|
||||
}
|
||||
|
||||
return $nugetVersion
|
||||
|
||||
@@ -54,20 +54,22 @@ using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public class ConvertingJsonAndXmlTests
|
||||
[TestFixture]
|
||||
public class ConvertingJsonAndXmlTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void SerializeXmlNode()
|
||||
{
|
||||
#region SerializeXmlNode
|
||||
string xml = @"<?xml version='1.0' standalone='no'?>
|
||||
<root>
|
||||
<person id='1'>
|
||||
<name>Alan</name>
|
||||
<url>http://www.google.com</url>
|
||||
<name>Alan</name>
|
||||
<url>http://www.google.com</url>
|
||||
</person>
|
||||
<person id='2'>
|
||||
<name>Louis</name>
|
||||
<url>http://www.yahoo.com</url>
|
||||
<name>Louis</name>
|
||||
<url>http://www.yahoo.com</url>
|
||||
</person>
|
||||
</root>";
|
||||
|
||||
@@ -98,6 +100,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeXmlNode()
|
||||
{
|
||||
#region DeserializeXmlNode
|
||||
@@ -126,17 +129,18 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// <?xml version="1.0" standalone="no"?>
|
||||
// <root>
|
||||
// <person id="1">
|
||||
// <name>Alan</name>
|
||||
// <url>http://www.google.com</url>
|
||||
// <name>Alan</name>
|
||||
// <url>http://www.google.com</url>
|
||||
// </person>
|
||||
// <person id="2">
|
||||
// <name>Louis</name>
|
||||
// <url>http://www.yahoo.com</url>
|
||||
// <name>Louis</name>
|
||||
// <url>http://www.yahoo.com</url>
|
||||
// </person>
|
||||
// </root>
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForceJsonArray()
|
||||
{
|
||||
#region ForceJsonArray
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public static StreamReader OpenText(string path)
|
||||
{
|
||||
return null;
|
||||
return new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("{}")));
|
||||
}
|
||||
|
||||
public static StreamWriter CreateText(string path)
|
||||
@@ -76,7 +76,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
}
|
||||
|
||||
public class LinqToJsonTests
|
||||
[TestFixture]
|
||||
public class LinqToJsonTests : TestFixtureBase
|
||||
{
|
||||
public void LinqToJsonBasic()
|
||||
{
|
||||
@@ -129,9 +130,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
|
||||
private List<Post> GetPosts()
|
||||
{
|
||||
return null;
|
||||
return new List<Post>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateDeclaratively()
|
||||
{
|
||||
#region LinqToJsonCreateDeclaratively
|
||||
@@ -163,7 +165,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// "channel": {
|
||||
// "title": "James Newton-King",
|
||||
// "link": "http://james.newtonking.com",
|
||||
// "description": "James Newton-King's blog.",
|
||||
// "description": "James Newton-King\'s blog.",
|
||||
// "item": [
|
||||
// {
|
||||
// "title": "Json.NET 1.3 + New license + Now on CodePlex",
|
||||
@@ -189,9 +191,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateFromObject()
|
||||
{
|
||||
List<Post> posts = null;
|
||||
List<Post> posts = GetPosts();
|
||||
|
||||
#region LinqToJsonCreateFromObject
|
||||
JObject o = JObject.FromObject(new
|
||||
@@ -216,6 +219,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateParse()
|
||||
{
|
||||
#region LinqToJsonCreateParse
|
||||
@@ -231,6 +235,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateParseArray()
|
||||
{
|
||||
#region LinqToJsonCreateParseArray
|
||||
@@ -244,6 +249,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonReadObject()
|
||||
{
|
||||
#region LinqToJsonReadObject
|
||||
@@ -255,6 +261,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonSimpleQuerying()
|
||||
{
|
||||
#region LinqToJsonSimpleQuerying
|
||||
@@ -262,7 +269,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
'channel': {
|
||||
'title': 'James Newton-King',
|
||||
'link': 'http://james.newtonking.com',
|
||||
'description': 'James Newton-King's blog.',
|
||||
'description': 'James Newton-King\'s blog.',
|
||||
'item': [
|
||||
{
|
||||
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
|
||||
@@ -303,9 +310,36 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonQuerying()
|
||||
{
|
||||
JObject rss = new JObject();
|
||||
JObject rss = JObject.Parse(@"{
|
||||
'channel': {
|
||||
'title': 'James Newton-King',
|
||||
'link': 'http://james.newtonking.com',
|
||||
'description': 'James Newton-King\'s blog.',
|
||||
'item': [
|
||||
{
|
||||
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
|
||||
'description': 'Annoucing the release of Json.NET 1.3, the MIT license and the source on CodePlex',
|
||||
'link': 'http://james.newtonking.com/projects/json-net.aspx',
|
||||
'categories': [
|
||||
'Json.NET',
|
||||
'CodePlex'
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'LINQ to JSON beta',
|
||||
'description': 'Annoucing LINQ to JSON',
|
||||
'link': 'http://james.newtonking.com/projects/json-net.aspx',
|
||||
'categories': [
|
||||
'Json.NET',
|
||||
'LINQ'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}");
|
||||
|
||||
#region LinqToJsonQuerying
|
||||
var postTitles =
|
||||
@@ -321,7 +355,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
//Json.NET 1.3 + New license + Now on CodePlex
|
||||
|
||||
var categories =
|
||||
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
||||
from c in rss["channel"]["item"].SelectMany(i => i["categories"]).Values<string>()
|
||||
group c by c
|
||||
into g
|
||||
orderby g.Count() descending
|
||||
@@ -336,6 +370,9 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
//LINQ - Count: 1
|
||||
//CodePlex - Count: 1
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(2, postTitles.Count());
|
||||
Assert.AreEqual(3, categories.Count());
|
||||
}
|
||||
|
||||
#region LinqToJsonDeserializeObject
|
||||
@@ -354,6 +391,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonDeserializeExample()
|
||||
{
|
||||
#region LinqToJsonDeserializeExample
|
||||
@@ -362,9 +400,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
'original': 'http://www.foo.com/',
|
||||
'short': 'krehqk',
|
||||
'error': {
|
||||
'code':0,
|
||||
'msg':'No action taken'
|
||||
'code': 0,
|
||||
'msg': 'No action taken'
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
JObject json = JObject.Parse(jsonText);
|
||||
@@ -386,17 +425,53 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
Console.WriteLine(shortie.Error.ErrorMessage);
|
||||
// No action taken
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("http://www.foo.com/", shortie.Original);
|
||||
Assert.AreEqual("No action taken", shortie.Error.ErrorMessage);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectTokenSimple()
|
||||
{
|
||||
JObject o = new JObject();
|
||||
JObject o = JObject.Parse(@"{
|
||||
'Stores': [
|
||||
'Lambton Quay',
|
||||
'Willis Street'
|
||||
],
|
||||
'Manufacturers': [
|
||||
{
|
||||
'Name': 'Acme Co',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Anvil',
|
||||
'Price': 50
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'Name': 'Contoso',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Elbow Grease',
|
||||
'Price': 99.95
|
||||
},
|
||||
{
|
||||
'Name': 'Headlight Fluid',
|
||||
'Price': 4
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}");
|
||||
|
||||
#region SelectTokenSimple
|
||||
string name = (string)o.SelectToken("Manufacturers[0].Name");
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Acme Co", name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectTokenComplex()
|
||||
{
|
||||
#region SelectTokenComplex
|
||||
@@ -440,11 +515,45 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
string productName = (string)o.SelectToken("Manufacturers[1].Products[0].Name");
|
||||
// Elbow Grease
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Acme Co", name);
|
||||
Assert.AreEqual(50m, productPrice);
|
||||
Assert.AreEqual("Elbow Grease", productName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectTokenLinq()
|
||||
{
|
||||
JObject o = new JObject();
|
||||
JObject o = JObject.Parse(@"{
|
||||
'Stores': [
|
||||
'Lambton Quay',
|
||||
'Willis Street'
|
||||
],
|
||||
'Manufacturers': [
|
||||
{
|
||||
'Name': 'Acme Co',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Anvil',
|
||||
'Price': 50
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'Name': 'Contoso',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Elbow Grease',
|
||||
'Price': 99.95
|
||||
},
|
||||
{
|
||||
'Name': 'Headlight Fluid',
|
||||
'Price': 4
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}");
|
||||
|
||||
#region SelectTokenLinq
|
||||
IList<string> storeNames = o.SelectToken("Stores").Select(s => (string)s).ToList();
|
||||
@@ -458,6 +567,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
decimal totalPrice = o["Manufacturers"].Sum(m => (decimal)m.SelectToken("Products[0].Price"));
|
||||
// 149.95
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(2, storeNames.Count);
|
||||
Assert.AreEqual(2, firstProductNames.Count);
|
||||
Assert.AreEqual(149.95m, totalPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
<ProjectGuid>13e906ae-5a47-4354-8caf-e63e8ac541ed</ProjectGuid>
|
||||
<RootNamespace>Newtonsoft.Json.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
<ProjectGuid>779e052e-7218-4da3-b419-ffb0f4c95081</ProjectGuid>
|
||||
<RootNamespace>Newtonsoft.Json</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user