-Replace tests console writes with asserts

This commit is contained in:
James Newton-King
2015-03-22 12:37:12 +13:00
parent a3df7ecd98
commit b9af7f227b
34 changed files with 380 additions and 362 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.18321")]
[assembly: AssemblyFileVersion("7.0.1.18322")]
@@ -148,7 +148,6 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteEnd();
string bson = BytesToHex(ms.ToArray());
Console.WriteLine(bson);
Assert.AreEqual("1D-00-00-00-05-30-00-10-00-00-00-04-D7-EE-21-D8-5C-4B-C9-43-8A-C2-69-28-E5-79-B7-05-00", bson);
}
@@ -290,15 +289,6 @@ namespace Newtonsoft.Json.Tests.Bson
serializer.Serialize(writer1, s1);
CollectionAssert.AreEquivalent(ms.ToArray(), ms1.ToArray());
string s = JsonConvert.SerializeObject(s1);
byte[] textData = Encoding.UTF8.GetBytes(s);
int l1 = textData.Length;
int l2 = ms.ToArray().Length;
Console.WriteLine(l1);
Console.WriteLine(l2);
}
[Test]
@@ -740,10 +730,9 @@ namespace Newtonsoft.Json.Tests.Bson
JObject o = (JObject)JObject.ReadFrom(new BsonReader(new MemoryStream(ms.ToArray())));
Console.WriteLine(o.ToString());
//{
// "Regex": "/(hi)/iux"
//}
Assert.AreEqual(@"{
""Regex"": ""/(hi)/iux""
}", o.ToString());
}
[Test]
@@ -111,16 +111,13 @@ namespace Newtonsoft.Json.Tests.Converters
IPerson person = people[0];
Console.WriteLine(person.GetType());
// Newtonsoft.Json.Tests.Employee
Assert.AreEqual("Newtonsoft.Json.Tests.Employee", person.GetType().Name);
Console.WriteLine(person.FirstName);
// Maurice
Assert.AreEqual("Maurice", person.FirstName);
Employee employee = (Employee)person;
Console.WriteLine(employee.JobTitle);
// Support
Assert.AreEqual("Support", employee.JobTitle);
}
public class MyClass
@@ -109,7 +109,6 @@ namespace Newtonsoft.Json.Tests.Converters
ts.Stop();
Console.WriteLine(ts.Elapsed.TotalSeconds);
Console.WriteLine(json);
}
[Test]
@@ -136,7 +135,6 @@ namespace Newtonsoft.Json.Tests.Converters
ts.Stop();
Console.WriteLine(ts.Elapsed.TotalSeconds);
Console.WriteLine(json);
}
[Test]
@@ -224,10 +222,8 @@ namespace Newtonsoft.Json.Tests.Converters
object[] fields = caseInfo.FieldReader.Invoke(value);
foreach (object field in fields)
{
Console.WriteLine(field);
}
Assert.AreEqual(10, fields[0]);
Assert.AreEqual(5, fields[1]);
}
[Test]
@@ -242,10 +238,9 @@ namespace Newtonsoft.Json.Tests.Converters
10.0, 5.0
});
Console.WriteLine(value.ToString());
Console.WriteLine(value.width);
Console.WriteLine(value.length);
Assert.AreEqual("Newtonsoft.Json.Tests.TestObjects.Shape+Rectangle", value.ToString());
Assert.AreEqual(10, value.width);
Assert.AreEqual(5, value.length);
}
[Test]
@@ -293,8 +288,6 @@ namespace Newtonsoft.Json.Tests.Converters
TypeNameHandling = TypeNameHandling.All
});
Console.WriteLine(json);
Assert.AreEqual(@"{""Case"":""Rectangle"",""Fields"":[10.0,5.0]}", json);
Shape c = JsonConvert.DeserializeObject<Shape>(json);
@@ -275,7 +275,7 @@ namespace Newtonsoft.Json.Tests.Converters
// "LastModified": "2009-04-12T20:44:55"
// }
Console.WriteLine(jsonText);
Assert.AreEqual(@"{""Name"":""Keith"",""BirthDate"":""1980-03-08T00:00:00"",""LastModified"":""2009-04-12T20:44:55""}", jsonText);
}
#if !NET20
@@ -70,13 +70,6 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual("new Date(976918263055)", result);
}
[Test]
public void sdfs()
{
int i = Convert.ToInt32("+1");
Console.WriteLine(i);
}
[Test]
public void SerializeNullableDateTimeClass()
{
@@ -491,15 +491,11 @@ namespace Newtonsoft.Json.Tests.Converters
Value2 = DuplicateNameEnum2.foo_bar_NOT_USED
});
Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
string xml = @"<DuplicateEnumNameTestClass xmlns=""http://schemas.datacontract.org/2004/07/Newtonsoft.Json.Tests.Converters"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
<Value>foo_bar</Value>
<Value2>foo_bar</Value2>
</DuplicateEnumNameTestClass>";
Console.WriteLine(xml);
var o = (DuplicateEnumNameTestClass)s.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(xml)));
Assert.AreEqual(DuplicateNameEnum.foo_bar, o.Value);
@@ -151,12 +151,21 @@ namespace Newtonsoft.Json.Tests.Converters
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
Console.WriteLine(json);
Assert.AreEqual(@"{
""result"": {
""@xp_0:end"": ""2014-08-15 13:12:11.9184"",
""@xp_0:start"": ""2014-08-15 13:11:49.3140"",
""@xp_0:time_diff"": ""22604.3836"",
""@xmlns:xp_0"": ""Test1"",
""@p2:end"": ""2014-08-15 13:13:49.5522"",
""@p2:start"": ""2014-08-15 13:13:49.0268"",
""@p2:time_diff"": ""525.4646"",
""@xmlns:p2"": ""Test2""
}
}", json);
XDocument doc = JsonConvert.DeserializeObject<XDocument>(json);
Console.WriteLine(doc.ToString());
Assert.AreEqual(xml, doc.ToString());
}
#endif
@@ -171,12 +180,21 @@ namespace Newtonsoft.Json.Tests.Converters
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
Console.WriteLine(json);
Assert.AreEqual(@"{
""result"": {
""@xp_0:end"": ""2014-08-15 13:12:11.9184"",
""@xp_0:start"": ""2014-08-15 13:11:49.3140"",
""@xp_0:time_diff"": ""22604.3836"",
""@xmlns:xp_0"": ""Test1"",
""@p2:end"": ""2014-08-15 13:13:49.5522"",
""@p2:start"": ""2014-08-15 13:13:49.0268"",
""@p2:time_diff"": ""525.4646"",
""@xmlns:p2"": ""Test2""
}
}", json);
XmlDocument doc = JsonConvert.DeserializeObject<XmlDocument>(json);
Console.WriteLine(doc.OuterXml);
Assert.AreEqual(xml, doc.OuterXml);
}
@@ -378,7 +396,7 @@ namespace Newtonsoft.Json.Tests.Converters
{
XmlDocument doc = JsonConvert.DeserializeXmlNode("{ A: { '@xsi:nil': true } }");
Console.WriteLine(doc.OuterXml);
Assert.AreEqual(@"<A nil=""true"" />", doc.OuterXml);
XDocument xdoc = JsonConvert.DeserializeXNode("{ A: { '@xsi:nil': true } }");
@@ -468,10 +486,6 @@ namespace Newtonsoft.Json.Tests.Converters
}";
StringAssert.AreEqual(expected, jsonText);
Console.WriteLine("DocumentSerializeIndented");
Console.WriteLine(jsonText);
Console.WriteLine();
}
[Test]
@@ -480,8 +494,6 @@ namespace Newtonsoft.Json.Tests.Converters
XmlDocument doc = new XmlDocument();
string jsonText;
Console.WriteLine("SerializeNodeTypes");
string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<xs:schema xs:id=""SomeID""
xmlns=""""
@@ -500,7 +512,6 @@ namespace Newtonsoft.Json.Tests.Converters
jsonText = JsonConvert.SerializeXmlNode(attribute);
Console.WriteLine(jsonText);
Assert.AreEqual(@"{""@msdata:IsDataSet"":""true""}", jsonText);
#if !NET20
@@ -517,7 +528,6 @@ namespace Newtonsoft.Json.Tests.Converters
jsonText = JsonConvert.SerializeXmlNode(instruction);
Console.WriteLine(jsonText);
Assert.AreEqual(@"{""?xml-stylesheet"":""href=\""classic.xsl\"" type=\""text/xml\""""}", jsonText);
@@ -526,7 +536,6 @@ namespace Newtonsoft.Json.Tests.Converters
jsonText = JsonConvert.SerializeXmlNode(cDataSection);
Console.WriteLine(jsonText);
Assert.AreEqual(@"{""#cdata-section"":""<Kiwi>true</Kiwi>""}", jsonText);
@@ -574,10 +583,6 @@ namespace Newtonsoft.Json.Tests.Converters
string expected = @"{""Item"":[""widget"",""widget""]}";
Assert.AreEqual(expected, jsonText);
Console.WriteLine("DocumentFragmentSerialize");
Console.WriteLine(jsonText);
Console.WriteLine();
}
[Test]
@@ -794,11 +799,6 @@ namespace Newtonsoft.Json.Tests.Converters
XmlDocument deserializedDoc = (XmlDocument)DeserializeXmlNode(jsonText);
Assert.AreEqual(doc.InnerXml, deserializedDoc.InnerXml);
Console.WriteLine("NamespaceSerializeDeserialize");
Console.WriteLine(jsonText);
Console.WriteLine(deserializedDoc.InnerXml);
Console.WriteLine();
}
[Test]
@@ -834,10 +834,6 @@ namespace Newtonsoft.Json.Tests.Converters
string formattedXml = GetIndentedInnerXml(doc);
Console.WriteLine("DocumentDeserialize");
Console.WriteLine(formattedXml);
Console.WriteLine();
StringAssert.AreEqual(expected, formattedXml);
}
@@ -901,7 +897,26 @@ namespace Newtonsoft.Json.Tests.Converters
string jsonText = SerializeXmlNode(doc);
Console.WriteLine(jsonText);
Assert.AreEqual(@"{
""?xml"": {
""@version"": ""1.0"",
""@standalone"": ""no""
},
""root"": {
""person"": [
{
""@id"": ""1"",
""name"": ""Alan"",
""url"": null
},
{
""@id"": ""2"",
""name"": ""Louis"",
""url"": ""http://www.yahoo.com""
}
]
}
}", jsonText);
XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
@@ -1171,8 +1186,6 @@ namespace Newtonsoft.Json.Tests.Converters
#if !NET20
XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot", true);
Console.WriteLine(IndentXml(newXDoc.ToString(SaveOptions.DisableFormatting)));
StringAssert.AreEqual(@"<myRoot>
<available_sizes json:Array=""true"" xmlns:json=""http://james.newtonking.com/projects/json"">
<available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes>
+59 -8
View File
@@ -92,7 +92,7 @@ namespace Newtonsoft.Json.Tests
Assert.AreEqual(0, r2.Green);
Assert.AreEqual(0, r2.Blue);
Console.WriteLine(json);
Assert.AreEqual(@"""#FF0000""", json);
}
public class PersonDemo
@@ -206,13 +206,11 @@ namespace Newtonsoft.Json.Tests
string trace = traceWriter.ToString();
// Started serializing System.Collections.Generic.List`1[System.String].
// Finished serializing System.Collections.Generic.List`1[System.String].
// 2014-05-13T13:41:53.706 Verbose Serialized JSON:
// Verbose Serialized JSON:
// [
// "User",
// "Admin"
// ]
Console.WriteLine(trace);
}
[Test]
@@ -234,7 +232,12 @@ namespace Newtonsoft.Json.Tests
// "Date": new Date(1401796800000)
// }
Console.WriteLine(j);
Assert.AreEqual(@"{
""Name"": ""Serialize All The Things"",
""Date"": new Date(
1401796800000
)
}", j);
}
[Test]
@@ -251,6 +254,8 @@ namespace Newtonsoft.Json.Tests
});
// Name = Serialize All The Things
// Date = Tuesday, 3 June 2014
Assert.AreEqual("Serialize All The Things", s.Name);
}
[Test]
@@ -311,7 +316,23 @@ namespace Newtonsoft.Json.Tests
// ],
// "Name": "Mike Manager"
// }
Console.WriteLine(json);
Assert.AreEqual(@"{
""Reportees"": [
{
""Name"": ""Arnie Admin""
},
{
""Reportees"": [
{
""Name"": ""Arnie Admin""
}
],
""Name"": ""Susan Supervisor""
}
],
""Name"": ""Mike Manager""
}", json);
}
[Test]
@@ -352,7 +373,29 @@ namespace Newtonsoft.Json.Tests
// }
// ]
// }
Console.WriteLine(json);
Assert.AreEqual(@"{
""$id"": ""1"",
""$type"": ""Newtonsoft.Json.Tests.DemoTests+Manager, Newtonsoft.Json.Tests"",
""Reportees"": [
{
""$id"": ""2"",
""$type"": ""Newtonsoft.Json.Tests.DemoTests+Employee, Newtonsoft.Json.Tests"",
""Name"": ""Arnie Admin""
},
{
""$id"": ""3"",
""$type"": ""Newtonsoft.Json.Tests.DemoTests+Manager, Newtonsoft.Json.Tests"",
""Reportees"": [
{
""$ref"": ""2""
}
],
""Name"": ""Susan Supervisor""
}
],
""Name"": ""Mike Manager""
}", json);
}
[Test]
@@ -527,7 +570,15 @@ namespace Newtonsoft.Json.Tests
// ]
// }
Console.WriteLine(json);
Assert.AreEqual(@"{
""FirstName"": ""John"",
""LastName"": ""Smith"",
""Enabled"": true,
""Roles"": [
""User"",
""Admin""
]
}", json);
}
}
}
@@ -68,7 +68,6 @@ namespace Newtonsoft.Json.Tests.Documentation
public static void WriteAllText(string path, string contents)
{
Console.WriteLine(contents);
}
public static string ReadAllText(string path)
+1 -10
View File
@@ -1081,8 +1081,6 @@ namespace Newtonsoft.Json.Tests
settings.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
var json = JsonConvert.SerializeObject(dict, settings);
Console.WriteLine(json);
var newDict = new Dictionary<string, object>();
JsonConvert.PopulateObject(json, newDict, settings);
@@ -1103,8 +1101,7 @@ namespace Newtonsoft.Json.Tests
writer.WriteValue(dt);
writer.Flush();
Console.WriteLine(sw.ToString());
Console.WriteLine(sw.ToString().Length);
Assert.AreEqual(@"""2000-12-31T20:59:59.9999999+11:33""", sw.ToString());
}
#endif
@@ -1119,9 +1116,6 @@ namespace Newtonsoft.Json.Tests
writer.WriteValue(dt);
writer.Flush();
Console.WriteLine(sw.ToString());
Console.WriteLine(sw.ToString().Length);
}
[Test]
@@ -1135,9 +1129,6 @@ namespace Newtonsoft.Json.Tests
writer.WriteValue(dt);
writer.Flush();
Console.WriteLine(sw.ToString());
Console.WriteLine(sw.ToString().Length);
}
@@ -461,7 +461,6 @@ third line", jsonTextReader.Value);
{
while (jsonReader.Read())
{
Console.WriteLine(jsonReader.Value);
}
}
}
@@ -2848,11 +2847,9 @@ null//comment
double d;
d = Convert.ToDouble("6.0221418e23", CultureInfo.InvariantCulture);
Console.WriteLine(d.ToString(new CultureInfo("fr-FR")));
Console.WriteLine(d.ToString("0.#############################################################################"));
//CultureInfo info = CultureInfo.GetCultureInfo("fr-FR");
//Console.WriteLine(info.NumberFormat.NumberDecimalSeparator);
Assert.AreEqual("6,0221418E+23", d.ToString(new CultureInfo("fr-FR")));
Assert.AreEqual("602214180000000000000000", d.ToString("0.#############################################################################"));
string json = @"[0e-10,0E-10,0.25e-5,0.3e10,6.0221418e23]";
@@ -161,9 +161,6 @@ namespace Newtonsoft.Json.Tests
string expected = @"[""@"",""\r\n\t\f\b?{\\r\\n\""'"",true,10,10.99,0.99,1E-18,0.000000000000000001,null,null,""This is a string."",null,undefined]";
string result = sb.ToString();
Console.WriteLine("ValueFormatting");
Console.WriteLine(result);
Assert.AreEqual(expected, result);
}
@@ -274,9 +271,6 @@ namespace Newtonsoft.Json.Tests
string expected = @"[""\""These pretzels are making me thirsty!\"""",""Jeff's house was burninated."",""1. You don't talk about fight club.\r\n2. You don't talk about fight club."",""35% of\t statistics\n are made\r up.""]";
string result = sb.ToString();
Console.WriteLine("StringEscaping");
Console.WriteLine(result);
Assert.AreEqual(expected, result);
}
@@ -1145,11 +1139,6 @@ _____'propertyName': NaN,
JsonTextReader reader = new JsonTextReader(new StringReader(json));
Assert.AreEqual(script, reader.ReadAsString());
//Console.WriteLine(HttpUtility.HtmlEncode(script));
//System.Web.Script.Serialization.JavaScriptSerializer s = new System.Web.Script.Serialization.JavaScriptSerializer();
//Console.WriteLine(s.Serialize(new { html = script }));
}
[Test]
@@ -1272,15 +1261,10 @@ _____'propertyName': NaN,
[Test]
public void CompareNewStringEscapingWithOld()
{
Console.WriteLine("Started");
char c = (char)0;
do
{
if (c % 1000 == 0)
Console.WriteLine("Position: " + (int)c);
StringWriter swNew = new StringWriter();
char[] buffer = null;
JavaScriptUtils.WriteEscapedJavaScriptString(swNew, c.ToString(), '"', true, JavaScriptUtils.DoubleQuoteCharEscapeFlags, StringEscapeHandling.Default, ref buffer);
@@ -1296,8 +1280,6 @@ _____'propertyName': NaN,
c++;
} while (c != char.MaxValue);
Console.WriteLine("Finished");
}
private const string EscapedUnicodeText = "!";
@@ -94,11 +94,6 @@ namespace Newtonsoft.Json.Tests.Linq
}
}
//foreach (KeyValuePair<string, int> keyValuePair in counts)
//{
// Console.WriteLine(keyValuePair.Key + ": " + keyValuePair.Value);
//}
Console.WriteLine("Time (secs): " + sw.Elapsed.TotalSeconds);
}
#endif
+16 -25
View File
@@ -570,8 +570,8 @@ Parameter name: arrayIndex");
string smallest = (string)sizes[0];
// Small
Console.WriteLine(name);
Console.WriteLine(smallest);
Assert.AreEqual("Apple", name);
Assert.AreEqual("Small", smallest);
}
[Test]
@@ -603,12 +603,6 @@ Parameter name: arrayIndex");
}
};
Console.WriteLine(shortie.Original);
// http://www.foo.com/
Console.WriteLine(shortie.Error.ErrorMessage);
// No action taken
Assert.AreEqual("http://www.foo.com/", shortie.Original);
Assert.AreEqual("krehqk", shortie.Short);
Assert.AreEqual(null, shortie.Shortened);
@@ -641,15 +635,13 @@ Parameter name: arrayIndex");
moss["Department"] = new JValue("IT");
moss["JobTitle"] = new JValue("Support");
Console.WriteLine(moss.ToString());
//{
// "FirstName": "Maurice",
// "LastName": "Moss",
// "BirthDate": "\/Date(252241200000+1300)\/",
// "Department": "IT",
// "JobTitle": "Support"
//}
Assert.AreEqual(@"{
""FirstName"": ""Maurice"",
""LastName"": ""Moss"",
""BirthDate"": ""1977-12-30T00:00:00"",
""Department"": ""IT"",
""JobTitle"": ""Support""
}", moss.ToString());
JObject jen = new JObject();
jen["FirstName"] = "Jen";
@@ -658,14 +650,13 @@ Parameter name: arrayIndex");
jen["Department"] = "IT";
jen["JobTitle"] = "Manager";
Console.WriteLine(jen.ToString());
//{
// "FirstName": "Jen",
// "LastName": "Barber",
// "BirthDate": "\/Date(258721200000+1300)\/",
// "Department": "IT",
// "JobTitle": "Manager"
//}
Assert.AreEqual(@"{
""FirstName"": ""Jen"",
""LastName"": ""Barber"",
""BirthDate"": ""1978-03-15T00:00:00"",
""Department"": ""IT"",
""JobTitle"": ""Manager""
}", jen.ToString());
}
[Test]
+25 -1
View File
@@ -1109,7 +1109,31 @@ namespace Newtonsoft.Json.Tests.Linq
JArray a2 = (JArray)a.DeepClone();
Console.WriteLine(a2.ToString(Formatting.Indented));
Assert.AreEqual(@"[
5,
[
1
],
[
1,
2
],
[
1,
2,
3
],
{
""First"": ""SGk="",
""Second"": 1,
""Third"": null,
""Fourth"": new Date(
12345
),
""Fifth"": ""Infinity"",
""Sixth"": ""NaN""
}
]", a2.ToString(Formatting.Indented));
Assert.IsTrue(a.DeepEquals(a2));
}
@@ -223,7 +223,7 @@ undefined
JToken v1 = o["frameworks"]["aspnetcore50"]["dependencies"]["System.Xml.ReaderWriter"]["source"];
Console.WriteLine(v1.Path);
Assert.AreEqual("frameworks.aspnetcore50.dependencies.['System.Xml.ReaderWriter'].source", v1.Path);
JToken v2 = o.SelectToken(v1.Path);
@@ -260,7 +260,9 @@ undefined
foreach (JObject friend in items)
{
Console.WriteLine(friend);
Assert.AreEqual(@"{
""name"": ""value!""
}", friend.ToString());
}
}
@@ -304,8 +306,7 @@ undefined
JsonSerializer serializer = new JsonSerializer();
Person p = (Person)serializer.Deserialize(new JTokenReader(o), typeof(Person));
// John Smith
Console.WriteLine(p.Name);
Assert.AreEqual("John Smith", p.Name);
}
[Test]
@@ -714,47 +715,40 @@ keyword such as type of business.""
from c in p.Categories
select new JValue(c)))))))));
Console.WriteLine(rss.ToString());
//{
// "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 being available on CodePlex",
// "link": "http://james.newtonking.com/projects/json-net.aspx",
// "category": [
// "Json.NET",
// "CodePlex"
// ]
// },
// {
// "title": "LINQ to JSON beta",
// "description": "Annoucing LINQ to JSON",
// "link": "http://james.newtonking.com/projects/json-net.aspx",
// "category": [
// "Json.NET",
// "LINQ"
// ]
// }
// ]
// }
//}
Assert.AreEqual(@"{
""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 being available on CodePlex"",
""link"": ""http://james.newtonking.com/projects/json-net.aspx"",
""category"": [
""Json.NET"",
""CodePlex""
]
},
{
""title"": ""LINQ to JSON beta"",
""description"": ""Annoucing LINQ to JSON"",
""link"": ""http://james.newtonking.com/projects/json-net.aspx"",
""category"": [
""Json.NET"",
""LINQ""
]
}
]
}
}", rss.ToString());
var postTitles =
from p in rss["channel"]["item"]
select p.Value<string>("title");
foreach (var item in postTitles)
{
Console.WriteLine(item);
}
//LINQ to JSON beta
//Json.NET 1.3 + New license + Now on CodePlex
Assert.AreEqual("Json.NET 1.3 + New license + Now on CodePlex", postTitles.ElementAt(0));
Assert.AreEqual("LINQ to JSON beta", postTitles.ElementAt(1));
var categories =
from c in rss["channel"]["item"].Children()["category"].Values<string>()
@@ -763,14 +757,12 @@ keyword such as type of business.""
orderby g.Count() descending
select new { Category = g.Key, Count = g.Count() };
foreach (var c in categories)
{
Console.WriteLine(c.Category + " - Count: " + c.Count);
}
//Json.NET - Count: 2
//LINQ - Count: 1
//CodePlex - Count: 1
Assert.AreEqual("Json.NET", categories.ElementAt(0).Category);
Assert.AreEqual(2, categories.ElementAt(0).Count);
Assert.AreEqual("CodePlex", categories.ElementAt(1).Category);
Assert.AreEqual(1, categories.ElementAt(1).Count);
Assert.AreEqual("LINQ", categories.ElementAt(2).Category);
Assert.AreEqual(1, categories.ElementAt(2).Count);
}
[Test]
@@ -930,7 +922,34 @@ keyword such as type of business.""
}
});
Console.WriteLine(o.ToString());
Assert.AreEqual(@"{
""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 being available on CodePlex"",
""link"": ""http://james.newtonking.com/projects/json-net.aspx"",
""category"": [
""Json.NET"",
""CodePlex""
]
},
{
""title"": ""LINQ to JSON beta"",
""description"": ""Annoucing LINQ to JSON"",
""link"": ""http://james.newtonking.com/projects/json-net.aspx"",
""category"": [
""Json.NET"",
""LINQ""
]
}
]
}
}", o.ToString());
CustomAssert.IsInstanceOfType(typeof(JObject), o);
CustomAssert.IsInstanceOfType(typeof(JObject), o["channel"]);
Assert.AreEqual("James Newton-King", (string)o["channel"]["title"]);
@@ -968,7 +987,34 @@ keyword such as type of business.""
}
});
Console.WriteLine(o.ToString());
Assert.AreEqual(@"{
""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 being available on CodePlex"",
""link"": ""http://james.newtonking.com/projects/json-net.aspx"",
""category"": [
""Json.NET"",
""CodePlex""
]
},
{
""title"": ""LINQ to JSON beta"",
""description"": ""Annoucing LINQ to JSON"",
""link"": ""http://james.newtonking.com/projects/json-net.aspx"",
""category"": [
""Json.NET"",
""LINQ""
]
}
]
}
}", o.ToString());
CustomAssert.IsInstanceOfType(typeof(JObject), o);
CustomAssert.IsInstanceOfType(typeof(JObject), o["channel"]);
Assert.AreEqual("James Newton-King", (string)o["channel"]["title"]);
@@ -76,4 +76,4 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.1.18321")]
[assembly: AssemblyFileVersion("7.0.1.18322")]
@@ -59,18 +59,13 @@ namespace Newtonsoft.Json.Tests.Schema
[TestCaseSourceAttribute("GetSpecTestDetails")]
public void SpecTest(JsonSchemaSpecTest jsonSchemaSpecTest)
{
//if (jsonSchemaSpecTest.ToString() == "enum.json - simple enum validation - something else is invalid")
{
Console.WriteLine("Running JSON Schema test " + jsonSchemaSpecTest.TestNumber + ": " + jsonSchemaSpecTest);
JsonSchema s = JsonSchema.Read(jsonSchemaSpecTest.Schema.CreateReader());
JsonSchema s = JsonSchema.Read(jsonSchemaSpecTest.Schema.CreateReader());
IList<string> errorMessages;
bool v = jsonSchemaSpecTest.Data.IsValid(s, out errorMessages);
errorMessages = errorMessages ?? new List<string>();
IList<string> errorMessages;
bool v = jsonSchemaSpecTest.Data.IsValid(s, out errorMessages);
errorMessages = errorMessages ?? new List<string>();
Assert.AreEqual(jsonSchemaSpecTest.IsValid, v, jsonSchemaSpecTest.TestCaseDescription + " - " + jsonSchemaSpecTest.TestDescription + " - errors: " + string.Join(", ", errorMessages));
}
Assert.AreEqual(jsonSchemaSpecTest.IsValid, v, jsonSchemaSpecTest.TestCaseDescription + " - " + jsonSchemaSpecTest.TestDescription + " - errors: " + string.Join(", ", errorMessages));
}
public IList<JsonSchemaSpecTest> GetSpecTestDetails()
@@ -373,7 +373,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void PopulateTest()
{
var test = JsonConvert.DeserializeObject<PopulateWithNullJsonTest>("{\"IntValue\":null}");
Console.WriteLine("IntValue:{0}", test.IntValue);
Assert.AreEqual(0, test.IntValue);
}
public class PopulateWithNullJsonTest
@@ -123,7 +123,16 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
});
Console.WriteLine(json);
Assert.AreEqual(@"{
""$type"": ""System.Dynamic.ExpandoObject, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"",
""Text"": ""Text!"",
""Integer"": 2147483647,
""DynamicChildObject"": {
""$type"": ""Newtonsoft.Json.Tests.Serialization.DynamicChildObject, Newtonsoft.Json.Tests, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null"",
""Text"": ""Child text!"",
""Integer"": -2147483648
}
}", json);
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full, null);
string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full, null);
@@ -268,8 +277,6 @@ namespace Newtonsoft.Json.Tests.Serialization
NullValueHandling = NullValueHandling.Ignore,
});
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""Explicit"": false,
""Text"": ""Text!"",
@@ -291,8 +298,6 @@ namespace Newtonsoft.Json.Tests.Serialization
NullValueHandling = NullValueHandling.Include,
});
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""Explicit"": false,
""Text"": ""Text!"",
@@ -318,8 +323,6 @@ namespace Newtonsoft.Json.Tests.Serialization
DefaultValueHandling = DefaultValueHandling.Ignore,
});
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""Text"": ""Text!"",
""Int"": 2147483647
@@ -150,7 +150,13 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(e, Formatting.Indented);
Console.WriteLine(json);
Assert.AreEqual(@"{
""extensionData1"": [
1,
2,
3
]
}", json);
Example e2 = JsonConvert.DeserializeObject<Example>(json);
@@ -66,9 +66,6 @@ namespace Newtonsoft.Json.Tests.Serialization
""II"",
""3""
]", json);
Console.WriteLine("Serialized immutable list:");
Console.WriteLine(json);
}
[Test]
@@ -100,17 +97,10 @@ namespace Newtonsoft.Json.Tests.Serialization
// what sorcery is this?!
IImmutableList<string> champions = JsonConvert.DeserializeObject<IImmutableList<string>>(json);
Console.WriteLine(champions[0]);
// Volibear
Assert.AreEqual(3, champions.Count);
Assert.AreEqual("Volibear", champions[0]);
Assert.AreEqual("Teemo", champions[1]);
Assert.AreEqual("Katarina", champions[2]);
Console.WriteLine("Deserialized immutable list:");
Console.WriteLine(string.Join(", ", champions));
}
#endregion
@@ -1522,16 +1522,10 @@ namespace Newtonsoft.Json.Tests.Serialization
List<Product> products = JsonConvert.DeserializeObject<List<Product>>(json);
Console.WriteLine(products.Count);
// 2
Product p1 = products[0];
Console.WriteLine(p1.Name);
// Product 1
Assert.AreEqual(2, products.Count);
Assert.AreEqual("Product 1", products[0].Name);
Assert.AreEqual("Product 1", p1.Name);
}
#if !(NET40 || NET35 || NET20 || PORTABLE40)
@@ -229,8 +229,6 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""FaqId"": 1,
""Name"": null,
@@ -256,8 +254,6 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""IsProxy"": true,
""FaqId"": 1,
@@ -1117,8 +1113,6 @@ namespace Newtonsoft.Json.Tests.Serialization
var stopWatch = Stopwatch.StartNew();
var deserialize = jsonSerializer.Deserialize(new StreamReader(ms), typeof(Dictionary<DictionaryKeyCast, int>));
stopWatch.Stop();
Console.WriteLine("Time elapsed: " + stopWatch.ElapsedMilliseconds);
}
#endif
@@ -1308,8 +1302,6 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(baseWith, Formatting.Indented);
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""VirtualWithDataMemberBase"": ""VirtualWithDataMember2!"",
""VirtualSub"": ""Virtual2!"",
@@ -1388,9 +1380,9 @@ namespace Newtonsoft.Json.Tests.Serialization
JObject jsonNetJson = JObject.Parse(JsonConvert.SerializeObject(o));
jsonNetJson = new JObject(jsonNetJson.Properties().OrderBy(p => p.Name));
Console.WriteLine("Results for " + o.GetType().Name);
Console.WriteLine("DataContractJsonSerializer: " + dataContractJson);
Console.WriteLine("JsonDotNetSerializer : " + jsonNetJson);
//Console.WriteLine("Results for " + o.GetType().Name);
//Console.WriteLine("DataContractJsonSerializer: " + dataContractJson);
//Console.WriteLine("JsonDotNetSerializer : " + jsonNetJson);
Assert.AreEqual(dataContractJson.Count, jsonNetJson.Count);
foreach (KeyValuePair<string, JToken> property in dataContractJson)
@@ -2235,11 +2227,10 @@ keyword such as type of business.""
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
Console.WriteLine(json);
//{
// "DefaultConverter": "\/Date(0)\/",
// "MemberConverter": "1970-01-01T00:00:00Z"
//}
Assert.AreEqual(@"{
""DefaultConverter"": ""1970-01-01T00:00:00Z"",
""MemberConverter"": ""1970-01-01T00:00:00Z""
}", json);
}
[Test]
@@ -2454,7 +2445,6 @@ keyword such as type of business.""
};
string json = JsonConvert.SerializeObject(requiredMembersClass);
Console.WriteLine(json);
}, "Cannot write a null value for property 'FirstName'. Property requires a value. Path ''.");
}
@@ -2591,9 +2581,9 @@ keyword such as type of business.""
string javascriptJson = JsonConvert.SerializeObject(entry, new JavaScriptDateTimeConverter());
// {"Details":"Application started.","LogDate":new Date(1234656000000)}
Console.WriteLine(defaultJson);
Console.WriteLine(isoJson);
Console.WriteLine(javascriptJson);
Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":""2009-02-15T00:00:00Z""}", defaultJson);
Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":""2009-02-15T00:00:00Z""}", isoJson);
Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":new Date(1234656000000)}", javascriptJson);
}
public void GenericListAndDictionaryInterfaceProperties()
@@ -3157,12 +3147,6 @@ keyword such as type of business.""
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Console.WriteLine(values.Count);
// 2
Console.WriteLine(values["key1"]);
// value1
Assert.AreEqual(2, values.Count);
Assert.AreEqual("value1", values["key1"]);
Assert.AreEqual("value2", values["key2"]);
@@ -3455,7 +3439,7 @@ Path '', line 1, position 1.");
};
string json = JsonConvert.SerializeObject(structTest, Formatting.Indented);
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""StringField"": ""StringField"",
""IntField"": 10,
@@ -4857,7 +4841,7 @@ Path '', line 1, position 1.");
string json = JsonConvert.SerializeObject(child);
Console.WriteLine(json);
Assert.AreEqual(@"{""_id"":2,""Name"":""Isabell"",""Father"":{""$ref"":null,""$id"":null,""blah"":""blah!""}}", json);
Dictionary<string, object> result = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
@@ -5700,7 +5684,10 @@ Path '', line 1, position 1.");
// ""nonVirtualMember"": ""NonVirtualMember!""
//}", result);
Console.WriteLine(result);
Assert.AreEqual(@"{
""virtualMember"": ""VirtualMember!"",
""nonVirtualMember"": ""NonVirtualMember!""
}", result);
}
[Test]
@@ -5719,7 +5706,7 @@ Path '', line 1, position 1.");
string xml = Encoding.UTF8.GetString(ms.ToArray(), 0, Convert.ToInt32(ms.Length));
Console.WriteLine(xml);
Assert.AreEqual(@"<JsonSerializerTest.ChildDataContract xmlns=""http://schemas.datacontract.org/2004/07/Newtonsoft.Json.Tests.Serialization"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><nonVirtualMember>NonVirtualMember!</nonVirtualMember><virtualMember>VirtualMember!</virtualMember><NewMember i:nil=""true""/></JsonSerializerTest.ChildDataContract>", xml);
}
#endif
@@ -5768,7 +5755,6 @@ Path '', line 1, position 1.");
};
string result = JsonConvert.SerializeObject(cc);
Console.WriteLine(result);
Assert.AreEqual(@"{""differentVirtualMember"":""VirtualMember!"",""nonVirtualMember"":""NonVirtualMember!""}", result);
}
@@ -6908,8 +6894,11 @@ Path '', line 1, position 1.");
JArray a = (JArray)JArray.ReadFrom(reader);
JValue v = (JValue)a[0];
Console.WriteLine(v.Value.GetType());
Console.WriteLine(a.ToString());
Assert.AreEqual(typeof(string), v.Value.GetType());
Assert.AreEqual(@"[
""2000-01-02T03:04:05+06:00""
]", a.ToString());
}
[Test]
@@ -7907,15 +7896,11 @@ Path '', line 1, position 1.");
string expected = JsonConvert.SerializeObject(dates, Formatting.Indented);
Console.WriteLine(expected);
string actual = JsonConvert.SerializeObject(dates, Formatting.Indented, new JsonSerializerSettings
{
DateFormatString = JsonSerializerSettings.DefaultDateFormatString
});
Console.WriteLine(expected);
Assert.AreEqual(expected, actual);
}
#endif
@@ -8202,7 +8187,8 @@ Path '', line 1, position 1.");
ParticipantEntity product = new ParticipantEntity();
product.Properties = new Dictionary<string, string> { { "s", "d" } };
string json = JsonConvert.SerializeObject(product);
Console.WriteLine(json);
Assert.AreEqual(@"{""pa_info"":{""s"":""d""}}", json);
ParticipantEntity deserializedProduct = JsonConvert.DeserializeObject<ParticipantEntity>(json);
}
@@ -8601,8 +8587,6 @@ Path '', line 1, position 1.");
var serializerSettings = new JsonSerializerSettings();
var jsonCopy = JsonConvert.SerializeObject(original, serializerSettings);
Console.WriteLine(original);
var clonedObject = JsonConvert.DeserializeObject<DerivedConstructorType>(jsonCopy, serializerSettings);
Assert.AreEqual("Base", clonedObject.BaseProperty);
@@ -70,8 +70,7 @@ namespace Newtonsoft.Json.Tests.Serialization
User u = (User)o;
Console.WriteLine(u.Name);
// James
Assert.AreEqual(u.Name, "James");
}
[Test]
@@ -119,7 +118,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
{
const string contextKey = "k1";
var someValue = Guid.NewGuid();
var someValue = new Guid("5dd2dba0-20c0-49f8-a054-1fa3b0a8d774");
Dictionary<string, Guid> inputContext = new Dictionary<string, Guid>();
inputContext.Add(contextKey, someValue);
@@ -132,7 +131,10 @@ namespace Newtonsoft.Json.Tests.Serialization
};
string serializedString = JsonConvert.SerializeObject(inputContext, jsonSerializerSettings);
Console.WriteLine(serializedString);
Assert.AreEqual(@"{
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Guid, mscorlib]], mscorlib"",
""k1"": ""5dd2dba0-20c0-49f8-a054-1fa3b0a8d774""
}", serializedString);
var deserializedObject = (Dictionary<string, Guid>)JsonConvert.DeserializeObject(serializedString, jsonSerializerSettings);
@@ -257,7 +259,15 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(child, Formatting.Indented);
Console.WriteLine(json);
Assert.AreEqual(@"{
""_id"": 2,
""Name"": ""Isabell"",
""Father"": {
""blah"": ""blah!"",
""$ref"": null,
""$id"": null
}
}", json);
Dictionary<string, object> result = JsonConvert.DeserializeObject<Dictionary<string, object>>(json, new JsonSerializerSettings
{
@@ -823,19 +823,16 @@ namespace Newtonsoft.Json.Tests.Serialization
List<Person> deserializedPeople = JsonConvert.DeserializeObject<List<Person>>(json,
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects });
Console.WriteLine(deserializedPeople.Count);
// 2
Assert.AreEqual(2, deserializedPeople.Count);
Person p1 = deserializedPeople[0];
Person p2 = deserializedPeople[1];
Console.WriteLine(p1.Name);
// James
Console.WriteLine(p2.Name);
// James
Assert.AreEqual("James", p1.Name);
Assert.AreEqual("James", p2.Name);
bool equal = Object.ReferenceEquals(p1, p2);
// true
Assert.AreEqual(true, equal);
}
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
@@ -370,13 +370,6 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(person, Formatting.Indented);
Console.WriteLine(json);
//{
// "Name": "George Michael Bluth",
// "Age": 16,
// "Title": "Mister Manager"
//}
StringAssert.AreEqual(@"{
""Name"": ""George Michael Bluth"",
""Age"": 16,
@@ -219,45 +219,32 @@ namespace Newtonsoft.Json.Tests.Serialization
{
SerializationEventTestObject obj = new SerializationEventTestObject();
Console.WriteLine(obj.Member1);
// 11
Console.WriteLine(obj.Member2);
// Hello World!
Console.WriteLine(obj.Member3);
// This is a nonserialized value
Console.WriteLine(obj.Member4);
// null
Console.WriteLine(obj.Member5);
// null
Assert.AreEqual(11, obj.Member1);
Assert.AreEqual("Hello World!", obj.Member2);
Assert.AreEqual("This is a nonserialized value", obj.Member3);
Assert.AreEqual(null, obj.Member4);
Assert.AreEqual(null, obj.Member5);
string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
// {
// "Member1": 11,
// "Member2": "This value went into the data file during serialization.",
// "Member4": null
// }
Assert.AreEqual(@"{
""Member1"": 11,
""Member2"": ""This value went into the data file during serialization."",
""Member4"": null
}", json);
Console.WriteLine(obj.Member1);
// 11
Console.WriteLine(obj.Member2);
// This value was reset after serialization.
Console.WriteLine(obj.Member3);
// This is a nonserialized value
Console.WriteLine(obj.Member4);
// null
Console.WriteLine(obj.Member5);
// Error message for member Member6 = Exception has been thrown by the target of an invocation.
Assert.AreEqual(11, obj.Member1);
Assert.AreEqual("This value was reset after serialization.", obj.Member2);
Assert.AreEqual("This is a nonserialized value", obj.Member3);
Assert.AreEqual(null, obj.Member4);
Assert.AreEqual("Error message for member Member6 = Error getting value from 'Member6' on 'Newtonsoft.Json.Tests.TestObjects.SerializationEventTestObject'.", obj.Member5);
obj = JsonConvert.DeserializeObject<SerializationEventTestObject>(json);
Console.WriteLine(obj.Member1);
// 11
Console.WriteLine(obj.Member2);
// This value went into the data file during serialization.
Console.WriteLine(obj.Member3);
// This value was set during deserialization
Console.WriteLine(obj.Member4);
// This value was set after deserialization.
Assert.AreEqual(11, obj.Member1);
Assert.AreEqual("This value went into the data file during serialization.", obj.Member2);
Assert.AreEqual("This value was set during deserialization", obj.Member3);
Assert.AreEqual("This value was set after deserialization.", obj.Member4);
Assert.AreEqual(null, obj.Member5);
}
public class SerializationEventBaseTestObject
@@ -356,9 +343,6 @@ namespace Newtonsoft.Json.Tests.Serialization
// persisted "Id" value into the renamed "Identifier"
// property, etc.
error.Handled = true;
// We never get here :(
Console.WriteLine("Error has been fixed");
}
}
@@ -135,8 +135,6 @@ namespace Newtonsoft.Json.Tests.Serialization
jsonSerializer.Serialize(jsonWriter, f, typeof(Foo1));
}
Console.WriteLine("Trace output:\n{0}", traceWriter.ToString());
return sw.ToString();
}
@@ -190,7 +188,17 @@ namespace Newtonsoft.Json.Tests.Serialization
// }
// ]
Console.WriteLine(json);
Assert.AreEqual(@"[
{
""Name"": ""Joe Employee"",
""Manager"": {
""Name"": ""Mike Manager""
}
},
{
""Name"": ""Mike Manager""
}
]", json);
}
[Test]
@@ -322,17 +330,26 @@ namespace Newtonsoft.Json.Tests.Serialization
// "Name": "Martha Family Details"
// }
//]
Console.WriteLine(json);
Assert.AreEqual(@"[
{
""Name"": ""Joe Family Details"",
""NumberOfChildren"": 4
},
{
""Name"": ""Martha Family Details""
}
]", json);
string mikeString = "{\"Name\": \"Mike Person\"}";
FamilyDetails mike = JsonConvert.DeserializeObject<FamilyDetails>(mikeString);
Console.WriteLine("mikeString specifies number of children: {0}", mike.NumberOfChildrenSpecified);
Assert.AreEqual(false, mike.NumberOfChildrenSpecified);
string mikeFullDisclosureString = "{\"Name\": \"Mike Person\", \"NumberOfChildren\": \"0\"}";
mike = JsonConvert.DeserializeObject<FamilyDetails>(mikeFullDisclosureString);
Console.WriteLine("mikeString specifies number of children: {0}", mike.NumberOfChildrenSpecified);
Assert.AreEqual(true, mike.NumberOfChildrenSpecified);
}
[Test]
@@ -90,7 +90,6 @@ Newtonsoft.Json Error: 0 : Error!
staff,
new JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new JavaScriptDateTimeConverter() } });
Console.WriteLine(traceWriter);
// 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
// 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
// 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
@@ -150,7 +149,6 @@ Newtonsoft.Json Error: 0 : Error!
MetadataPropertyHandling = MetadataPropertyHandling.Default
});
Console.WriteLine(traceWriter);
// 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
// 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
// 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
@@ -878,8 +876,6 @@ Newtonsoft.Json Error: 0 : Error!
traceWriter.Flush();
traceWriter.Close();
Console.WriteLine(traceWriter.GetJson());
StringAssert.AreEqual(@"{
""Array"": [
""String!"",
@@ -1039,8 +1035,6 @@ Newtonsoft.Json Error: 0 : Error!
traceReader.Close();
Console.WriteLine(traceReader.GetJson());
StringAssert.AreEqual(json, traceReader.GetJson());
}
#endif
@@ -101,8 +101,6 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameHandling = TypeNameHandling.Auto
});
Console.WriteLine(json);
StringAssert.AreEqual(@"{
""Collection"": [
""Collection value!""
@@ -1132,7 +1130,6 @@ namespace Newtonsoft.Json.Tests.Serialization
private void TestJsonSerializationRoundTrip(SerializableWrapper e, TypeNameHandling flag)
{
Console.WriteLine("Type Name Handling: " + flag.ToString());
StringWriter writer = new StringWriter();
//Create our serializer and set Type Name Handling appropriately
@@ -1141,8 +1138,6 @@ namespace Newtonsoft.Json.Tests.Serialization
//Do the actual serialization and dump to Console for inspection
serializer.Serialize(new JsonTextWriter(writer), e);
Console.WriteLine(writer.ToString());
Console.WriteLine();
//Now try to deserialize
//Json.Net will cause an error here as it will try and instantiate
@@ -1653,7 +1648,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
{
const string contextKey = "k1";
var someValue = Guid.NewGuid();
var someValue = new Guid("a6e986df-fc2c-4906-a1ef-9492388f7833");
Dictionary<string, Guid> inputContext = new Dictionary<string, Guid>();
inputContext.Add(contextKey, someValue);
@@ -1665,7 +1660,10 @@ namespace Newtonsoft.Json.Tests.Serialization
};
string serializedString = JsonConvert.SerializeObject(inputContext, jsonSerializerSettings);
Console.WriteLine(serializedString);
Assert.AreEqual(@"{
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Guid, mscorlib]], mscorlib"",
""k1"": ""a6e986df-fc2c-4906-a1ef-9492388f7833""
}", serializedString);
var deserializedObject = (Dictionary<string, Guid>)JsonConvert.DeserializeObject(serializedString, jsonSerializerSettings);
@@ -1799,19 +1797,15 @@ namespace Newtonsoft.Json.Tests.Serialization
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = FormatterAssemblyStyle.Full } // TypeNameHandling.Auto will work
);
Console.WriteLine(serialized);
var output = JsonConvert.DeserializeObject<List<Stack<string>>>(serialized,
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }
);
foreach (var stack in output)
{
foreach (var value in stack)
{
Console.WriteLine(value);
}
}
List<string> strings = output.SelectMany(s => s).ToList();
Assert.AreEqual(9, strings.Count);
Assert.AreEqual("One", strings[0]);
Assert.AreEqual("Nine", strings[8]);
}
#if !NET20
@@ -156,7 +156,7 @@ namespace Newtonsoft.Json.Tests.Utilities
private void AssertNewDateTimeParseEqual(string text)
{
Console.WriteLine("Parsing date text: " + text);
//Console.WriteLine("Parsing date text: " + text);
object oldDt;
TryParseDateIso(text, DateParseHandling.DateTime, DateTimeZoneHandling.RoundtripKind, out oldDt);
@@ -92,5 +92,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.1.18321")]
[assembly: AssemblyFileVersion("7.0.1.18322")]
[assembly: CLSCompliant(true)]