-Refactor ExceptionAssert

This commit is contained in:
James Newton-King
2014-09-12 21:33:53 +12:00
parent 4b9ce67ab7
commit dfb2ac17a5
43 changed files with 979 additions and 1482 deletions
@@ -204,9 +204,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
@"Index 1 not valid on JObject.",
() => { o.SelectToken("[1]", true); });
ExceptionAssert.Throws<JsonException>(() => { o.SelectToken("[1]", true); }, @"Index 1 not valid on JObject.");
}
[Test]
@@ -215,9 +213,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
@"Index * not valid on JObject.",
() => { o.SelectToken("[*]", true); });
ExceptionAssert.Throws<JsonException>(() => { o.SelectToken("[*]", true); }, @"Index * not valid on JObject.");
}
[Test]
@@ -226,9 +222,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
@"Array slice is not valid on JObject.",
() => { o.SelectToken("[:]", true); });
ExceptionAssert.Throws<JsonException>(() => { o.SelectToken("[:]", true); }, @"Array slice is not valid on JObject.");
}
[Test]
@@ -245,9 +239,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
@"Path returned multiple tokens.",
() => { a.SelectToken("[0, 1]"); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[0, 1]"); }, @"Path returned multiple tokens.");
}
[Test]
@@ -255,9 +247,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
@"Property 'BlahBlah' not valid on JArray.",
() => { a.SelectToken("BlahBlah", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("BlahBlah", true); }, @"Property 'BlahBlah' not valid on JArray.");
}
[Test]
@@ -265,9 +255,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
@"Index 9 outside the bounds of JArray.",
() => { a.SelectToken("[9,10]", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[9,10]", true); }, @"Index 9 outside the bounds of JArray.");
}
[Test]
@@ -275,9 +263,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JConstructor c = new JConstructor("Blah");
ExceptionAssert.Throws<JsonException>(
@"Index 1 outside the bounds of JConstructor.",
() => { c.SelectToken("[1]", true); });
ExceptionAssert.Throws<JsonException>(() => { c.SelectToken("[1]", true); }, @"Index 1 outside the bounds of JConstructor.");
}
[Test]
@@ -294,9 +280,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
"Property 'Missing' does not exist on JObject.",
() => { o.SelectToken("Missing", true); });
ExceptionAssert.Throws<JsonException>(() => { o.SelectToken("Missing", true); }, "Property 'Missing' does not exist on JObject.");
}
[Test]
@@ -315,9 +299,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
"Property 'Missing' does not exist on JObject.",
() => { o.SelectToken("['Missing','Missing2']", true); });
ExceptionAssert.Throws<JsonException>(() => { o.SelectToken("['Missing','Missing2']", true); }, "Property 'Missing' does not exist on JObject.");
}
[Test]
@@ -325,9 +307,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
"Properties 'Missing', 'Missing2' not valid on JArray.",
() => { a.SelectToken("['Missing','Missing2']", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("['Missing','Missing2']", true); }, "Properties 'Missing', 'Missing2' not valid on JArray.");
}
[Test]
@@ -335,23 +315,15 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
"Array slice of 99 to * returned no results.",
() => { a.SelectToken("[99:]", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[99:]", true); }, "Array slice of 99 to * returned no results.");
ExceptionAssert.Throws<JsonException>(
"Array slice of 1 to -19 returned no results.",
() => { a.SelectToken("[1:-19]", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[1:-19]", true); }, "Array slice of 1 to -19 returned no results.");
ExceptionAssert.Throws<JsonException>(
"Array slice of * to -19 returned no results.",
() => { a.SelectToken("[:-19]", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[:-19]", true); }, "Array slice of * to -19 returned no results.");
a = new JArray();
ExceptionAssert.Throws<JsonException>(
"Array slice of * to * returned no results.",
() => { a.SelectToken("[:]", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[:]", true); }, "Array slice of * to * returned no results.");
}
[Test]
@@ -368,9 +340,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
"Index 1000 outside the bounds of JArray.",
() => { a.SelectToken("[1000].Ha", true); });
ExceptionAssert.Throws<JsonException>(() => { a.SelectToken("[1000].Ha", true); }, "Index 1000 outside the bounds of JArray.");
}
[Test]
@@ -104,25 +104,19 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void RootWithBadWhitespace()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path: ",
() => { new JPath("$ .Blah"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("$ .Blah"); }, @"Unexpected character while parsing path: ");
}
[Test]
public void NoFieldNameAfterDot()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected end while parsing path.",
() => { new JPath("$.Blah."); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("$.Blah."); }, @"Unexpected end while parsing path.");
}
[Test]
public void RootWithBadWhitespace2()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path: ",
() => { new JPath("$. Blah"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("$. Blah"); }, @"Unexpected character while parsing path: ");
}
[Test]
@@ -273,9 +267,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void SinglePropertyAndFilterWithUnknownEscape()
{
ExceptionAssert.Throws<JsonException>(
@"Unknown escape chracter: \i",
() => { new JPath(@"Blah[ ?( @.name=='h\i' ) ]"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath(@"Blah[ ?( @.name=='h\i' ) ]"); }, @"Unknown escape chracter: \i");
}
[Test]
@@ -425,57 +417,49 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void BadOr1()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: )",
() => new JPath("[?(@.name||)]"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||)]"), "Unexpected character while parsing path query: )");
}
[Test]
public void BaddOr2()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: |",
() => new JPath("[?(@.name|)]"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name|)]"), "Unexpected character while parsing path query: |");
}
[Test]
public void BaddOr3()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: |",
() => new JPath("[?(@.name|"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name|"), "Unexpected character while parsing path query: |");
}
[Test]
public void BaddOr4()
{
ExceptionAssert.Throws<JsonException>("Path ended with open query.",
() => new JPath("[?(@.name||"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||"), "Path ended with open query.");
}
[Test]
public void NoAtAfterOr()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: s",
() => new JPath("[?(@.name||s"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||s"), "Unexpected character while parsing path query: s");
}
[Test]
public void NoPathAfterAt()
{
ExceptionAssert.Throws<JsonException>(@"Path ended with open query.",
() => new JPath("[?(@.name||@"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||@"), @"Path ended with open query.");
}
[Test]
public void NoPathAfterDot()
{
ExceptionAssert.Throws<JsonException>(@"Unexpected end while parsing path.",
() => new JPath("[?(@.name||@."));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||@."), @"Unexpected end while parsing path.");
}
[Test]
public void NoPathAfterDot2()
{
ExceptionAssert.Throws<JsonException>(@"Unexpected end while parsing path.",
() => new JPath("[?(@.name||@.)]"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||@.)]"), @"Unexpected end while parsing path.");
}
[Test]
@@ -502,17 +486,13 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void BadCharactersInIndexer()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path indexer: [",
() => { new JPath("Blah[[0]].Two.Three[1].Four"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("Blah[[0]].Two.Three[1].Four"); }, @"Unexpected character while parsing path indexer: [");
}
[Test]
public void UnclosedIndexer()
{
ExceptionAssert.Throws<JsonException>(
@"Path ended with open indexer.",
() => { new JPath("Blah[0"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("Blah[0"); }, @"Path ended with open indexer.");
}
[Test]
@@ -634,17 +614,13 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void EmptyIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Array index expected.",
() => { new JPath("[]"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("[]"); }, "Array index expected.");
}
[Test]
public void IndexerCloseInProperty()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character while parsing path: ]",
() => { new JPath("]"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("]"); }, "Unexpected character while parsing path: ]");
}
[Test]
@@ -661,9 +637,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void MissingDotAfterIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character following indexer: B",
() => { new JPath("[1]Blah"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("[1]Blah"); }, "Unexpected character following indexer: B");
}
}
}