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