-Added Path to JsonReaderException/JsonSerializationException messages

-Added JsonException
-Fixed all Exceptions thrown to be more specific
This commit is contained in:
James Newton-King
2012-04-21 17:25:44 +12:00
parent c120bf530d
commit a7bddf989f
69 changed files with 1400 additions and 1161 deletions
+60 -60
View File
@@ -59,25 +59,25 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Unexpected character while parsing path indexer: ["
#endif
)]
public void BadCharactersInIndexer()
{
new JPath("Blah[[0]].Two.Three[1].Four");
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path indexer: [",
() =>
{
new JPath("Blah[[0]].Two.Three[1].Four");
});
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Path ended with open indexer. Expected ]"
#endif
)]
public void UnclosedIndexer()
{
new JPath("Blah[0");
ExceptionAssert.Throws<JsonException>(
@"Path ended with open indexer. Expected ]",
() =>
{
new JPath("Blah[0");
});
}
[Test]
@@ -102,25 +102,25 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Empty path indexer."
#endif
)]
public void EmptyIndexer()
{
new JPath("[]");
ExceptionAssert.Throws<JsonException>(
"Empty path indexer.",
() =>
{
new JPath("[]");
});
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character while parsing path: ]"
#endif
)]
public void IndexerCloseInProperty()
{
new JPath("]");
ExceptionAssert.Throws<JsonException>(
"Unexpected character while parsing path: ]",
() =>
{
new JPath("]");
});
}
[Test]
@@ -135,14 +135,14 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character following indexer: B"
#endif
)]
public void MissingDotAfterIndexer()
{
new JPath("[1]Blah");
ExceptionAssert.Throws<JsonException>(
"Unexpected character following indexer: B",
() =>
{
new JPath("[1]Blah");
});
}
[Test]
@@ -178,17 +178,17 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Index 1 not valid on JObject."
#endif
)]
public void EvaluateIndexerOnObjectWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
o.SelectToken("[1]", true);
ExceptionAssert.Throws<JsonException>(
@"Index 1 not valid on JObject.",
() =>
{
o.SelectToken("[1]", true);
});
}
[Test]
@@ -201,43 +201,43 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Property 'BlahBlah' not valid on JArray."
#endif
)]
public void EvaluatePropertyOnArrayWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
a.SelectToken("BlahBlah", true);
ExceptionAssert.Throws<JsonException>(
@"Property 'BlahBlah' not valid on JArray.",
() =>
{
a.SelectToken("BlahBlah", true);
});
}
[Test]
[ExpectedException(typeof(IndexOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"Index 1 outside the bounds of JConstructor."
#endif
)]
public void EvaluateConstructorOutOfBoundsIndxerWithError()
{
JConstructor c = new JConstructor("Blah");
c.SelectToken("[1]", true);
ExceptionAssert.Throws<IndexOutOfRangeException>(
@"Index 1 outside the bounds of JConstructor.",
() =>
{
c.SelectToken("[1]", true);
});
}
[Test]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Property 'Missing' does not exist on JObject."
#endif
)]
public void EvaluateMissingPropertyWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
o.SelectToken("Missing", true);
ExceptionAssert.Throws<JsonException>(
"Property 'Missing' does not exist on JObject.",
() =>
{
o.SelectToken("Missing", true);
});
}
[Test]
@@ -250,16 +250,16 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(IndexOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = "Index 1000 outside the bounds of JArray."
#endif
)]
public void EvaluateArrayOutOfBoundsIndxerWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
a.SelectToken("[1000].Ha", true);
ExceptionAssert.Throws<IndexOutOfRangeException>(
"Index 1000 outside the bounds of JArray.",
() =>
{
a.SelectToken("[1000].Ha", true);
});
}
[Test]