-Fixed DataTable and DataColumn names not being modified by CamelCasePropertyNamesContractResolver

This commit is contained in:
JamesNK
2011-08-03 00:50:44 +00:00
parent 18c9400054
commit 44ab7f71df
10 changed files with 106 additions and 10 deletions
@@ -801,7 +801,54 @@ namespace Newtonsoft.Json.Tests.Bson
reader = new BsonReader(new MemoryStream(bson), false, DateTimeKind.Unspecified);
o = (JObject)JToken.ReadFrom(reader);
Assert.AreEqual(DateTime.SpecifyKind(value.ToLocalTime(), DateTimeKind.Unspecified), (DateTime)o["DateTime"]);
Assert.AreEqual(DateTime.SpecifyKind(value, DateTimeKind.Unspecified), (DateTime)o["DateTime"]);
}
[Test]
public void UnspecifiedDateTimeKindHandling()
{
DateTime value = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.DateTimeKindHandling = DateTimeKind.Unspecified;
writer.WriteStartObject();
writer.WritePropertyName("DateTime");
writer.WriteValue(value);
writer.WriteEndObject();
byte[] bson = ms.ToArray();
JObject o;
BsonReader reader;
reader = new BsonReader(new MemoryStream(bson), false, DateTimeKind.Unspecified);
o = (JObject)JToken.ReadFrom(reader);
Assert.AreEqual(value, (DateTime)o["DateTime"]);
}
[Test]
public void LocalDateTimeKindHandling()
{
DateTime value = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local);
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartObject();
writer.WritePropertyName("DateTime");
writer.WriteValue(value);
writer.WriteEndObject();
byte[] bson = ms.ToArray();
JObject o;
BsonReader reader;
reader = new BsonReader(new MemoryStream(bson), false, DateTimeKind.Local);
o = (JObject)JToken.ReadFrom(reader);
Assert.AreEqual(value, (DateTime)o["DateTime"]);
}
private string WriteAndReadStringValue(string val)
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
using NUnit.Framework;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using System.Data;
@@ -251,7 +252,51 @@ namespace Newtonsoft.Json.Tests.Converters
}
[Test]
public void Blah()
public void SerializeWithCamelCaseResolver()
{
DataSet ds = new DataSet();
ds.Tables.Add(CreateDataTable("FirstTable", 2));
ds.Tables.Add(CreateDataTable("SecondTable", 1));
string json = JsonConvert.SerializeObject(ds, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
Assert.AreEqual(@"{
""firstTable"": [
{
""stringCol"": ""Item Name"",
""int32Col"": 1,
""booleanCol"": true,
""timeSpanCol"": ""10.22:10:15.1000000"",
""dateTimeCol"": ""\/Date(978048000000)\/"",
""decimalCol"": 64.0021
},
{
""stringCol"": ""Item Name"",
""int32Col"": 2,
""booleanCol"": true,
""timeSpanCol"": ""10.22:10:15.1000000"",
""dateTimeCol"": ""\/Date(978048000000)\/"",
""decimalCol"": 64.0021
}
],
""secondTable"": [
{
""stringCol"": ""Item Name"",
""int32Col"": 1,
""booleanCol"": true,
""timeSpanCol"": ""10.22:10:15.1000000"",
""dateTimeCol"": ""\/Date(978048000000)\/"",
""decimalCol"": 64.0021
}
]
}", json);
}
[Test]
public void SerializeDataSetProperty()
{
DataSet ds = new DataSet();
ds.Tables.Add(CreateDataTable("FirstTable", 2));
@@ -41,5 +41,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.2.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.0.2.14002")]
[assembly: AssemblyFileVersion("4.0.2.14003")]
#endif