-Refactor ExceptionAssert
This commit is contained in:
@@ -133,14 +133,12 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void JObjectPropertyNameWithNonToken()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Could not determine JSON object type for type System.String[].",
|
||||
() =>
|
||||
{
|
||||
dynamic d = new JObject();
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
dynamic d = new JObject();
|
||||
|
||||
d.First = new[] { "One", "II", "3" };
|
||||
});
|
||||
d.First = new[] { "One", "II", "3" };
|
||||
}, "Could not determine JSON object type for type System.String[].");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -127,10 +127,8 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentNullException>(
|
||||
@"Value cannot be null.
|
||||
Parameter name: array",
|
||||
() => { ((ICollection<JToken>)j).CopyTo(null, 0); });
|
||||
ExceptionAssert.Throws<ArgumentNullException>(() => { ((ICollection<JToken>)j).CopyTo(null, 0); }, @"Value cannot be null.
|
||||
Parameter name: array");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -138,10 +136,8 @@ Parameter name: array",
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||
@"arrayIndex is less than 0.
|
||||
Parameter name: arrayIndex",
|
||||
() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], -1); });
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], -1); }, @"arrayIndex is less than 0.
|
||||
Parameter name: arrayIndex");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -149,9 +145,7 @@ Parameter name: arrayIndex",
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"arrayIndex is equal to or greater than the length of array.",
|
||||
() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], 1); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], 1); }, @"arrayIndex is equal to or greater than the length of array.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -162,9 +156,7 @@ Parameter name: arrayIndex",
|
||||
j.Add(new JValue(2));
|
||||
j.Add(new JValue(3));
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.",
|
||||
() => { ((ICollection<JToken>)j).CopyTo(new JToken[3], 1); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { ((ICollection<JToken>)j).CopyTo(new JToken[3], 1); }, @"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -240,10 +232,8 @@ Parameter name: arrayIndex",
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||
@"Index is equal to or greater than Count.
|
||||
Parameter name: index",
|
||||
() => { j.RemoveAt(0); });
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => { j.RemoveAt(0); }, @"Index is equal to or greater than Count.
|
||||
Parameter name: index");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -251,10 +241,8 @@ Parameter name: index",
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||
@"Index is less than 0.
|
||||
Parameter name: index",
|
||||
() => { j.RemoveAt(-1); });
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => { j.RemoveAt(-1); }, @"Index is less than 0.
|
||||
Parameter name: index");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -332,10 +320,8 @@ Parameter name: index",
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||
@"Index was out of range. Must be non-negative and less than the size of the collection.
|
||||
Parameter name: index",
|
||||
() => { j.Insert(-1, new JValue(1)); });
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => { j.Insert(-1, new JValue(1)); }, @"Index was out of range. Must be non-negative and less than the size of the collection.
|
||||
Parameter name: index");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -343,10 +329,8 @@ Parameter name: index",
|
||||
{
|
||||
JArray j = new JArray();
|
||||
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||
@"Index must be within the bounds of the List.
|
||||
Parameter name: index",
|
||||
() => { j.Insert(2, new JValue(1)); });
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => { j.Insert(2, new JValue(1)); }, @"Index must be within the bounds of the List.
|
||||
Parameter name: index");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -376,9 +360,7 @@ Parameter name: index",
|
||||
{
|
||||
string json = @"{""prop"":""value""}";
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.",
|
||||
() => { JArray.Parse(json); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { JArray.Parse(json); }, "Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.");
|
||||
}
|
||||
|
||||
public class ListItemFields
|
||||
@@ -481,13 +463,11 @@ Parameter name: index",
|
||||
[Test]
|
||||
public void SetValueWithInvalidIndex()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"Set JArray values with invalid key value: ""badvalue"". Array position index expected.",
|
||||
() =>
|
||||
{
|
||||
JArray a = new JArray();
|
||||
a["badvalue"] = new JValue(3);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JArray a = new JArray();
|
||||
a["badvalue"] = new JValue(3);
|
||||
}, @"Set JArray values with invalid key value: ""badvalue"". Array position index expected.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -518,9 +498,7 @@ Parameter name: index",
|
||||
[Test]
|
||||
public void ParseIncomplete()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Unexpected end of content while loading JArray. Path '[0]', line 1, position 2.",
|
||||
() => { JArray.Parse("[1"); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { JArray.Parse("[1"); }, "Unexpected end of content while loading JArray. Path '[0]', line 1, position 2.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -544,9 +522,7 @@ Parameter name: index",
|
||||
""Large""
|
||||
], 987987";
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.",
|
||||
() => { JArray.Parse(json); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { JArray.Parse(json); }, "Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -84,12 +84,11 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void SetValueWithInvalidIndex()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(@"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.",
|
||||
() =>
|
||||
{
|
||||
JConstructor c = new JConstructor();
|
||||
c["badvalue"] = new JValue(3);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JConstructor c = new JConstructor();
|
||||
c["badvalue"] = new JValue(3);
|
||||
}, @"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -194,14 +194,12 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void DuplicatePropertyNameShouldThrow()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Can not add property PropertyNameValue to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o.Add("PropertyNameValue", null);
|
||||
o.Add("PropertyNameValue", null);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o.Add("PropertyNameValue", null);
|
||||
o.Add("PropertyNameValue", null);
|
||||
}, "Can not add property PropertyNameValue to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -308,55 +306,47 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void GenericCollectionCopyToNullArrayShouldThrow()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"Value cannot be null.
|
||||
Parameter name: array",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(null, 0);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(null, 0);
|
||||
}, @"Value cannot be null.
|
||||
Parameter name: array");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericCollectionCopyToNegativeArrayIndexShouldThrow()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||
@"arrayIndex is less than 0.
|
||||
Parameter name: arrayIndex",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(new KeyValuePair<string, JToken>[1], -1);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(new KeyValuePair<string, JToken>[1], -1);
|
||||
}, @"arrayIndex is less than 0.
|
||||
Parameter name: arrayIndex");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericCollectionCopyToArrayIndexEqualGreaterToArrayLengthShouldThrow()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"arrayIndex is equal to or greater than the length of array.",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(new KeyValuePair<string, JToken>[1], 1);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(new KeyValuePair<string, JToken>[1], 1);
|
||||
}, @"arrayIndex is equal to or greater than the length of array.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericCollectionCopyToInsufficientArrayCapacity()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o.Add("PropertyNameValue", new JValue(1));
|
||||
o.Add("PropertyNameValue2", new JValue(2));
|
||||
o.Add("PropertyNameValue3", new JValue(3));
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o.Add("PropertyNameValue", new JValue(1));
|
||||
o.Add("PropertyNameValue2", new JValue(2));
|
||||
o.Add("PropertyNameValue3", new JValue(3));
|
||||
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(new KeyValuePair<string, JToken>[3], 1);
|
||||
});
|
||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(new KeyValuePair<string, JToken>[3], 1);
|
||||
}, @"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -442,12 +432,11 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void Parse_ShouldThrowOnUnexpectedToken()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>("Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.",
|
||||
() =>
|
||||
{
|
||||
string json = @"[""prop""]";
|
||||
JObject.Parse(json);
|
||||
});
|
||||
ExceptionAssert.Throws<JsonReaderException>(() =>
|
||||
{
|
||||
string json = @"[""prop""]";
|
||||
JObject.Parse(json);
|
||||
}, "Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -478,12 +467,10 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void Blog()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Invalid property identifier character: ]. Path 'name', line 3, position 5.",
|
||||
() => { JObject.Parse(@"{
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { JObject.Parse(@"{
|
||||
""name"": ""James"",
|
||||
]!#$THIS IS: BAD JSON![{}}}}]
|
||||
}"); });
|
||||
}"); }, "Invalid property identifier character: ]. Path 'name', line 3, position 5.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -890,48 +877,42 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void IListAddBadToken()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
|
||||
l.Add(new JValue("Bad!"));
|
||||
});
|
||||
l.Add(new JValue("Bad!"));
|
||||
}, "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IListAddBadValue()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Argument is not a JToken.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
|
||||
l.Add("Bad!");
|
||||
});
|
||||
l.Add("Bad!");
|
||||
}, "Argument is not a JToken.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IListAddPropertyWithExistingName()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
|
||||
JProperty p3 = new JProperty("Test2", "II");
|
||||
JProperty p3 = new JProperty("Test2", "II");
|
||||
|
||||
l.Add(p3);
|
||||
});
|
||||
l.Add(p3);
|
||||
}, "Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1024,34 +1005,30 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void IListSetItemAlreadyExists()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
|
||||
JProperty p3 = new JProperty("Test3", "III");
|
||||
JProperty p3 = new JProperty("Test3", "III");
|
||||
|
||||
l[0] = p3;
|
||||
l[1] = p3;
|
||||
});
|
||||
l[0] = p3;
|
||||
l[1] = p3;
|
||||
}, "Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IListSetItemInvalid()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
@"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList l = new JObject(p1, p2);
|
||||
|
||||
l[0] = new JValue(true);
|
||||
});
|
||||
l[0] = new JValue(true);
|
||||
}, @"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1140,46 +1117,43 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void GenericListJTokenAddBadToken()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
|
||||
l.Add(new JValue("Bad!"));
|
||||
});
|
||||
l.Add(new JValue("Bad!"));
|
||||
}, "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericListJTokenAddBadValue()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
|
||||
// string is implicitly converted to JValue
|
||||
l.Add("Bad!");
|
||||
});
|
||||
// string is implicitly converted to JValue
|
||||
l.Add("Bad!");
|
||||
}, "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericListJTokenAddPropertyWithExistingName()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
|
||||
JProperty p3 = new JProperty("Test2", "II");
|
||||
JProperty p3 = new JProperty("Test2", "II");
|
||||
|
||||
l.Add(p3);
|
||||
});
|
||||
l.Add(p3);
|
||||
}, "Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1265,18 +1239,17 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void GenericListJTokenSetItemAlreadyExists()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
|
||||
() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JProperty p1 = new JProperty("Test1", 1);
|
||||
JProperty p2 = new JProperty("Test2", "Two");
|
||||
IList<JToken> l = new JObject(p1, p2);
|
||||
|
||||
JProperty p3 = new JProperty("Test3", "III");
|
||||
JProperty p3 = new JProperty("Test3", "III");
|
||||
|
||||
l[0] = p3;
|
||||
l[1] = p3;
|
||||
});
|
||||
l[0] = p3;
|
||||
l[1] = p3;
|
||||
}, "Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.");
|
||||
}
|
||||
|
||||
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
|
||||
@@ -1347,25 +1320,21 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void IBindingListApplySort()
|
||||
{
|
||||
ExceptionAssert.Throws<NotSupportedException>(
|
||||
"Specified method is not supported.",
|
||||
() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.ApplySort(null, ListSortDirection.Ascending);
|
||||
});
|
||||
ExceptionAssert.Throws<NotSupportedException>(() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.ApplySort(null, ListSortDirection.Ascending);
|
||||
}, "Specified method is not supported.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IBindingListRemoveSort()
|
||||
{
|
||||
ExceptionAssert.Throws<NotSupportedException>(
|
||||
"Specified method is not supported.",
|
||||
() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.RemoveSort();
|
||||
});
|
||||
ExceptionAssert.Throws<NotSupportedException>(() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.RemoveSort();
|
||||
}, "Specified method is not supported.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1379,13 +1348,11 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void IBindingListFind()
|
||||
{
|
||||
ExceptionAssert.Throws<NotSupportedException>(
|
||||
"Specified method is not supported.",
|
||||
() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.Find(null, null);
|
||||
});
|
||||
ExceptionAssert.Throws<NotSupportedException>(() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.Find(null, null);
|
||||
}, "Specified method is not supported.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1398,13 +1365,11 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void IBindingListAddNew()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Could not determine new value to add to 'Newtonsoft.Json.Linq.JObject'.",
|
||||
() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.AddNew();
|
||||
});
|
||||
ExceptionAssert.Throws<JsonException>(() =>
|
||||
{
|
||||
IBindingList l = new JObject();
|
||||
l.AddNew();
|
||||
}, "Could not determine new value to add to 'Newtonsoft.Json.Linq.JObject'.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1579,12 +1544,11 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void SetValueWithInvalidPropertyName()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Set JObject values with invalid key value: 0. Object property name expected.",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o[0] = new JValue(3);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o[0] = new JValue(3);
|
||||
}, "Set JObject values with invalid key value: 0. Object property name expected.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1635,44 +1599,41 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void InvalidValueCastExceptionMessage()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Object to String.",
|
||||
() =>
|
||||
{
|
||||
string json = @"{
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
string json = @"{
|
||||
""responseData"": {},
|
||||
""responseDetails"": null,
|
||||
""responseStatus"": 200
|
||||
}";
|
||||
|
||||
JObject o = JObject.Parse(json);
|
||||
JObject o = JObject.Parse(json);
|
||||
|
||||
string name = (string)o["responseData"];
|
||||
});
|
||||
string name = (string)o["responseData"];
|
||||
}, "Can not convert Object to String.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidPropertyValueCastExceptionMessage()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Object to String.",
|
||||
() =>
|
||||
{
|
||||
string json = @"{
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
string json = @"{
|
||||
""responseData"": {},
|
||||
""responseDetails"": null,
|
||||
""responseStatus"": 200
|
||||
}";
|
||||
|
||||
JObject o = JObject.Parse(json);
|
||||
JObject o = JObject.Parse(json);
|
||||
|
||||
string name = (string)o.Property("responseData");
|
||||
});
|
||||
string name = (string)o.Property("responseData");
|
||||
}, "Can not convert Object to String.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseIncomplete()
|
||||
{
|
||||
ExceptionAssert.Throws<Exception>("Unexpected end of content while loading JObject. Path 'foo', line 1, position 6.",
|
||||
() => { JObject.Parse("{ foo:"); });
|
||||
ExceptionAssert.Throws<Exception>(() => { JObject.Parse("{ foo:"); }, "Unexpected end of content while loading JObject. Path 'foo', line 1, position 6.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1707,25 +1668,24 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void LoadFromNestedObjectIncomplete()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>("Unexpected end of content while loading JObject. Path 'short.error.code', line 6, position 15.",
|
||||
() =>
|
||||
{
|
||||
string jsonText = @"{
|
||||
ExceptionAssert.Throws<JsonReaderException>(() =>
|
||||
{
|
||||
string jsonText = @"{
|
||||
""short"":
|
||||
{
|
||||
""error"":
|
||||
{
|
||||
""code"":0";
|
||||
|
||||
JsonReader reader = new JsonTextReader(new StringReader(jsonText));
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
JsonReader reader = new JsonTextReader(new StringReader(jsonText));
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
|
||||
JToken.ReadFrom(reader);
|
||||
});
|
||||
JToken.ReadFrom(reader);
|
||||
}, "Unexpected end of content while loading JObject. Path 'short.error.code', line 6, position 15.");
|
||||
}
|
||||
|
||||
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
|
||||
@@ -1806,10 +1766,9 @@ Parameter name: arrayIndex",
|
||||
[Test]
|
||||
public void ParseAdditionalContent()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>("Additional text encountered after finished reading JSON content: ,. Path '', line 10, position 2.",
|
||||
() =>
|
||||
{
|
||||
string json = @"{
|
||||
ExceptionAssert.Throws<JsonReaderException>(() =>
|
||||
{
|
||||
string json = @"{
|
||||
""Name"": ""Apple"",
|
||||
""Expiry"": new Date(1230422400000),
|
||||
""Price"": 3.99,
|
||||
@@ -1820,8 +1779,8 @@ Parameter name: arrayIndex",
|
||||
]
|
||||
}, 987987";
|
||||
|
||||
JObject o = JObject.Parse(json);
|
||||
});
|
||||
JObject o = JObject.Parse(json);
|
||||
}, "Additional text encountered after finished reading JSON content: ,. Path '', line 10, position 2.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -99,9 +99,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
JProperty p = new JProperty("TestProperty", null);
|
||||
IList l = p;
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
||||
() => { l.Clear(); });
|
||||
ExceptionAssert.Throws<JsonException>(() => { l.Clear(); }, "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -110,9 +108,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
JProperty p = new JProperty("TestProperty", null);
|
||||
IList l = p;
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
|
||||
() => { l.Add(null); });
|
||||
ExceptionAssert.Throws<JsonException>(() => { l.Add(null); }, "Newtonsoft.Json.Linq.JProperty cannot have multiple values.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -121,9 +117,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
JProperty p = new JProperty("TestProperty", null);
|
||||
IList l = p;
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
||||
() => { l.Remove(p.Value); });
|
||||
ExceptionAssert.Throws<JsonException>(() => { l.Remove(p.Value); }, "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -132,9 +126,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
JProperty p = new JProperty("TestProperty", null);
|
||||
IList l = p;
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
||||
() => { l.RemoveAt(0); });
|
||||
ExceptionAssert.Throws<JsonException>(() => { l.RemoveAt(0); }, "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -223,9 +215,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
{
|
||||
IList<JToken> t = new JProperty("error", new List<string> { "one", "two" });
|
||||
|
||||
ExceptionAssert.Throws<JsonException>(
|
||||
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
|
||||
() => { t.Add(1); });
|
||||
ExceptionAssert.Throws<JsonException>(() => { t.Add(1); }, "Newtonsoft.Json.Linq.JProperty cannot have multiple values.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,14 +49,12 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
{
|
||||
JObject json = JObject.Parse(@"{""IntList"":[1, ""two""]}");
|
||||
|
||||
ExceptionAssert.Throws<Exception>(
|
||||
"Could not convert string to integer: two. Path 'IntList[1]', line 1, position 20.",
|
||||
() =>
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
ExceptionAssert.Throws<Exception>(() =>
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
|
||||
serializer.Deserialize<TraceTestObject>(json.CreateReader());
|
||||
});
|
||||
serializer.Deserialize<TraceTestObject>(json.CreateReader());
|
||||
}, "Could not convert string to integer: two. Path 'IntList[1]', line 1, position 20.");
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
@@ -152,9 +150,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Could not convert string to DateTimeOffset: blablahbla. Path 'Offset', line 1, position 22.",
|
||||
() => { reader.ReadAsDateTimeOffset(); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDateTimeOffset(); }, "Could not convert string to DateTimeOffset: blablahbla. Path 'Offset', line 1, position 22.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -172,9 +168,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Error reading date. Unexpected token: Boolean. Path 'Offset', line 1, position 14.",
|
||||
() => { reader.ReadAsDateTimeOffset(); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDateTimeOffset(); }, "Error reading date. Unexpected token: Boolean. Path 'Offset', line 1, position 14.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -320,27 +314,25 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void ReadBytesFailure()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Error reading bytes. Unexpected token: Integer. Path 'Test1'.",
|
||||
() =>
|
||||
ExceptionAssert.Throws<JsonReaderException>(() =>
|
||||
{
|
||||
JObject o =
|
||||
new JObject(
|
||||
new JProperty("Test1", 1)
|
||||
);
|
||||
|
||||
using (JTokenReader jsonReader = new JTokenReader(o))
|
||||
{
|
||||
JObject o =
|
||||
new JObject(
|
||||
new JProperty("Test1", 1)
|
||||
);
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
|
||||
|
||||
using (JTokenReader jsonReader = new JTokenReader(o))
|
||||
{
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
|
||||
Assert.AreEqual("Test1", jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
|
||||
Assert.AreEqual("Test1", jsonReader.Value);
|
||||
|
||||
jsonReader.ReadAsBytes();
|
||||
}
|
||||
});
|
||||
jsonReader.ReadAsBytes();
|
||||
}
|
||||
}, "Error reading bytes. Unexpected token: Integer. Path 'Test1'.");
|
||||
}
|
||||
|
||||
public class HasBytes
|
||||
@@ -504,9 +496,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Could not convert string to integer: hi. Path 'Name', line 1, position 12.",
|
||||
() => { reader.ReadAsInt32(); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsInt32(); }, "Could not convert string to integer: hi. Path 'Name', line 1, position 12.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -524,9 +514,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Error reading integer. Unexpected token: Boolean. Path 'Name', line 1, position 12.",
|
||||
() => { reader.ReadAsInt32(); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsInt32(); }, "Error reading integer. Unexpected token: Boolean. Path 'Name', line 1, position 12.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -565,9 +553,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Could not convert string to decimal: blah. Path 'Name', line 1, position 14.",
|
||||
() => { reader.ReadAsDecimal(); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDecimal(); }, "Could not convert string to decimal: blah. Path 'Name', line 1, position 14.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -585,9 +571,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Error reading decimal. Unexpected token: Boolean. Path 'Name', line 1, position 12.",
|
||||
() => { reader.ReadAsDecimal(); });
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDecimal(); }, "Error reading decimal. Unexpected token: Boolean. Path 'Name', line 1, position 12.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -386,67 +386,67 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void FailedCasting()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to DateTime.", () => { var i = (DateTime)new JValue(true); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Integer to DateTime.", () => { var i = (DateTime)new JValue(1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to DateTime.", () => { var i = (DateTime)new JValue(1.1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to DateTime.", () => { var i = (DateTime)new JValue(1.1m); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert TimeSpan to DateTime.", () => { var i = (DateTime)new JValue(TimeSpan.Zero); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Uri to DateTime.", () => { var i = (DateTime)new JValue(new Uri("http://www.google.com")); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to DateTime.", () => { var i = (DateTime)JValue.CreateNull(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to DateTime.", () => { var i = (DateTime)new JValue(Guid.NewGuid()); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(true); }, "Can not convert Boolean to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(1); }, "Can not convert Integer to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(1.1); }, "Can not convert Float to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(1.1m); }, "Can not convert Float to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(TimeSpan.Zero); }, "Can not convert TimeSpan to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(new Uri("http://www.google.com")); }, "Can not convert Uri to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)JValue.CreateNull(); }, "Can not convert Null to DateTime.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTime)new JValue(Guid.NewGuid()); }, "Can not convert Guid to DateTime.");
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to Uri.", () => { var i = (Uri)new JValue(true); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Integer to Uri.", () => { var i = (Uri)new JValue(1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to Uri.", () => { var i = (Uri)new JValue(1.1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to Uri.", () => { var i = (Uri)new JValue(1.1m); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert TimeSpan to Uri.", () => { var i = (Uri)new JValue(TimeSpan.Zero); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to Uri.", () => { var i = (Uri)new JValue(Guid.NewGuid()); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to Uri.", () => { var i = (Uri)new JValue(DateTime.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(true); }, "Can not convert Boolean to Uri.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(1); }, "Can not convert Integer to Uri.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(1.1); }, "Can not convert Float to Uri.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(1.1m); }, "Can not convert Float to Uri.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(TimeSpan.Zero); }, "Can not convert TimeSpan to Uri.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(Guid.NewGuid()); }, "Can not convert Guid to Uri.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(DateTime.Now); }, "Can not convert Date to Uri.");
|
||||
#if !NET20
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to Uri.", () => { var i = (Uri)new JValue(DateTimeOffset.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(DateTimeOffset.Now); }, "Can not convert Date to Uri.");
|
||||
#endif
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to TimeSpan.", () => { var i = (TimeSpan)new JValue(true); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Integer to TimeSpan.", () => { var i = (TimeSpan)new JValue(1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to TimeSpan.", () => { var i = (TimeSpan)new JValue(1.1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to TimeSpan.", () => { var i = (TimeSpan)new JValue(1.1m); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to TimeSpan.", () => { var i = (TimeSpan)JValue.CreateNull(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to TimeSpan.", () => { var i = (TimeSpan)new JValue(Guid.NewGuid()); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to TimeSpan.", () => { var i = (TimeSpan)new JValue(DateTime.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(true); }, "Can not convert Boolean to TimeSpan.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(1); }, "Can not convert Integer to TimeSpan.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(1.1); }, "Can not convert Float to TimeSpan.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(1.1m); }, "Can not convert Float to TimeSpan.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)JValue.CreateNull(); }, "Can not convert Null to TimeSpan.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(Guid.NewGuid()); }, "Can not convert Guid to TimeSpan.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(DateTime.Now); }, "Can not convert Date to TimeSpan.");
|
||||
#if !NET20
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to TimeSpan.", () => { var i = (TimeSpan)new JValue(DateTimeOffset.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(DateTimeOffset.Now); }, "Can not convert Date to TimeSpan.");
|
||||
#endif
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Uri to TimeSpan.", () => { var i = (TimeSpan)new JValue(new Uri("http://www.google.com")); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (TimeSpan)new JValue(new Uri("http://www.google.com")); }, "Can not convert Uri to TimeSpan.");
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to Guid.", () => { var i = (Guid)new JValue(true); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Integer to Guid.", () => { var i = (Guid)new JValue(1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to Guid.", () => { var i = (Guid)new JValue(1.1); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Float to Guid.", () => { var i = (Guid)new JValue(1.1m); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to Guid.", () => { var i = (Guid)JValue.CreateNull(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to Guid.", () => { var i = (Guid)new JValue(DateTime.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(true); }, "Can not convert Boolean to Guid.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(1); }, "Can not convert Integer to Guid.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(1.1); }, "Can not convert Float to Guid.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(1.1m); }, "Can not convert Float to Guid.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)JValue.CreateNull(); }, "Can not convert Null to Guid.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(DateTime.Now); }, "Can not convert Date to Guid.");
|
||||
#if !NET20
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to Guid.", () => { var i = (Guid)new JValue(DateTimeOffset.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(DateTimeOffset.Now); }, "Can not convert Date to Guid.");
|
||||
#endif
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert TimeSpan to Guid.", () => { var i = (Guid)new JValue(TimeSpan.FromMinutes(1)); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Uri to Guid.", () => { var i = (Guid)new JValue(new Uri("http://www.google.com")); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(TimeSpan.FromMinutes(1)); }, "Can not convert TimeSpan to Guid.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Guid)new JValue(new Uri("http://www.google.com")); }, "Can not convert Uri to Guid.");
|
||||
|
||||
#if !NET20
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to DateTimeOffset.", () => { var i = (DateTimeOffset)new JValue(true); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (DateTimeOffset)new JValue(true); }, "Can not convert Boolean to DateTimeOffset.");
|
||||
#endif
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to Uri.", () => { var i = (Uri)new JValue(true); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(true); }, "Can not convert Boolean to Uri.");
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Uri to BigInteger.", () => { var i = (new JValue(new Uri("http://www.google.com"))).ToObject<BigInteger>(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to BigInteger.", () => { var i = (JValue.CreateNull()).ToObject<BigInteger>(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to BigInteger.", () => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger>(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to BigInteger.", () => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger?>(); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue(new Uri("http://www.google.com"))).ToObject<BigInteger>(); }, "Can not convert Uri to BigInteger.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (JValue.CreateNull()).ToObject<BigInteger>(); }, "Can not convert Null to BigInteger.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger>(); }, "Can not convert Guid to BigInteger.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger?>(); }, "Can not convert Guid to BigInteger.");
|
||||
#endif
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to SByte.", () => { var i = (sbyte?)new JValue(DateTime.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Date to SByte.", () => { var i = (sbyte)new JValue(DateTime.Now); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (sbyte?)new JValue(DateTime.Now); }, "Can not convert Date to SByte.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (sbyte)new JValue(DateTime.Now); }, "Can not convert Date to SByte.");
|
||||
|
||||
ExceptionAssert.Throws<ArgumentException>("Could not convert 'Ordinal1' to StringComparison.", () => { var i = (new JValue("Ordinal1")).ToObject<StringComparison>(); });
|
||||
ExceptionAssert.Throws<ArgumentException>("Could not convert 'Ordinal1' to StringComparison.", () => { var i = (new JValue("Ordinal1")).ToObject<StringComparison?>(); });
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue("Ordinal1")).ToObject<StringComparison>(); }, "Could not convert 'Ordinal1' to StringComparison.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue("Ordinal1")).ToObject<StringComparison?>(); }, "Could not convert 'Ordinal1' to StringComparison.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -790,24 +790,21 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void AddPropertyToArray()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not add Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JArray.",
|
||||
() =>
|
||||
{
|
||||
JArray a = new JArray();
|
||||
a.Add(new JProperty("PropertyName"));
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JArray a = new JArray();
|
||||
a.Add(new JProperty("PropertyName"));
|
||||
}, "Can not add Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JArray.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddValueToObject()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o.Add(5);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
o.Add(5);
|
||||
}, "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1004,17 +1001,16 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void ParseAdditionalContent()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonReaderException>("Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.",
|
||||
() =>
|
||||
{
|
||||
string json = @"[
|
||||
ExceptionAssert.Throws<JsonReaderException>(() =>
|
||||
{
|
||||
string json = @"[
|
||||
""Small"",
|
||||
""Medium"",
|
||||
""Large""
|
||||
],";
|
||||
|
||||
JToken.Parse(json);
|
||||
});
|
||||
JToken.Parse(json);
|
||||
}, "Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -233,12 +233,11 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void Last()
|
||||
{
|
||||
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
|
||||
() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
JToken last = v.Last;
|
||||
});
|
||||
ExceptionAssert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
JToken last = v.Last;
|
||||
}, "Cannot access child value on Newtonsoft.Json.Linq.JValue.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -252,45 +251,41 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void First()
|
||||
{
|
||||
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
|
||||
() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
JToken first = v.First;
|
||||
});
|
||||
ExceptionAssert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
JToken first = v.First;
|
||||
}, "Cannot access child value on Newtonsoft.Json.Linq.JValue.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Item()
|
||||
{
|
||||
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
|
||||
() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
JToken first = v[0];
|
||||
});
|
||||
ExceptionAssert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
JToken first = v[0];
|
||||
}, "Cannot access child value on Newtonsoft.Json.Linq.JValue.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Values()
|
||||
{
|
||||
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
|
||||
() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
v.Values<int>();
|
||||
});
|
||||
ExceptionAssert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
v.Values<int>();
|
||||
}, "Cannot access child value on Newtonsoft.Json.Linq.JValue.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveParentNull()
|
||||
{
|
||||
ExceptionAssert.Throws<InvalidOperationException>("The parent is missing.",
|
||||
() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
v.Remove();
|
||||
});
|
||||
ExceptionAssert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
JValue v = new JValue(true);
|
||||
v.Remove();
|
||||
}, "The parent is missing.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -331,23 +326,21 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void SetValue()
|
||||
{
|
||||
ExceptionAssert.Throws<InvalidOperationException>("Cannot set child value on Newtonsoft.Json.Linq.JValue.",
|
||||
() =>
|
||||
{
|
||||
JToken t = new JValue(5L);
|
||||
t[0] = new JValue(3);
|
||||
});
|
||||
ExceptionAssert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
JToken t = new JValue(5L);
|
||||
t[0] = new JValue(3);
|
||||
}, "Cannot set child value on Newtonsoft.Json.Linq.JValue.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CastNullValueToNonNullable()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to Int32.",
|
||||
() =>
|
||||
{
|
||||
JValue v = JValue.CreateNull();
|
||||
int i = (int)v;
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JValue v = JValue.CreateNull();
|
||||
int i = (int)v;
|
||||
}, "Can not convert Null to Int32.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,8 +120,7 @@ undefined
|
||||
jsonReader.Read();
|
||||
jsonReader.Read();
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(@"Error reading JToken from JsonReader. Unexpected token: EndArray. Path '', line 1, position 2.",
|
||||
() => JToken.ReadFrom(jsonReader));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => JToken.ReadFrom(jsonReader), @"Error reading JToken from JsonReader. Unexpected token: EndArray. Path '', line 1, position 2.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -711,34 +710,31 @@ keyword such as type of business.""
|
||||
[Test]
|
||||
public void JObjectIntIndex()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>("Accessed JObject values with invalid key value: 0. Object property name expected.",
|
||||
() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
Assert.AreEqual(null, o[0]);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JObject o = new JObject();
|
||||
Assert.AreEqual(null, o[0]);
|
||||
}, "Accessed JObject values with invalid key value: 0. Object property name expected.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JArrayStringIndex()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(@"Accessed JArray values with invalid key value: ""purple"". Array position index expected.",
|
||||
() =>
|
||||
{
|
||||
JArray a = new JArray();
|
||||
Assert.AreEqual(null, a["purple"]);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JArray a = new JArray();
|
||||
Assert.AreEqual(null, a["purple"]);
|
||||
}, @"Accessed JArray values with invalid key value: ""purple"". Array position index expected.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JConstructorStringIndex()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(@"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.",
|
||||
() =>
|
||||
{
|
||||
JConstructor c = new JConstructor("ConstructorValue");
|
||||
Assert.AreEqual(null, c["purple"]);
|
||||
});
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
JConstructor c = new JConstructor("ConstructorValue");
|
||||
Assert.AreEqual(null, c["purple"]);
|
||||
}, @"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.");
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
@@ -1065,13 +1061,12 @@ keyword such as type of business.""
|
||||
IDictionary<string, string> users = new Dictionary<string, string>();
|
||||
|
||||
// unfortunatly there doesn't appear to be a way around this
|
||||
ExceptionAssert.Throws<Microsoft.CSharp.RuntimeBinder.RuntimeBinderException>("The best overloaded method match for 'System.Collections.Generic.IDictionary<string,string>.Add(string, string)' has some invalid arguments",
|
||||
() =>
|
||||
{
|
||||
users.Add("name2", name);
|
||||
ExceptionAssert.Throws<Microsoft.CSharp.RuntimeBinder.RuntimeBinderException>(() =>
|
||||
{
|
||||
users.Add("name2", name);
|
||||
|
||||
Assert.AreEqual(users["name2"], "Matthew Doig");
|
||||
});
|
||||
Assert.AreEqual(users["name2"], "Matthew Doig");
|
||||
}, "The best overloaded method match for 'System.Collections.Generic.IDictionary<string,string>.Add(string, string)' has some invalid arguments");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user