Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/Newtonsoft.Json.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamesNK <james@newtonking.com>2011-08-03 04:50:44 +0400
committerJamesNK <james@newtonking.com>2011-08-03 04:50:44 +0400
commit44ab7f71dfcb4e07b6c1bf59241673a7054a5132 (patch)
treed9bf5077738ca7dfa6cb61fa6143c66753b88ddc /Src/Newtonsoft.Json.Tests
parent18c9400054ea6581beaa4db9beaba08291bb6826 (diff)
-Fixed DataTable and DataColumn names not being modified by CamelCasePropertyNamesContractResolver
Diffstat (limited to 'Src/Newtonsoft.Json.Tests')
-rw-r--r--Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs49
-rw-r--r--Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs47
-rw-r--r--Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs2
3 files changed, 95 insertions, 3 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs
index a5c3c1d..7548052 100644
--- a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs
@@ -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)
diff --git a/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs
index 14f1ef1..058072b 100644
--- a/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs
@@ -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));
diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
index cef54af..eb1028f 100644
--- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
+++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
@@ -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