-Code reformat

This commit is contained in:
James Newton-King
2013-10-20 15:08:39 +13:00
parent d03963016e
commit bcd6982419
466 changed files with 71645 additions and 71598 deletions
@@ -30,46 +30,47 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq.ComponentModel
{
[TestFixture]
public class BindingTests : TestFixtureBase
{
[Test]
public void DataBinderEval()
[TestFixture]
public class BindingTests : TestFixtureBase
{
JObject o = new JObject(
new JProperty("First", "String!"),
new JProperty("Second", 12345.6789m),
new JProperty("Third", new JArray(
1,
2,
3,
4,
5,
new JObject(
new JProperty("Fourth", "String!"),
new JProperty("Fifth", new JObject(
new JProperty("Sixth", "String!")))))));
[Test]
public void DataBinderEval()
{
JObject o = new JObject(
new JProperty("First", "String!"),
new JProperty("Second", 12345.6789m),
new JProperty("Third", new JArray(
1,
2,
3,
4,
5,
new JObject(
new JProperty("Fourth", "String!"),
new JProperty("Fifth", new JObject(
new JProperty("Sixth", "String!")))))));
object value;
object value;
value = (string)DataBinder.Eval(o, "First.Value");
Assert.AreEqual(value, (string)o["First"]);
value = (string)DataBinder.Eval(o, "First.Value");
Assert.AreEqual(value, (string)o["First"]);
value = DataBinder.Eval(o, "Second.Value");
Assert.AreEqual(value, (decimal)o["Second"]);
value = DataBinder.Eval(o, "Second.Value");
Assert.AreEqual(value, (decimal)o["Second"]);
value = DataBinder.Eval(o, "Third");
Assert.AreEqual(value, o["Third"]);
value = DataBinder.Eval(o, "Third");
Assert.AreEqual(value, o["Third"]);
value = DataBinder.Eval(o, "Third[0].Value");
Assert.AreEqual((int)value, (int)o["Third"][0]);
value = DataBinder.Eval(o, "Third[0].Value");
Assert.AreEqual((int)value, (int)o["Third"][0]);
value = DataBinder.Eval(o, "Third[5].Fourth.Value");
Assert.AreEqual(value, (string)o["Third"][5]["Fourth"]);
value = DataBinder.Eval(o, "Third[5].Fourth.Value");
Assert.AreEqual(value, (string)o["Third"][5]["Fourth"]);
value = DataBinder.Eval(o, "Third[5].Fifth.Sixth.Value");
Assert.AreEqual(value, (string)o["Third"][5]["Fifth"]["Sixth"]);
value = DataBinder.Eval(o, "Third[5].Fifth.Sixth.Value");
Assert.AreEqual(value, (string)o["Third"][5]["Fifth"]["Sixth"]);
}
}
}
}
#endif
@@ -29,59 +29,60 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq.ComponentModel
{
[TestFixture]
public class JPropertyDescriptorTests : TestFixtureBase
{
[Test]
public void GetValue()
[TestFixture]
public class JPropertyDescriptorTests : TestFixtureBase
{
JObject o = JObject.Parse("{prop1:'12345!',prop2:[1,'two','III']}");
[Test]
public void GetValue()
{
JObject o = JObject.Parse("{prop1:'12345!',prop2:[1,'two','III']}");
JPropertyDescriptor prop1 = new JPropertyDescriptor("prop1", typeof(string));
JPropertyDescriptor prop2 = new JPropertyDescriptor("prop2", typeof(JArray));
JPropertyDescriptor prop1 = new JPropertyDescriptor("prop1", typeof(string));
JPropertyDescriptor prop2 = new JPropertyDescriptor("prop2", typeof(JArray));
Assert.AreEqual("12345!", ((JValue) prop1.GetValue(o)).Value);
Assert.AreEqual(o["prop2"], prop2.GetValue(o));
Assert.AreEqual("12345!", ((JValue)prop1.GetValue(o)).Value);
Assert.AreEqual(o["prop2"], prop2.GetValue(o));
}
[Test]
public void SetValue()
{
JObject o = JObject.Parse("{prop1:'12345!'}");
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
propertyDescriptor1.SetValue(o, "54321!");
Assert.AreEqual("54321!", (string)o["prop1"]);
}
[Test]
public void ResetValue()
{
JObject o = JObject.Parse("{prop1:'12345!'}");
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
propertyDescriptor1.ResetValue(o);
Assert.AreEqual("12345!", (string)o["prop1"]);
}
[Test]
public void IsReadOnly()
{
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
Assert.AreEqual(false, propertyDescriptor1.IsReadOnly);
}
[Test]
public void PropertyType()
{
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
Assert.AreEqual(typeof(string), propertyDescriptor1.PropertyType);
}
}
[Test]
public void SetValue()
{
JObject o = JObject.Parse("{prop1:'12345!'}");
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
propertyDescriptor1.SetValue(o, "54321!");
Assert.AreEqual("54321!", (string)o["prop1"]);
}
[Test]
public void ResetValue()
{
JObject o = JObject.Parse("{prop1:'12345!'}");
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
propertyDescriptor1.ResetValue(o);
Assert.AreEqual("12345!", (string)o["prop1"]);
}
[Test]
public void IsReadOnly()
{
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
Assert.AreEqual(false, propertyDescriptor1.IsReadOnly);
}
[Test]
public void PropertyType()
{
JPropertyDescriptor propertyDescriptor1 = new JPropertyDescriptor("prop1", typeof(string));
Assert.AreEqual(typeof(string), propertyDescriptor1.PropertyType);
}
}
}
#endif
File diff suppressed because it is too large Load Diff
+424 -457
View File
@@ -38,410 +38,383 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JArrayTests : TestFixtureBase
{
[Test]
public void RemoveSpecificAndRemoveSelf()
[TestFixture]
public class JArrayTests : TestFixtureBase
{
JObject o = new JObject
{
{"results", new JArray(1, 2, 3, 4)}
};
[Test]
public void RemoveSpecificAndRemoveSelf()
{
JObject o = new JObject
{
{ "results", new JArray(1, 2, 3, 4) }
};
JArray a = (JArray)o["results"];
JArray a = (JArray)o["results"];
var last = a.Last();
var last = a.Last();
Assert.IsTrue(a.Remove(last));
Assert.IsTrue(a.Remove(last));
last = a.Last();
last.Remove();
last = a.Last();
last.Remove();
Assert.AreEqual(2, a.Count);
}
Assert.AreEqual(2, a.Count);
}
[Test]
public void Clear()
{
JArray a = new JArray {1};
Assert.AreEqual(1, a.Count);
[Test]
public void Clear()
{
JArray a = new JArray { 1 };
Assert.AreEqual(1, a.Count);
a.Clear();
Assert.AreEqual(0, a.Count);
}
a.Clear();
Assert.AreEqual(0, a.Count);
}
[Test]
public void AddToSelf()
{
JArray a = new JArray();
a.Add(a);
[Test]
public void AddToSelf()
{
JArray a = new JArray();
a.Add(a);
Assert.IsFalse(ReferenceEquals(a[0], a));
}
Assert.IsFalse(ReferenceEquals(a[0], a));
}
[Test]
public void Contains()
{
JValue v = new JValue(1);
[Test]
public void Contains()
{
JValue v = new JValue(1);
JArray a = new JArray {v};
JArray a = new JArray { v };
Assert.AreEqual(false, a.Contains(new JValue(2)));
Assert.AreEqual(false, a.Contains(new JValue(1)));
Assert.AreEqual(false, a.Contains(null));
Assert.AreEqual(true, a.Contains(v));
}
Assert.AreEqual(false, a.Contains(new JValue(2)));
Assert.AreEqual(false, a.Contains(new JValue(1)));
Assert.AreEqual(false, a.Contains(null));
Assert.AreEqual(true, a.Contains(v));
}
[Test]
public void GenericCollectionCopyTo()
{
JArray j = new JArray();
j.Add(new JValue(1));
j.Add(new JValue(2));
j.Add(new JValue(3));
Assert.AreEqual(3, j.Count);
[Test]
public void GenericCollectionCopyTo()
{
JArray j = new JArray();
j.Add(new JValue(1));
j.Add(new JValue(2));
j.Add(new JValue(3));
Assert.AreEqual(3, j.Count);
JToken[] a = new JToken[5];
JToken[] a = new JToken[5];
((ICollection<JToken>) j).CopyTo(a, 1);
((ICollection<JToken>)j).CopyTo(a, 1);
Assert.AreEqual(null, a[0]);
Assert.AreEqual(null, a[0]);
Assert.AreEqual(1, (int) a[1]);
Assert.AreEqual(1, (int)a[1]);
Assert.AreEqual(2, (int) a[2]);
Assert.AreEqual(2, (int)a[2]);
Assert.AreEqual(3, (int) a[3]);
Assert.AreEqual(3, (int)a[3]);
Assert.AreEqual(null, a[4]);
Assert.AreEqual(null, a[4]);
}
}
[Test]
public void GenericCollectionCopyToNullArrayShouldThrow()
{
JArray j = new JArray();
[Test]
public void GenericCollectionCopyToNullArrayShouldThrow()
{
JArray j = new JArray();
ExceptionAssert.Throws<ArgumentNullException>(
@"Value cannot be null.
ExceptionAssert.Throws<ArgumentNullException>(
@"Value cannot be null.
Parameter name: array",
() =>
{
((ICollection<JToken>) j).CopyTo(null, 0);
});
}
() => { ((ICollection<JToken>)j).CopyTo(null, 0); });
}
[Test]
public void GenericCollectionCopyToNegativeArrayIndexShouldThrow()
{
JArray j = new JArray();
[Test]
public void GenericCollectionCopyToNegativeArrayIndexShouldThrow()
{
JArray j = new JArray();
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"arrayIndex is less than 0.
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"arrayIndex is less than 0.
Parameter name: arrayIndex",
() =>
{
((ICollection<JToken>) j).CopyTo(new JToken[1], -1);
});
}
() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], -1); });
}
[Test]
public void GenericCollectionCopyToArrayIndexEqualGreaterToArrayLengthShouldThrow()
{
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);
});
}
[Test]
public void GenericCollectionCopyToInsufficientArrayCapacity()
{
JArray j = new JArray();
j.Add(new JValue(1));
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.",
() =>
[Test]
public void GenericCollectionCopyToArrayIndexEqualGreaterToArrayLengthShouldThrow()
{
((ICollection<JToken>)j).CopyTo(new JToken[3], 1);
});
}
JArray j = new JArray();
[Test]
public void Remove()
{
JValue v = new JValue(1);
JArray j = new JArray();
j.Add(v);
ExceptionAssert.Throws<ArgumentException>(
@"arrayIndex is equal to or greater than the length of array.",
() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], 1); });
}
Assert.AreEqual(1, j.Count);
[Test]
public void GenericCollectionCopyToInsufficientArrayCapacity()
{
JArray j = new JArray();
j.Add(new JValue(1));
j.Add(new JValue(2));
j.Add(new JValue(3));
Assert.AreEqual(false, j.Remove(new JValue(1)));
Assert.AreEqual(false, j.Remove(null));
Assert.AreEqual(true, j.Remove(v));
Assert.AreEqual(false, j.Remove(v));
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); });
}
Assert.AreEqual(0, j.Count);
}
[Test]
public void Remove()
{
JValue v = new JValue(1);
JArray j = new JArray();
j.Add(v);
[Test]
public void IndexOf()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(1);
JValue v3 = new JValue(1);
Assert.AreEqual(1, j.Count);
JArray j = new JArray();
Assert.AreEqual(false, j.Remove(new JValue(1)));
Assert.AreEqual(false, j.Remove(null));
Assert.AreEqual(true, j.Remove(v));
Assert.AreEqual(false, j.Remove(v));
j.Add(v1);
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(0, j.Count);
}
j.Add(v2);
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v2));
[Test]
public void IndexOf()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(1);
JValue v3 = new JValue(1);
j.AddFirst(v3);
Assert.AreEqual(1, j.IndexOf(v1));
Assert.AreEqual(2, j.IndexOf(v2));
Assert.AreEqual(0, j.IndexOf(v3));
JArray j = new JArray();
v3.Remove();
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v2));
Assert.AreEqual(-1, j.IndexOf(v3));
}
j.Add(v1);
Assert.AreEqual(0, j.IndexOf(v1));
[Test]
public void RemoveAt()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(1);
JValue v3 = new JValue(1);
j.Add(v2);
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v2));
JArray j = new JArray();
j.AddFirst(v3);
Assert.AreEqual(1, j.IndexOf(v1));
Assert.AreEqual(2, j.IndexOf(v2));
Assert.AreEqual(0, j.IndexOf(v3));
j.Add(v1);
j.Add(v2);
j.Add(v3);
v3.Remove();
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v2));
Assert.AreEqual(-1, j.IndexOf(v3));
}
Assert.AreEqual(true, j.Contains(v1));
j.RemoveAt(0);
Assert.AreEqual(false, j.Contains(v1));
[Test]
public void RemoveAt()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(1);
JValue v3 = new JValue(1);
Assert.AreEqual(true, j.Contains(v3));
j.RemoveAt(1);
Assert.AreEqual(false, j.Contains(v3));
JArray j = new JArray();
Assert.AreEqual(1, j.Count);
}
j.Add(v1);
j.Add(v2);
j.Add(v3);
[Test]
public void RemoveAtOutOfRangeIndexShouldError()
{
JArray j = new JArray();
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"Index is equal to or greater than Count.
Parameter name: index",
() =>
{
Assert.AreEqual(true, j.Contains(v1));
j.RemoveAt(0);
});
}
Assert.AreEqual(false, j.Contains(v1));
[Test]
public void RemoveAtNegativeIndexShouldError()
{
JArray j = new JArray();
Assert.AreEqual(true, j.Contains(v3));
j.RemoveAt(1);
Assert.AreEqual(false, j.Contains(v3));
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"Index is less than 0.
Parameter name: index",
() =>
{
j.RemoveAt(-1);
});
}
Assert.AreEqual(1, j.Count);
}
[Test]
public void Insert()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JValue v4 = new JValue(4);
JArray j = new JArray();
j.Add(v1);
j.Add(v2);
j.Add(v3);
j.Insert(1, v4);
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v4));
Assert.AreEqual(2, j.IndexOf(v2));
Assert.AreEqual(3, j.IndexOf(v3));
}
[Test]
public void AddFirstAddedTokenShouldBeFirst()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JArray j = new JArray();
Assert.AreEqual(null, j.First);
Assert.AreEqual(null, j.Last);
j.AddFirst(v1);
Assert.AreEqual(v1, j.First);
Assert.AreEqual(v1, j.Last);
j.AddFirst(v2);
Assert.AreEqual(v2, j.First);
Assert.AreEqual(v1, j.Last);
j.AddFirst(v3);
Assert.AreEqual(v3, j.First);
Assert.AreEqual(v1, j.Last);
}
[Test]
public void InsertShouldInsertAtZeroIndex()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JArray j = new JArray();
j.Insert(0, v1);
Assert.AreEqual(0, j.IndexOf(v1));
j.Insert(0, v2);
Assert.AreEqual(1, j.IndexOf(v1));
Assert.AreEqual(0, j.IndexOf(v2));
}
[Test]
public void InsertNull()
{
JArray j = new JArray();
j.Insert(0, null);
Assert.AreEqual(null, ((JValue) j[0]).Value);
}
[Test]
public void InsertNegativeIndexShouldThrow()
{
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",
() =>
[Test]
public void RemoveAtOutOfRangeIndexShouldError()
{
j.Insert(-1, new JValue(1));
});
}
JArray j = new JArray();
[Test]
public void InsertOutOfRangeIndexShouldThrow()
{
JArray j = new JArray();
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"Index must be within the bounds of the List.
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"Index is equal to or greater than Count.
Parameter name: index",
() =>
{
j.Insert(2, new JValue(1));
});
}
() => { j.RemoveAt(0); });
}
[Test]
public void Item()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JValue v4 = new JValue(4);
JArray j = new JArray();
j.Add(v1);
j.Add(v2);
j.Add(v3);
j[1] = v4;
Assert.AreEqual(null, v2.Parent);
Assert.AreEqual(-1, j.IndexOf(v2));
Assert.AreEqual(j, v4.Parent);
Assert.AreEqual(1, j.IndexOf(v4));
}
[Test]
public void Parse_ShouldThrowOnUnexpectedToken()
{
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);
});
}
public class ListItemFields
{
public string ListItemText { get; set; }
public object ListItemValue { get; set; }
}
[Test]
public void ArrayOrder()
{
string itemZeroText = "Zero text";
IEnumerable<ListItemFields> t = new List<ListItemFields>
[Test]
public void RemoveAtNegativeIndexShouldError()
{
new ListItemFields {ListItemText = "First", ListItemValue = 1},
new ListItemFields {ListItemText = "Second", ListItemValue = 2},
new ListItemFields {ListItemText = "Third", ListItemValue = 3}
};
JArray j = new JArray();
JObject optionValues =
new JObject(
new JProperty("options",
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
@"Index is less than 0.
Parameter name: index",
() => { j.RemoveAt(-1); });
}
[Test]
public void Insert()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JValue v4 = new JValue(4);
JArray j = new JArray();
j.Add(v1);
j.Add(v2);
j.Add(v3);
j.Insert(1, v4);
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v4));
Assert.AreEqual(2, j.IndexOf(v2));
Assert.AreEqual(3, j.IndexOf(v3));
}
[Test]
public void AddFirstAddedTokenShouldBeFirst()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JArray j = new JArray();
Assert.AreEqual(null, j.First);
Assert.AreEqual(null, j.Last);
j.AddFirst(v1);
Assert.AreEqual(v1, j.First);
Assert.AreEqual(v1, j.Last);
j.AddFirst(v2);
Assert.AreEqual(v2, j.First);
Assert.AreEqual(v1, j.Last);
j.AddFirst(v3);
Assert.AreEqual(v3, j.First);
Assert.AreEqual(v1, j.Last);
}
[Test]
public void InsertShouldInsertAtZeroIndex()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JArray j = new JArray();
j.Insert(0, v1);
Assert.AreEqual(0, j.IndexOf(v1));
j.Insert(0, v2);
Assert.AreEqual(1, j.IndexOf(v1));
Assert.AreEqual(0, j.IndexOf(v2));
}
[Test]
public void InsertNull()
{
JArray j = new JArray();
j.Insert(0, null);
Assert.AreEqual(null, ((JValue)j[0]).Value);
}
[Test]
public void InsertNegativeIndexShouldThrow()
{
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)); });
}
[Test]
public void InsertOutOfRangeIndexShouldThrow()
{
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)); });
}
[Test]
public void Item()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JValue v4 = new JValue(4);
JArray j = new JArray();
j.Add(v1);
j.Add(v2);
j.Add(v3);
j[1] = v4;
Assert.AreEqual(null, v2.Parent);
Assert.AreEqual(-1, j.IndexOf(v2));
Assert.AreEqual(j, v4.Parent);
Assert.AreEqual(1, j.IndexOf(v4));
}
[Test]
public void Parse_ShouldThrowOnUnexpectedToken()
{
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); });
}
public class ListItemFields
{
public string ListItemText { get; set; }
public object ListItemValue { get; set; }
}
[Test]
public void ArrayOrder()
{
string itemZeroText = "Zero text";
IEnumerable<ListItemFields> t = new List<ListItemFields>
{
new ListItemFields { ListItemText = "First", ListItemValue = 1 },
new ListItemFields { ListItemText = "Second", ListItemValue = 2 },
new ListItemFields { ListItemText = "Third", ListItemValue = 3 }
};
JObject optionValues =
new JObject(
new JProperty("options",
new JArray(
new JObject(
new JProperty("text", itemZeroText),
new JProperty("value", "0")),
from r in t
orderby r.ListItemValue
select new JObject(
new JProperty("text", r.ListItemText),
new JProperty("value", r.ListItemValue.ToString())))));
new JObject(
new JProperty("text", itemZeroText),
new JProperty("value", "0")),
from r in t
orderby r.ListItemValue
select new JObject(
new JProperty("text", r.ListItemText),
new JProperty("value", r.ListItemValue.ToString())))));
string result = "myOptions = " + optionValues.ToString();
string result = "myOptions = " + optionValues.ToString();
Assert.AreEqual(@"myOptions = {
Assert.AreEqual(@"myOptions = {
""options"": [
{
""text"": ""Zero text"",
@@ -461,141 +434,135 @@ Parameter name: index",
}
]
}", result);
}
}
[Test]
public void Iterate()
{
JArray a = new JArray(1, 2, 3, 4, 5);
[Test]
public void Iterate()
{
JArray a = new JArray(1, 2, 3, 4, 5);
int i = 1;
foreach (JToken token in a)
{
Assert.AreEqual(i, (int) token);
i++;
}
}
int i = 1;
foreach (JToken token in a)
{
Assert.AreEqual(i, (int)token);
i++;
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void ITypedListGetItemProperties()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
ITypedList a = new JArray(new JObject(p1, p2));
[Test]
public void ITypedListGetItemProperties()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
ITypedList a = new JArray(new JObject(p1, p2));
PropertyDescriptorCollection propertyDescriptors = a.GetItemProperties(null);
Assert.IsNotNull(propertyDescriptors);
Assert.AreEqual(2, propertyDescriptors.Count);
Assert.AreEqual("Test1", propertyDescriptors[0].Name);
Assert.AreEqual("Test2", propertyDescriptors[1].Name);
}
PropertyDescriptorCollection propertyDescriptors = a.GetItemProperties(null);
Assert.IsNotNull(propertyDescriptors);
Assert.AreEqual(2, propertyDescriptors.Count);
Assert.AreEqual("Test1", propertyDescriptors[0].Name);
Assert.AreEqual("Test2", propertyDescriptors[1].Name);
}
#endif
[Test]
public void AddArrayToSelf()
{
JArray a = new JArray(1, 2);
a.Add(a);
Assert.AreEqual(3, a.Count);
Assert.AreEqual(1, (int) a[0]);
Assert.AreEqual(2, (int) a[1]);
Assert.AreNotSame(a, a[2]);
}
[Test]
public void SetValueWithInvalidIndex()
{
ExceptionAssert.Throws<ArgumentException>(
@"Set JArray values with invalid key value: ""badvalue"". Array position index expected.",
() =>
[Test]
public void AddArrayToSelf()
{
JArray a = new JArray();
a["badvalue"] = new JValue(3);
});
}
JArray a = new JArray(1, 2);
a.Add(a);
[Test]
public void SetValue()
{
object key = 0;
Assert.AreEqual(3, a.Count);
Assert.AreEqual(1, (int)a[0]);
Assert.AreEqual(2, (int)a[1]);
Assert.AreNotSame(a, a[2]);
}
JArray a = new JArray((object) null);
a[key] = new JValue(3);
Assert.AreEqual(3, (int) a[key]);
}
[Test]
public void ReplaceAll()
{
JArray a = new JArray(new[] {1, 2, 3});
Assert.AreEqual(3, a.Count);
Assert.AreEqual(1, (int) a[0]);
Assert.AreEqual(2, (int) a[1]);
Assert.AreEqual(3, (int) a[2]);
a.ReplaceAll(1);
Assert.AreEqual(1, a.Count);
Assert.AreEqual(1, (int) a[0]);
}
[Test]
public void ParseIncomplete()
{
ExceptionAssert.Throws<JsonReaderException>(
"Unexpected end of content while loading JArray. Path '[0]', line 1, position 2.",
() =>
[Test]
public void SetValueWithInvalidIndex()
{
JArray.Parse("[1");
});
}
ExceptionAssert.Throws<ArgumentException>(
@"Set JArray values with invalid key value: ""badvalue"". Array position index expected.",
() =>
{
JArray a = new JArray();
a["badvalue"] = new JValue(3);
});
}
[Test]
public void InsertAddEnd()
{
JArray array = new JArray();
array.Insert(0, 123);
array.Insert(1, 456);
[Test]
public void SetValue()
{
object key = 0;
Assert.AreEqual(2, array.Count);
Assert.AreEqual(123, (int) array[0]);
Assert.AreEqual(456, (int) array[1]);
}
JArray a = new JArray((object)null);
a[key] = new JValue(3);
[Test]
public void ParseAdditionalContent()
{
string json = @"[
Assert.AreEqual(3, (int)a[key]);
}
[Test]
public void ReplaceAll()
{
JArray a = new JArray(new[] { 1, 2, 3 });
Assert.AreEqual(3, a.Count);
Assert.AreEqual(1, (int)a[0]);
Assert.AreEqual(2, (int)a[1]);
Assert.AreEqual(3, (int)a[2]);
a.ReplaceAll(1);
Assert.AreEqual(1, a.Count);
Assert.AreEqual(1, (int)a[0]);
}
[Test]
public void ParseIncomplete()
{
ExceptionAssert.Throws<JsonReaderException>(
"Unexpected end of content while loading JArray. Path '[0]', line 1, position 2.",
() => { JArray.Parse("[1"); });
}
[Test]
public void InsertAddEnd()
{
JArray array = new JArray();
array.Insert(0, 123);
array.Insert(1, 456);
Assert.AreEqual(2, array.Count);
Assert.AreEqual(123, (int)array[0]);
Assert.AreEqual(456, (int)array[1]);
}
[Test]
public void ParseAdditionalContent()
{
string json = @"[
""Small"",
""Medium"",
""Large""
], 987987";
ExceptionAssert.Throws<JsonReaderException>(
"Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.",
() =>
{
JArray.Parse(json);
});
ExceptionAssert.Throws<JsonReaderException>(
"Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.",
() => { JArray.Parse(json); });
}
[Test]
public void ToListOnEmptyArray()
{
string json = @"{""decks"":[]}";
JArray decks = (JArray)JObject.Parse(json)["decks"];
IList<JToken> l = decks.ToList();
Assert.AreEqual(0, l.Count);
json = @"{""decks"":[1]}";
decks = (JArray)JObject.Parse(json)["decks"];
l = decks.ToList();
Assert.AreEqual(1, l.Count);
}
}
[Test]
public void ToListOnEmptyArray()
{
string json = @"{""decks"":[]}";
JArray decks = (JArray)JObject.Parse(json)["decks"];
IList<JToken> l = decks.ToList();
Assert.AreEqual(0, l.Count);
json = @"{""decks"":[1]}";
decks = (JArray)JObject.Parse(json)["decks"];
l = decks.ToList();
Assert.AreEqual(1, l.Count);
}
}
}
@@ -38,70 +38,71 @@ using System.IO;
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JConstructorTests : TestFixtureBase
{
[Test]
public void Load()
[TestFixture]
public class JConstructorTests : TestFixtureBase
{
JsonReader reader = new JsonTextReader(new StringReader("new Date(123)"));
reader.Read();
[Test]
public void Load()
{
JsonReader reader = new JsonTextReader(new StringReader("new Date(123)"));
reader.Read();
JConstructor constructor = JConstructor.Load(reader);
Assert.AreEqual("Date", constructor.Name);
Assert.IsTrue(JToken.DeepEquals(new JValue(123), constructor.Values().ElementAt(0)));
JConstructor constructor = JConstructor.Load(reader);
Assert.AreEqual("Date", constructor.Name);
Assert.IsTrue(JToken.DeepEquals(new JValue(123), constructor.Values().ElementAt(0)));
}
[Test]
public void CreateWithMultiValue()
{
JConstructor constructor = new JConstructor("Test", new List<int> { 1, 2, 3 });
Assert.AreEqual("Test", constructor.Name);
Assert.AreEqual(3, constructor.Children().Count());
Assert.AreEqual(1, (int)constructor.Children().ElementAt(0));
Assert.AreEqual(2, (int)constructor.Children().ElementAt(1));
Assert.AreEqual(3, (int)constructor.Children().ElementAt(2));
}
[Test]
public void Iterate()
{
JConstructor c = new JConstructor("MrConstructor", 1, 2, 3, 4, 5);
int i = 1;
foreach (JToken token in c)
{
Assert.AreEqual(i, (int)token);
i++;
}
}
[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);
});
}
[Test]
public void SetValue()
{
object key = 0;
JConstructor c = new JConstructor();
c.Name = "con";
c.Add(null);
c[key] = new JValue(3);
Assert.AreEqual(3, (int)c[key]);
}
}
[Test]
public void CreateWithMultiValue()
{
JConstructor constructor = new JConstructor("Test", new List<int> { 1, 2, 3 });
Assert.AreEqual("Test", constructor.Name);
Assert.AreEqual(3, constructor.Children().Count());
Assert.AreEqual(1, (int)constructor.Children().ElementAt(0));
Assert.AreEqual(2, (int)constructor.Children().ElementAt(1));
Assert.AreEqual(3, (int)constructor.Children().ElementAt(2));
}
[Test]
public void Iterate()
{
JConstructor c = new JConstructor("MrConstructor", 1, 2, 3, 4, 5);
int i = 1;
foreach (JToken token in c)
{
Assert.AreEqual(i, (int)token);
i++;
}
}
[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);
});
}
[Test]
public void SetValue()
{
object key = 0;
JConstructor c = new JConstructor();
c.Name = "con";
c.Add(null);
c[key] = new JValue(3);
Assert.AreEqual(3, (int)c[key]);
}
}
}
}
File diff suppressed because it is too large Load Diff
+260 -289
View File
@@ -37,295 +37,266 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JPathTests : TestFixtureBase
{
[Test]
public void SingleProperty()
[TestFixture]
public class JPathTests : TestFixtureBase
{
JPath path = new JPath("Blah");
Assert.AreEqual(1, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
}
[Test]
public void TwoProperties()
{
JPath path = new JPath("Blah.Two");
Assert.AreEqual(2, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual("Two", path.Parts[1]);
}
[Test]
public void SinglePropertyAndIndexer()
{
JPath path = new JPath("Blah[0]");
Assert.AreEqual(2, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
}
[Test]
public void MultiplePropertiesAndIndexers()
{
JPath path = new JPath("Blah[0].Two.Three[1].Four");
Assert.AreEqual(6, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
Assert.AreEqual("Two", path.Parts[2]);
Assert.AreEqual("Three", path.Parts[3]);
Assert.AreEqual(1, path.Parts[4]);
Assert.AreEqual("Four", path.Parts[5]);
}
[Test]
public void BadCharactersInIndexer()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path indexer: [",
() =>
[Test]
public void SingleProperty()
{
new JPath("Blah[[0]].Two.Three[1].Four");
});
}
JPath path = new JPath("Blah");
Assert.AreEqual(1, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
}
[Test]
public void UnclosedIndexer()
{
ExceptionAssert.Throws<JsonException>(
@"Path ended with open indexer. Expected ]",
() =>
[Test]
public void TwoProperties()
{
new JPath("Blah[0");
});
}
JPath path = new JPath("Blah.Two");
Assert.AreEqual(2, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual("Two", path.Parts[1]);
}
[Test]
public void AdditionalDots()
{
JPath path = new JPath(".Blah..[0]..Two.Three....[1].Four.");
Assert.AreEqual(6, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
Assert.AreEqual("Two", path.Parts[2]);
Assert.AreEqual("Three", path.Parts[3]);
Assert.AreEqual(1, path.Parts[4]);
Assert.AreEqual("Four", path.Parts[5]);
}
[Test]
public void IndexerOnly()
{
JPath path = new JPath("[111119990]");
Assert.AreEqual(1, path.Parts.Count);
Assert.AreEqual(111119990, path.Parts[0]);
}
[Test]
public void EmptyIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Empty path indexer.",
() =>
[Test]
public void SinglePropertyAndIndexer()
{
new JPath("[]");
});
}
JPath path = new JPath("Blah[0]");
Assert.AreEqual(2, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
}
[Test]
public void IndexerCloseInProperty()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character while parsing path: ]",
() =>
[Test]
public void MultiplePropertiesAndIndexers()
{
new JPath("]");
});
}
JPath path = new JPath("Blah[0].Two.Three[1].Four");
Assert.AreEqual(6, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
Assert.AreEqual("Two", path.Parts[2]);
Assert.AreEqual("Three", path.Parts[3]);
Assert.AreEqual(1, path.Parts[4]);
Assert.AreEqual("Four", path.Parts[5]);
}
[Test]
public void AdjacentIndexers()
{
JPath path = new JPath("[1][0][0][" + int.MaxValue + "]");
Assert.AreEqual(4, path.Parts.Count);
Assert.AreEqual(1, path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
Assert.AreEqual(0, path.Parts[2]);
Assert.AreEqual(int.MaxValue, path.Parts[3]);
}
[Test]
public void MissingDotAfterIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character following indexer: B",
() =>
[Test]
public void BadCharactersInIndexer()
{
new JPath("[1]Blah");
});
}
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path indexer: [",
() => { new JPath("Blah[[0]].Two.Three[1].Four"); });
}
[Test]
public void EvaluateSingleProperty()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken("Blah");
Assert.IsNotNull(t);
Assert.AreEqual(JTokenType.Integer, t.Type);
Assert.AreEqual(1, (int)t);
}
[Test]
public void EvaluateMissingProperty()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken("Missing[1]");
Assert.IsNull(t);
}
[Test]
public void EvaluateIndexerOnObject()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken("[1]");
Assert.IsNull(t);
}
[Test]
public void EvaluateIndexerOnObjectWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
@"Index 1 not valid on JObject.",
() =>
[Test]
public void UnclosedIndexer()
{
o.SelectToken("[1]", true);
});
}
ExceptionAssert.Throws<JsonException>(
@"Path ended with open indexer. Expected ]",
() => { new JPath("Blah[0"); });
}
[Test]
public void EvaluatePropertyOnArray()
{
JArray a = new JArray(1, 2, 3, 4, 5);
JToken t = a.SelectToken("BlahBlah");
Assert.IsNull(t);
}
[Test]
public void EvaluatePropertyOnArrayWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
@"Property 'BlahBlah' not valid on JArray.",
() =>
[Test]
public void AdditionalDots()
{
a.SelectToken("BlahBlah", true);
});
}
JPath path = new JPath(".Blah..[0]..Two.Three....[1].Four.");
Assert.AreEqual(6, path.Parts.Count);
Assert.AreEqual("Blah", path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
Assert.AreEqual("Two", path.Parts[2]);
Assert.AreEqual("Three", path.Parts[3]);
Assert.AreEqual(1, path.Parts[4]);
Assert.AreEqual("Four", path.Parts[5]);
}
[Test]
public void EvaluateConstructorOutOfBoundsIndxerWithError()
{
JConstructor c = new JConstructor("Blah");
ExceptionAssert.Throws<JsonException>(
@"Index 1 outside the bounds of JConstructor.",
() =>
[Test]
public void IndexerOnly()
{
c.SelectToken("[1]", true);
});
}
JPath path = new JPath("[111119990]");
Assert.AreEqual(1, path.Parts.Count);
Assert.AreEqual(111119990, path.Parts[0]);
}
[Test]
public void EvaluateMissingPropertyWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
"Property 'Missing' does not exist on JObject.",
() =>
[Test]
public void EmptyIndexer()
{
o.SelectToken("Missing", true);
});
}
ExceptionAssert.Throws<JsonException>(
"Empty path indexer.",
() => { new JPath("[]"); });
}
[Test]
public void EvaluateOutOfBoundsIndxer()
{
JArray a = new JArray(1, 2, 3, 4, 5);
JToken t = a.SelectToken("[1000].Ha");
Assert.IsNull(t);
}
[Test]
public void EvaluateArrayOutOfBoundsIndxerWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
"Index 1000 outside the bounds of JArray.",
() =>
[Test]
public void IndexerCloseInProperty()
{
a.SelectToken("[1000].Ha", true);
});
}
ExceptionAssert.Throws<JsonException>(
"Unexpected character while parsing path: ]",
() => { new JPath("]"); });
}
[Test]
public void EvaluateArray()
{
JArray a = new JArray(1, 2, 3, 4);
[Test]
public void AdjacentIndexers()
{
JPath path = new JPath("[1][0][0][" + int.MaxValue + "]");
Assert.AreEqual(4, path.Parts.Count);
Assert.AreEqual(1, path.Parts[0]);
Assert.AreEqual(0, path.Parts[1]);
Assert.AreEqual(0, path.Parts[2]);
Assert.AreEqual(int.MaxValue, path.Parts[3]);
}
JToken t = a.SelectToken("[1]");
Assert.IsNotNull(t);
Assert.AreEqual(JTokenType.Integer, t.Type);
Assert.AreEqual(2, (int)t);
}
[Test]
public void MissingDotAfterIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character following indexer: B",
() => { new JPath("[1]Blah"); });
}
[Test]
public void EvaluateSinglePropertyReturningArray()
{
JObject o = new JObject(
new JProperty("Blah", new [] { 1, 2, 3 }));
[Test]
public void EvaluateSingleProperty()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken("Blah");
Assert.IsNotNull(t);
Assert.AreEqual(JTokenType.Array, t.Type);
JToken t = o.SelectToken("Blah");
Assert.IsNotNull(t);
Assert.AreEqual(JTokenType.Integer, t.Type);
Assert.AreEqual(1, (int)t);
}
t = o.SelectToken("Blah[2]");
Assert.AreEqual(JTokenType.Integer, t.Type);
Assert.AreEqual(3, (int)t);
}
[Test]
public void EvaluateMissingProperty()
{
JObject o = new JObject(
new JProperty("Blah", 1));
[Test]
public void EvaluateLastSingleCharacterProperty()
{
JObject o2 = JObject.Parse("{'People':[{'N':'Jeff'}]}");
string a2 = (string)o2.SelectToken("People[0].N");
JToken t = o.SelectToken("Missing[1]");
Assert.IsNull(t);
}
Assert.AreEqual("Jeff", a2);
}
[Test]
public void EvaluateIndexerOnObject()
{
JObject o = new JObject(
new JProperty("Blah", 1));
[Test]
public void PathWithConstructor()
{
JArray a = JArray.Parse(@"[
JToken t = o.SelectToken("[1]");
Assert.IsNull(t);
}
[Test]
public void EvaluateIndexerOnObjectWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
@"Index 1 not valid on JObject.",
() => { o.SelectToken("[1]", true); });
}
[Test]
public void EvaluatePropertyOnArray()
{
JArray a = new JArray(1, 2, 3, 4, 5);
JToken t = a.SelectToken("BlahBlah");
Assert.IsNull(t);
}
[Test]
public void EvaluatePropertyOnArrayWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
@"Property 'BlahBlah' not valid on JArray.",
() => { a.SelectToken("BlahBlah", true); });
}
[Test]
public void EvaluateConstructorOutOfBoundsIndxerWithError()
{
JConstructor c = new JConstructor("Blah");
ExceptionAssert.Throws<JsonException>(
@"Index 1 outside the bounds of JConstructor.",
() => { c.SelectToken("[1]", true); });
}
[Test]
public void EvaluateMissingPropertyWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
ExceptionAssert.Throws<JsonException>(
"Property 'Missing' does not exist on JObject.",
() => { o.SelectToken("Missing", true); });
}
[Test]
public void EvaluateOutOfBoundsIndxer()
{
JArray a = new JArray(1, 2, 3, 4, 5);
JToken t = a.SelectToken("[1000].Ha");
Assert.IsNull(t);
}
[Test]
public void EvaluateArrayOutOfBoundsIndxerWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<JsonException>(
"Index 1000 outside the bounds of JArray.",
() => { a.SelectToken("[1000].Ha", true); });
}
[Test]
public void EvaluateArray()
{
JArray a = new JArray(1, 2, 3, 4);
JToken t = a.SelectToken("[1]");
Assert.IsNotNull(t);
Assert.AreEqual(JTokenType.Integer, t.Type);
Assert.AreEqual(2, (int)t);
}
[Test]
public void EvaluateSinglePropertyReturningArray()
{
JObject o = new JObject(
new JProperty("Blah", new[] { 1, 2, 3 }));
JToken t = o.SelectToken("Blah");
Assert.IsNotNull(t);
Assert.AreEqual(JTokenType.Array, t.Type);
t = o.SelectToken("Blah[2]");
Assert.AreEqual(JTokenType.Integer, t.Type);
Assert.AreEqual(3, (int)t);
}
[Test]
public void EvaluateLastSingleCharacterProperty()
{
JObject o2 = JObject.Parse("{'People':[{'N':'Jeff'}]}");
string a2 = (string)o2.SelectToken("People[0].N");
Assert.AreEqual("Jeff", a2);
}
[Test]
public void PathWithConstructor()
{
JArray a = JArray.Parse(@"[
{
""Property1"": [
1,
@@ -346,15 +317,15 @@ namespace Newtonsoft.Json.Tests.Linq
}
]");
JValue v = (JValue)a.SelectToken("[1].Property2[1][0]");
Assert.AreEqual(1L, v.Value);
}
JValue v = (JValue)a.SelectToken("[1].Property2[1][0]");
Assert.AreEqual(1L, v.Value);
}
[Test]
public void Example()
{
JObject o = JObject.Parse(@"{
[Test]
public void Example()
{
JObject o = JObject.Parse(@"{
""Stores"": [
""Lambton Quay"",
""Willis Street""
@@ -385,37 +356,37 @@ namespace Newtonsoft.Json.Tests.Linq
]
}");
string name = (string)o.SelectToken("Manufacturers[0].Name");
// Acme Co
string name = (string)o.SelectToken("Manufacturers[0].Name");
// Acme Co
decimal productPrice = (decimal)o.SelectToken("Manufacturers[0].Products[0].Price");
// 50
decimal productPrice = (decimal)o.SelectToken("Manufacturers[0].Products[0].Price");
// 50
string productName = (string)o.SelectToken("Manufacturers[1].Products[0].Name");
// Elbow Grease
string productName = (string)o.SelectToken("Manufacturers[1].Products[0].Name");
// Elbow Grease
Assert.AreEqual("Acme Co", name);
Assert.AreEqual(50m, productPrice);
Assert.AreEqual("Elbow Grease", productName);
Assert.AreEqual("Acme Co", name);
Assert.AreEqual(50m, productPrice);
Assert.AreEqual("Elbow Grease", productName);
IList<string> storeNames = o.SelectToken("Stores").Select(s => (string)s).ToList();
// Lambton Quay
// Willis Street
IList<string> storeNames = o.SelectToken("Stores").Select(s => (string)s).ToList();
// Lambton Quay
// Willis Street
IList<string> firstProductNames = o["Manufacturers"].Select(m => (string)m.SelectToken("Products[1].Name")).ToList();
// null
// Headlight Fluid
IList<string> firstProductNames = o["Manufacturers"].Select(m => (string)m.SelectToken("Products[1].Name")).ToList();
// null
// Headlight Fluid
decimal totalPrice = o["Manufacturers"].Sum(m => (decimal)m.SelectToken("Products[0].Price"));
// 149.95
decimal totalPrice = o["Manufacturers"].Sum(m => (decimal)m.SelectToken("Products[0].Price"));
// 149.95
Assert.AreEqual(2, storeNames.Count);
Assert.AreEqual("Lambton Quay", storeNames[0]);
Assert.AreEqual("Willis Street", storeNames[1]);
Assert.AreEqual(2, firstProductNames.Count);
Assert.AreEqual(null, firstProductNames[0]);
Assert.AreEqual("Headlight Fluid", firstProductNames[1]);
Assert.AreEqual(149.95m, totalPrice);
Assert.AreEqual(2, storeNames.Count);
Assert.AreEqual("Lambton Quay", storeNames[0]);
Assert.AreEqual("Willis Street", storeNames[1]);
Assert.AreEqual(2, firstProductNames.Count);
Assert.AreEqual(null, firstProductNames[0]);
Assert.AreEqual("Headlight Fluid", firstProductNames[1]);
Assert.AreEqual(149.95m, totalPrice);
}
}
}
}
+120 -132
View File
@@ -39,147 +39,135 @@ using System.IO;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JPropertyTests : TestFixtureBase
{
[Test]
public void NullValue()
[TestFixture]
public class JPropertyTests : TestFixtureBase
{
JProperty p = new JProperty("TestProperty", null);
Assert.IsNotNull(p.Value);
Assert.AreEqual(JTokenType.Null, p.Value.Type);
Assert.AreEqual(p, p.Value.Parent);
[Test]
public void NullValue()
{
JProperty p = new JProperty("TestProperty", null);
Assert.IsNotNull(p.Value);
Assert.AreEqual(JTokenType.Null, p.Value.Type);
Assert.AreEqual(p, p.Value.Parent);
p.Value = null;
Assert.IsNotNull(p.Value);
Assert.AreEqual(JTokenType.Null, p.Value.Type);
Assert.AreEqual(p, p.Value.Parent);
}
p.Value = null;
Assert.IsNotNull(p.Value);
Assert.AreEqual(JTokenType.Null, p.Value.Type);
Assert.AreEqual(p, p.Value.Parent);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void ListChanged()
{
JProperty p = new JProperty("TestProperty", null);
IBindingList l = p;
ListChangedType? listChangedType = null;
int? index = null;
l.ListChanged += (sender, args) =>
[Test]
public void ListChanged()
{
listChangedType = args.ListChangedType;
index = args.NewIndex;
};
JProperty p = new JProperty("TestProperty", null);
IBindingList l = p;
p.Value = 1;
ListChangedType? listChangedType = null;
int? index = null;
Assert.AreEqual(ListChangedType.ItemChanged, listChangedType.Value);
Assert.AreEqual(0, index.Value);
}
l.ListChanged += (sender, args) =>
{
listChangedType = args.ListChangedType;
index = args.NewIndex;
};
p.Value = 1;
Assert.AreEqual(ListChangedType.ItemChanged, listChangedType.Value);
Assert.AreEqual(0, index.Value);
}
#endif
[Test]
public void IListCount()
{
JProperty p = new JProperty("TestProperty", null);
IList l = p;
Assert.AreEqual(1, l.Count);
}
[Test]
public void IListClear()
{
JProperty p = new JProperty("TestProperty", null);
IList l = p;
ExceptionAssert.Throws<JsonException>(
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
() =>
[Test]
public void IListCount()
{
l.Clear();
});
JProperty p = new JProperty("TestProperty", null);
IList l = p;
Assert.AreEqual(1, l.Count);
}
[Test]
public void IListClear()
{
JProperty p = new JProperty("TestProperty", null);
IList l = p;
ExceptionAssert.Throws<JsonException>(
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
() => { l.Clear(); });
}
[Test]
public void IListAdd()
{
JProperty p = new JProperty("TestProperty", null);
IList l = p;
ExceptionAssert.Throws<JsonException>(
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
() => { l.Add(null); });
}
[Test]
public void IListRemove()
{
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); });
}
[Test]
public void Load()
{
JsonReader reader = new JsonTextReader(new StringReader("{'propertyname':['value1']}"));
reader.Read();
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
reader.Read();
JProperty property = JProperty.Load(reader);
Assert.AreEqual("propertyname", property.Name);
Assert.IsTrue(JToken.DeepEquals(JArray.Parse("['value1']"), property.Value));
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
reader = new JsonTextReader(new StringReader("{'propertyname':null}"));
reader.Read();
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
reader.Read();
property = JProperty.Load(reader);
Assert.AreEqual("propertyname", property.Name);
Assert.IsTrue(JToken.DeepEquals(new JValue(null, JTokenType.Null), property.Value));
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
}
[Test]
public void MultiContentConstructor()
{
JProperty p = new JProperty("error", new List<string> { "one", "two" });
JArray a = (JArray)p.Value;
Assert.AreEqual(a.Count, 2);
Assert.AreEqual("one", (string)a[0]);
Assert.AreEqual("two", (string)a[1]);
}
[Test]
public void IListGenericAdd()
{
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); });
}
}
[Test]
public void IListAdd()
{
JProperty p = new JProperty("TestProperty", null);
IList l = p;
ExceptionAssert.Throws<JsonException>(
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
() =>
{
l.Add(null);
});
}
[Test]
public void IListRemove()
{
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);
});
}
[Test]
public void Load()
{
JsonReader reader = new JsonTextReader(new StringReader("{'propertyname':['value1']}"));
reader.Read();
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
reader.Read();
JProperty property = JProperty.Load(reader);
Assert.AreEqual("propertyname", property.Name);
Assert.IsTrue(JToken.DeepEquals(JArray.Parse("['value1']"), property.Value));
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
reader = new JsonTextReader(new StringReader("{'propertyname':null}"));
reader.Read();
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
reader.Read();
property = JProperty.Load(reader);
Assert.AreEqual("propertyname", property.Name);
Assert.IsTrue(JToken.DeepEquals(new JValue(null, JTokenType.Null), property.Value));
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
}
[Test]
public void MultiContentConstructor()
{
JProperty p = new JProperty("error", new List<string> {"one", "two"});
JArray a = (JArray) p.Value;
Assert.AreEqual(a.Count, 2);
Assert.AreEqual("one", (string) a[0]);
Assert.AreEqual("two", (string) a[1]);
}
[Test]
public void IListGenericAdd()
{
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);
});
}
}
}
+29 -29
View File
@@ -35,36 +35,36 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JRawTests : TestFixtureBase
{
[Test]
public void RawEquals()
[TestFixture]
public class JRawTests : TestFixtureBase
{
JRaw r1 = new JRaw("raw1");
JRaw r2 = new JRaw("raw1");
JRaw r3 = new JRaw("raw2");
[Test]
public void RawEquals()
{
JRaw r1 = new JRaw("raw1");
JRaw r2 = new JRaw("raw1");
JRaw r3 = new JRaw("raw2");
Assert.IsTrue(JToken.DeepEquals(r1, r2));
Assert.IsFalse(JToken.DeepEquals(r1, r3));
Assert.IsTrue(JToken.DeepEquals(r1, r2));
Assert.IsFalse(JToken.DeepEquals(r1, r3));
}
[Test]
public void RawClone()
{
JRaw r1 = new JRaw("raw1");
JToken r2 = r1.CloneToken();
CustomAssert.IsInstanceOfType(typeof(JRaw), r2);
}
[Test]
public void RawToObject()
{
JRaw r1 = new JRaw("1");
int i = r1.ToObject<int>();
Assert.AreEqual(1, i);
}
}
[Test]
public void RawClone()
{
JRaw r1 = new JRaw("raw1");
JToken r2 = r1.CloneToken();
CustomAssert.IsInstanceOfType(typeof(JRaw), r2);
}
[Test]
public void RawToObject()
{
JRaw r1 = new JRaw("1");
int i = r1.ToObject<int>();
Assert.AreEqual(1, i);
}
}
}
@@ -35,55 +35,55 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JTokenEqualityComparerTests : TestFixtureBase
{
[Test]
public void JValueDictionary()
[TestFixture]
public class JTokenEqualityComparerTests : TestFixtureBase
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JValue v11 = new JValue(1);
JValue v12 = new JValue(1);
[Test]
public void JValueDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JValue v11 = new JValue(1);
JValue v12 = new JValue(1);
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
[Test]
public void JArrayDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JArray v11 = new JArray();
JArray v12 = new JArray();
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
[Test]
public void JObjectDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JObject v11 = new JObject() { { "Test", new JValue(1) }, { "Test1", new JValue(1) } };
JObject v12 = new JObject() { { "Test", new JValue(1) }, { "Test1", new JValue(1) } };
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
[Test]
public void JConstructorDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JConstructor v11 = new JConstructor("ConstructorValue");
JConstructor v12 = new JConstructor("ConstructorValue");
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
}
[Test]
public void JArrayDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JArray v11 = new JArray();
JArray v12 = new JArray();
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
[Test]
public void JObjectDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JObject v11 = new JObject() { { "Test", new JValue(1) }, { "Test1", new JValue(1) } };
JObject v12 = new JObject() { { "Test", new JValue(1) }, { "Test1", new JValue(1) } };
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
[Test]
public void JConstructorDictionary()
{
Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
JConstructor v11 = new JConstructor("ConstructorValue");
JConstructor v12 = new JConstructor("ConstructorValue");
dic[v11] = 1;
dic[v12] += 1;
Assert.AreEqual(2, dic[v11]);
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+131 -130
View File
@@ -43,181 +43,182 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JTokenWriterTest : TestFixtureBase
{
[Test]
public void ValueFormatting()
[TestFixture]
public class JTokenWriterTest : TestFixtureBase
{
byte[] data = Encoding.UTF8.GetBytes("Hello world.");
[Test]
public void ValueFormatting()
{
byte[] data = Encoding.UTF8.GetBytes("Hello world.");
JToken root;
using (JTokenWriter jsonWriter = new JTokenWriter())
{
jsonWriter.WriteStartArray();
jsonWriter.WriteValue('@');
jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
jsonWriter.WriteValue(true);
jsonWriter.WriteValue(10);
jsonWriter.WriteValue(10.99);
jsonWriter.WriteValue(0.99);
jsonWriter.WriteValue(0.000000000000000001d);
jsonWriter.WriteValue(0.000000000000000001m);
jsonWriter.WriteValue((string)null);
jsonWriter.WriteValue("This is a string.");
jsonWriter.WriteNull();
jsonWriter.WriteUndefined();
jsonWriter.WriteValue(data);
jsonWriter.WriteEndArray();
JToken root;
using (JTokenWriter jsonWriter = new JTokenWriter())
{
jsonWriter.WriteStartArray();
jsonWriter.WriteValue('@');
jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
jsonWriter.WriteValue(true);
jsonWriter.WriteValue(10);
jsonWriter.WriteValue(10.99);
jsonWriter.WriteValue(0.99);
jsonWriter.WriteValue(0.000000000000000001d);
jsonWriter.WriteValue(0.000000000000000001m);
jsonWriter.WriteValue((string)null);
jsonWriter.WriteValue("This is a string.");
jsonWriter.WriteNull();
jsonWriter.WriteUndefined();
jsonWriter.WriteValue(data);
jsonWriter.WriteEndArray();
root = jsonWriter.Token;
}
root = jsonWriter.Token;
}
CustomAssert.IsInstanceOfType(typeof(JArray), root);
Assert.AreEqual(13, root.Children().Count());
Assert.AreEqual("@", (string)root[0]);
Assert.AreEqual("\r\n\t\f\b?{\\r\\n\"\'", (string)root[1]);
Assert.AreEqual(true, (bool)root[2]);
Assert.AreEqual(10, (int)root[3]);
Assert.AreEqual(10.99, (double)root[4]);
Assert.AreEqual(0.99, (double)root[5]);
Assert.AreEqual(0.000000000000000001d, (double)root[6]);
Assert.AreEqual(0.000000000000000001m, (decimal)root[7]);
Assert.AreEqual(string.Empty, (string)root[8]);
Assert.AreEqual("This is a string.", (string)root[9]);
Assert.AreEqual(null, ((JValue)root[10]).Value);
Assert.AreEqual(null, ((JValue)root[11]).Value);
Assert.AreEqual(data, (byte[])root[12]);
}
CustomAssert.IsInstanceOfType(typeof(JArray), root);
Assert.AreEqual(13, root.Children().Count());
Assert.AreEqual("@", (string)root[0]);
Assert.AreEqual("\r\n\t\f\b?{\\r\\n\"\'", (string)root[1]);
Assert.AreEqual(true, (bool)root[2]);
Assert.AreEqual(10, (int)root[3]);
Assert.AreEqual(10.99, (double)root[4]);
Assert.AreEqual(0.99, (double)root[5]);
Assert.AreEqual(0.000000000000000001d, (double)root[6]);
Assert.AreEqual(0.000000000000000001m, (decimal)root[7]);
Assert.AreEqual(string.Empty, (string)root[8]);
Assert.AreEqual("This is a string.", (string)root[9]);
Assert.AreEqual(null, ((JValue)root[10]).Value);
Assert.AreEqual(null, ((JValue)root[11]).Value);
Assert.AreEqual(data, (byte[])root[12]);
}
[Test]
public void State()
{
using (JsonWriter jsonWriter = new JTokenWriter())
{
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
[Test]
public void State()
{
using (JsonWriter jsonWriter = new JTokenWriter())
{
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
jsonWriter.WriteStartObject();
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WriteStartObject();
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WritePropertyName("CPU");
Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
jsonWriter.WritePropertyName("CPU");
Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
jsonWriter.WriteValue("Intel");
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WriteValue("Intel");
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WritePropertyName("Drives");
Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
jsonWriter.WritePropertyName("Drives");
Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
jsonWriter.WriteStartArray();
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteStartArray();
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteValue("DVD read/writer");
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteValue("DVD read/writer");
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
jsonWriter.WriteValue(new BigInteger(123));
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteValue(new BigInteger(123));
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
#endif
jsonWriter.WriteValue(new byte[0]);
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteValue(new byte[0]);
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
jsonWriter.WriteEnd();
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WriteEnd();
Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
jsonWriter.WriteEndObject();
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
}
}
jsonWriter.WriteEndObject();
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
}
}
[Test]
public void WriteComment()
{
JTokenWriter writer = new JTokenWriter();
[Test]
public void WriteComment()
{
JTokenWriter writer = new JTokenWriter();
writer.WriteStartArray();
writer.WriteComment("fail");
writer.WriteEndArray();
writer.WriteStartArray();
writer.WriteComment("fail");
writer.WriteEndArray();
Assert.AreEqual(@"[
Assert.AreEqual(@"[
/*fail*/]", writer.Token.ToString());
}
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void WriteBigInteger()
{
JTokenWriter writer = new JTokenWriter();
[Test]
public void WriteBigInteger()
{
JTokenWriter writer = new JTokenWriter();
writer.WriteStartArray();
writer.WriteValue(new BigInteger(123));
writer.WriteEndArray();
writer.WriteStartArray();
writer.WriteValue(new BigInteger(123));
writer.WriteEndArray();
JValue i = (JValue) writer.Token[0];
JValue i = (JValue)writer.Token[0];
Assert.AreEqual(new BigInteger(123), i.Value);
Assert.AreEqual(JTokenType.Integer, i.Type);
Assert.AreEqual(new BigInteger(123), i.Value);
Assert.AreEqual(JTokenType.Integer, i.Type);
Assert.AreEqual(@"[
Assert.AreEqual(@"[
123
]", writer.Token.ToString());
}
}
#endif
[Test]
public void WriteRaw()
{
JTokenWriter writer = new JTokenWriter();
[Test]
public void WriteRaw()
{
JTokenWriter writer = new JTokenWriter();
writer.WriteStartArray();
writer.WriteRaw("fail");
writer.WriteRaw("fail");
writer.WriteEndArray();
writer.WriteStartArray();
writer.WriteRaw("fail");
writer.WriteRaw("fail");
writer.WriteEndArray();
// this is a bug. write raw shouldn't be autocompleting like this
// hard to fix without introducing Raw and RawValue token types
// meh
Assert.AreEqual(@"[
// this is a bug. write raw shouldn't be autocompleting like this
// hard to fix without introducing Raw and RawValue token types
// meh
Assert.AreEqual(@"[
fail,
fail
]", writer.Token.ToString());
}
}
[Test]
public void WriteRawValue()
{
JTokenWriter writer = new JTokenWriter();
[Test]
public void WriteRawValue()
{
JTokenWriter writer = new JTokenWriter();
writer.WriteStartArray();
writer.WriteRawValue("fail");
writer.WriteRawValue("fail");
writer.WriteEndArray();
writer.WriteStartArray();
writer.WriteRawValue("fail");
writer.WriteRawValue("fail");
writer.WriteEndArray();
Assert.AreEqual(@"[
Assert.AreEqual(@"[
fail,
fail
]", writer.Token.ToString());
}
[Test]
public void DateTimeZoneHandling()
{
JTokenWriter writer = new JTokenWriter
{
DateTimeZoneHandling = Json.DateTimeZoneHandling.Utc
};
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
JValue value = (JValue)writer.Token;
DateTime dt = (DateTime)value.Value;
Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc), dt);
}
}
[Test]
public void DateTimeZoneHandling()
{
JTokenWriter writer = new JTokenWriter
{
DateTimeZoneHandling = Json.DateTimeZoneHandling.Utc
};
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
JValue value = (JValue) writer.Token;
DateTime dt = (DateTime)value.Value;
Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc), dt);
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff