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
path: root/Src
diff options
context:
space:
mode:
authorJamesNK <james@newtonking.com>2010-09-24 14:32:43 +0400
committerJamesNK <james@newtonking.com>2010-09-24 14:32:43 +0400
commit6591f7f29abeaa40fbdb83c067fab7f3ccc062b8 (patch)
treea6709ca391f3a45f21fa2c6e4949aa15cca0a47d /Src
parent8546dc4f620092053d1434b42df4dc9d05b2e08d (diff)
-Fixed test when tests run in UTC timezone
Diffstat (limited to 'Src')
-rw-r--r--Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs11
-rw-r--r--Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs32
2 files changed, 37 insertions, 6 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs
index 092a14e..2424c0e 100644
--- a/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs
@@ -262,14 +262,21 @@ namespace Newtonsoft.Json.Tests.Converters
[Test]
public void SerializeShouldChangeNonUTCDates()
{
+ DateTime localDateTime = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Local);
+
DateTimeTestClass c = new DateTimeTestClass();
- c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Local);
+ c.DateTimeField = localDateTime;
c.PreField = "Pre";
c.PostField = "Post";
string json = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal }); //note that this fails without the Utc converter...
c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc);
string json2 = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
- Assert.AreNotEqual(json, json2);
+
+ // if the current timezone is utc then local already equals utc
+ if (TimeZone.CurrentTimeZone.GetUtcOffset(localDateTime) == TimeSpan.Zero)
+ Assert.AreEqual(json, json2);
+ else
+ Assert.AreNotEqual(json, json2);
}
#endif
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs
index 1a1dd32..50d67fa 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs
@@ -579,12 +579,18 @@ namespace Newtonsoft.Json.Tests.Serialization
Dictionary<string, object> collection = new Dictionary<string, object>()
{
{"First", new UrlStatus{ Status = 404, Url = @"http://www.bing.com"}},
- {"Second", new UrlStatus{Status = 400, Url = @"http://www.google.com"}}
+ {"Second", new UrlStatus{Status = 400, Url = @"http://www.google.com"}},
+ {"List", new List<UrlStatus>
+ {
+ new UrlStatus {Status = 300, Url = @"http://www.yahoo.com"},
+ new UrlStatus {Status = 200, Url = @"http://www.askjeeves.com"}
+ }
+ }
};
string json = JsonConvert.SerializeObject(collection, Formatting.Indented, new JsonSerializerSettings
{
- TypeNameHandling = TypeNameHandling.Objects,
+ TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
@@ -599,20 +605,38 @@ namespace Newtonsoft.Json.Tests.Serialization
""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"",
""Status"": 400,
""Url"": ""http://www.google.com""
+ },
+ ""List"": {
+ ""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests]], mscorlib"",
+ ""$values"": [
+ {
+ ""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"",
+ ""Status"": 300,
+ ""Url"": ""http://www.yahoo.com""
+ },
+ {
+ ""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"",
+ ""Status"": 200,
+ ""Url"": ""http://www.askjeeves.com""
+ }
+ ]
}
}", json);
object c = JsonConvert.DeserializeObject(json, new JsonSerializerSettings
{
- TypeNameHandling = TypeNameHandling.Objects,
+ TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
Assert.IsInstanceOfType(typeof(Dictionary<string, object>), c);
Dictionary<string, object> newCollection = (Dictionary<string, object>)c;
- Assert.AreEqual(2, newCollection.Count);
+ Assert.AreEqual(3, newCollection.Count);
Assert.AreEqual(@"http://www.bing.com", ((UrlStatus)newCollection["First"]).Url);
+
+ List<UrlStatus> statues = (List<UrlStatus>) newCollection["List"];
+ Assert.AreEqual(2, statues.Count);
}
}