-Fixed test error when tests run in UTC timezone

-Fixed globalization warnings
-Fixed SelectToken skipping last property name if it is a single character
This commit is contained in:
JamesNK
2010-09-29 06:14:30 +00:00
parent 6591f7f29a
commit 4cea6d3c09
11 changed files with 35 additions and 11 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ Json.NET comes in different versions for the various .NET frameworks.
.NET latest (4.0) .NET latest (4.0)
-DotNet35: -DotNet35:
.NET 3.5, Mono .NET 3.5 SP1, Mono
-DotNet20: -DotNet20:
.NET 2.0 .NET 2.0
@@ -272,8 +272,16 @@ namespace Newtonsoft.Json.Tests.Converters
c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc); c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc);
string json2 = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal }); string json2 = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
TimeSpan offset;
#if SILVERLIGHT
offset = TimeZoneInfo.Local.GetUtcOffset(localDateTime);
#else
offset = TimeZone.CurrentTimeZone.GetUtcOffset(localDateTime);
#endif
// if the current timezone is utc then local already equals utc // if the current timezone is utc then local already equals utc
if (TimeZone.CurrentTimeZone.GetUtcOffset(localDateTime) == TimeSpan.Zero) if (offset == TimeSpan.Zero)
Assert.AreEqual(json, json2); Assert.AreEqual(json, json2);
else else
Assert.AreNotEqual(json, json2); Assert.AreNotEqual(json, json2);
@@ -243,6 +243,15 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(3, (int)t); 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] [Test]
public void Example() public void Example()
{ {
@@ -594,28 +594,30 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
}); });
string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof (UrlStatus), FormatterAssemblyStyle.Simple);
Assert.AreEqual(@"{ Assert.AreEqual(@"{
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"", ""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
""First"": { ""First"": {
""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"", ""$type"": """ + urlStatusTypeName + @""",
""Status"": 404, ""Status"": 404,
""Url"": ""http://www.bing.com"" ""Url"": ""http://www.bing.com""
}, },
""Second"": { ""Second"": {
""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"", ""$type"": """ + urlStatusTypeName + @""",
""Status"": 400, ""Status"": 400,
""Url"": ""http://www.google.com"" ""Url"": ""http://www.google.com""
}, },
""List"": { ""List"": {
""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests]], mscorlib"", ""$type"": ""System.Collections.Generic.List`1[[" + urlStatusTypeName + @"]], mscorlib"",
""$values"": [ ""$values"": [
{ {
""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"", ""$type"": """ + urlStatusTypeName + @""",
""Status"": 300, ""Status"": 300,
""Url"": ""http://www.yahoo.com"" ""Url"": ""http://www.yahoo.com""
}, },
{ {
""$type"": ""Newtonsoft.Json.Tests.Serialization.TypeNameHandlingTests+UrlStatus, Newtonsoft.Json.Tests"", ""$type"": """ + urlStatusTypeName + @""",
""Status"": 200, ""Status"": 200,
""Url"": ""http://www.askjeeves.com"" ""Url"": ""http://www.askjeeves.com""
} }
+1 -1
View File
@@ -165,7 +165,7 @@ namespace Newtonsoft.Json.Bson
return null; return null;
if (TokenType == JsonToken.Integer || TokenType == JsonToken.Float) if (TokenType == JsonToken.Integer || TokenType == JsonToken.Float)
{ {
SetToken(JsonToken.Float, Convert.ToDecimal(Value)); SetToken(JsonToken.Float, Convert.ToDecimal(Value, CultureInfo.InvariantCulture));
return (decimal)Value; return (decimal)Value;
} }
+1 -1
View File
@@ -744,7 +744,7 @@ namespace Newtonsoft.Json
} }
else else
{ {
numberValue = decimal.Parse(number, NumberStyles.Number | NumberStyles.AllowExponent); numberValue = decimal.Parse(number, NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture);
} }
numberType = JsonToken.Float; numberType = JsonToken.Float;
+1 -1
View File
@@ -65,7 +65,7 @@ namespace Newtonsoft.Json.Linq
_currentIndex++; _currentIndex++;
} }
if (_currentIndex - 1 > currentPartStartIndex) if (_currentIndex > currentPartStartIndex)
{ {
string member = _expression.Substring(currentPartStartIndex, _currentIndex - currentPartStartIndex); string member = _expression.Substring(currentPartStartIndex, _currentIndex - currentPartStartIndex);
Parts.Add(member); Parts.Add(member);
+1 -1
View File
@@ -66,7 +66,7 @@ namespace Newtonsoft.Json.Linq
return null; return null;
if (TokenType == JsonToken.Integer || TokenType == JsonToken.Float) if (TokenType == JsonToken.Integer || TokenType == JsonToken.Float)
{ {
SetToken(JsonToken.Float, Convert.ToDecimal(Value)); SetToken(JsonToken.Float, Convert.ToDecimal(Value, CultureInfo.InvariantCulture));
return (decimal) Value; return (decimal) Value;
} }
@@ -67,6 +67,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\DotNet35\Newtonsoft.Json.Net35.xml</DocumentationFile> <DocumentationFile>bin\Release\DotNet35\Newtonsoft.Json.Net35.xml</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
@@ -305,6 +305,9 @@ namespace Newtonsoft.Json.Serialization
return JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor<object>(createdType); return JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor<object>(createdType);
} }
#if !PocketPC && !NET20
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Portability", "CA1903:UseOnlyApiFromTargetedFramework", MessageId = "System.Runtime.Serialization.DataContractAttribute.#get_IsReference()")]
#endif
private void InitializeContract(JsonContract contract) private void InitializeContract(JsonContract contract)
{ {
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType); JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType);
@@ -447,6 +447,7 @@ namespace Newtonsoft.Json.Serialization
#if !SILVERLIGHT && !PocketPC #if !SILVERLIGHT && !PocketPC
#if !NET20 #if !NET20
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Portability", "CA1903:UseOnlyApiFromTargetedFramework", MessageId = "System.Security.SecuritySafeCriticalAttribute")]
[SecuritySafeCritical] [SecuritySafeCritical]
#endif #endif
private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract) private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract)