diff --git a/Build/build.ps1 b/Build/build.ps1 index 722c7be1..659acb7f 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -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 diff --git a/Src/Newtonsoft.Json.Tests/Documentation/ConvertingJsonAndXmlTests.cs b/Src/Newtonsoft.Json.Tests/Documentation/ConvertingJsonAndXmlTests.cs index f3cd803f..c43a4c05 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/ConvertingJsonAndXmlTests.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/ConvertingJsonAndXmlTests.cs @@ -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 = @" - Alan - http://www.google.com + Alan + http://www.google.com - Louis - http://www.yahoo.com + Louis + http://www.yahoo.com "; @@ -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 // // // - // Alan - // http://www.google.com + // Alan + // http://www.google.com // // - // Louis - // http://www.yahoo.com + // Louis + // http://www.yahoo.com // // #endregion } + [Test] public void ForceJsonArray() { #region ForceJsonArray diff --git a/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs b/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs index 6ee92436..6ae04a70 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs @@ -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 GetPosts() { - return null; + return new List(); } + [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 posts = null; + List 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() + from c in rss["channel"]["item"].SelectMany(i => i["categories"]).Values() 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 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); } } } diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Dotnet.xproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Dotnet.xproj index f3c3d980..e2efa374 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Dotnet.xproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Dotnet.xproj @@ -9,9 +9,8 @@ 13e906ae-5a47-4354-8caf-e63e8ac541ed Newtonsoft.Json.Tests ..\artifacts\obj\$(MSBuildProjectName) - ..\artifacts\bin\$(MSBuildProjectName)\ + .\bin\ - 2.0 diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Dotnet.xproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Dotnet.xproj index c841f384..07d8d0ba 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Dotnet.xproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Dotnet.xproj @@ -9,9 +9,8 @@ 779e052e-7218-4da3-b419-ffb0f4c95081 Newtonsoft.Json ..\artifacts\obj\$(MSBuildProjectName) - ..\artifacts\bin\$(MSBuildProjectName)\ + .\bin\ - 2.0