-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
@@ -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"]);