-Updated to NuGet 1.7

-Fixed JsonWriters not using DateTimeZoneHandling
This commit is contained in:
James Newton-King
2012-04-17 19:41:36 +12:00
parent fa3debccad
commit 6725edb75c
11 changed files with 87 additions and 4 deletions
@@ -664,5 +664,21 @@ namespace Newtonsoft.Json.Tests.Bson
}
});
}
[Test]
public void DateTimeZoneHandling()
{
MemoryStream ms = new MemoryStream();
JsonWriter writer = new BsonWriter(ms)
{
DateTimeZoneHandling = Json.DateTimeZoneHandling.Utc
};
writer.WriteStartArray();
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
writer.WriteEndArray();
Assert.AreEqual("10-00-00-00-09-30-00-C8-88-07-6B-DC-00-00-00-00", (BitConverter.ToString(ms.ToArray())));
}
}
}
@@ -751,5 +751,18 @@ now brown cow?", '"', true);
Assert.AreEqual("Existing,Appended", p.Name);
}
#endif
[Test]
public void SerializeObjectDateTimeZoneHandling()
{
string json = JsonConvert.SerializeObject(
new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified),
new JsonSerializerSettings
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc
});
Assert.AreEqual(@"""2000-01-01T01:01:01Z""", json);
}
}
}
@@ -824,5 +824,19 @@ _____'propertyName': NaN
}
}
}
[Test]
public void DateTimeZoneHandling()
{
StringWriter sw = new StringWriter();
JsonTextWriter writer = new JsonTextWriter(sw)
{
DateTimeZoneHandling = Json.DateTimeZoneHandling.Utc
};
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
Assert.AreEqual(@"""2000-01-01T01:01:01Z""", sw.ToString());
}
}
}
@@ -174,5 +174,21 @@ namespace Newtonsoft.Json.Tests.Linq
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);
}
}
}
@@ -72,5 +72,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.5.2.14814")]
[assembly: AssemblyFileVersion("4.5.3.14817")]
#endif
@@ -338,6 +338,29 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual("[0] - 0 - Could not convert string to integer: a. Line 1, position 4.", errors[0]);
Assert.AreEqual("[1] - 1 - Could not convert string to integer: b. Line 1, position 8.", errors[1]);
}
[Test]
public void ErrorHandlingAndAvoidingRecursiveDepthError()
{
string json = "{'A':{'A':{'A':{'A':{'A':{}}}}}}";
JsonSerializer serializer = new JsonSerializer() { };
IList<string> errors = new List<string>();
serializer.Error += (sender, e) =>
{
e.ErrorContext.Handled = true;
errors.Add(e.ErrorContext.Path);
};
serializer.Deserialize<Nest>(new JsonTextReader(new StringReader(json)) { MaxDepth = 3 });
Assert.AreEqual(1, errors.Count);
Assert.AreEqual("A.A.A", errors[0]);
}
public class Nest
{
public Nest A { get; set; }
}
}
[JsonObject]