diff --git a/Build/build.ps1 b/Build/build.ps1 index be2a02a8..263dfb60 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -162,7 +162,7 @@ function CoreClrTests($build) Write-Host -ForegroundColor Green "Ensuring latest CoreCLR is installed for $name" Write-Host - #exec { & $toolsDir\Kvm\kvm.ps1 upgrade -r CoreCLR | Out-Default } + exec { & $toolsDir\Kvm\kvm.ps1 upgrade -r CoreCLR -NoNative | Out-Default } Write-Host -ForegroundColor Green "Restoring packages for $name" Write-Host diff --git a/Build/runbuild.cmd b/Build/runbuild.cmd index fbfeb952..b8012495 100644 --- a/Build/runbuild.cmd +++ b/Build/runbuild.cmd @@ -1,3 +1,4 @@ +cls powershell -Command "& { [Console]::WindowWidth = 150; [Console]::WindowHeight = 50; Start-Transcript runbuild.txt; Import-Module ..\Tools\PSake\psake.psm1; Invoke-psake ..\Build\build.ps1 %*; Stop-Transcript; }" pause \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs index bd743bdb..0da436eb 100644 --- a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs +++ b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs @@ -74,6 +74,52 @@ namespace Newtonsoft.Json.Tests.Bson } #endif + public class MyTest + { + public DateTime TimeStamp { get; set; } + public string UserName { get; set; } + public MemoryStream Blob { get; set; } + } + + public void Bson_SupportMultipleContent() + { + MemoryStream myStream = new MemoryStream(); + BsonWriter writer = new BsonWriter(myStream); + JsonSerializer serializer = new JsonSerializer(); + MyTest tst1 = new MyTest + { + TimeStamp = new DateTime(2000, 12, 20, 12, 59, 59, DateTimeKind.Utc), + UserName = "Joe Doe" + }; + MyTest tst2 = new MyTest + { + TimeStamp = new DateTime(2010, 12, 20, 12, 59, 59, DateTimeKind.Utc), + UserName = "Bob" + }; + serializer.Serialize(writer, tst1); + serializer.Serialize(writer, tst2); + + myStream.Seek(0, SeekOrigin.Begin); + + BsonReader reader = new BsonReader(myStream) + { + SupportMultipleContent = true, + DateTimeKindHandling = DateTimeKind.Utc + }; + + MyTest tst1A = serializer.Deserialize(reader); + + reader.Read(); + + MyTest tst2A = serializer.Deserialize(reader); + + Assert.AreEqual(tst1.UserName, tst1A.UserName); + Assert.AreEqual(tst1.TimeStamp, tst1A.TimeStamp); + + Assert.AreEqual(tst2.UserName, tst2A.UserName); + Assert.AreEqual(tst2.TimeStamp, tst2A.TimeStamp); + } + [Test] public void CloseInput() { diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 3557f671..944388d3 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -2360,9 +2360,27 @@ third line", jsonTextReader.Value); [Test] public void SupportMultipleContent() { - JsonTextReader reader = new JsonTextReader(new StringReader(@"1 2 ""name"" [][]null {}{} 1.1")); + JsonTextReader reader = new JsonTextReader(new StringReader(@"{'prop1':[1]} 1 2 ""name"" [][]null {}{} 1.1")); reader.SupportMultipleContent = true; + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.StartObject, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.PropertyName, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.StartArray, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.Integer, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.EndArray, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.EndObject, reader.TokenType); + Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.Integer, reader.TokenType); diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenReaderTest.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenReaderTest.cs index c7cd98cf..d1448bfb 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JTokenReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenReaderTest.cs @@ -270,15 +270,15 @@ namespace Newtonsoft.Json.Tests.Linq jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray); - Assert.AreEqual(0, lineInfo.LineNumber); - Assert.AreEqual(0, lineInfo.LinePosition); - Assert.AreEqual(false, lineInfo.HasLineInfo()); + Assert.AreEqual(3, lineInfo.LineNumber); + Assert.AreEqual(12, lineInfo.LinePosition); + Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject); - Assert.AreEqual(0, lineInfo.LineNumber); - Assert.AreEqual(0, lineInfo.LinePosition); - Assert.AreEqual(false, lineInfo.HasLineInfo()); + Assert.AreEqual(1, lineInfo.LineNumber); + Assert.AreEqual(1, lineInfo.LinePosition); + Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.None); diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs index 69cac854..f7a839e6 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs @@ -107,18 +107,19 @@ namespace Newtonsoft.Json.Tests.Schema [Test] public void ValidateFailureWithOutLineInfoBecauseOfEndToken() { + // changed in 6.0.6 to now include line info! JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'required':true}}}"); JObject o = JObject.Parse("{}"); List errors = new List(); o.Validate(schema, (sender, args) => errors.Add(args.Message)); - Assert.AreEqual("Required properties are missing from object: lol.", errors[0]); + Assert.AreEqual("Required properties are missing from object: lol. Line 1, position 1.", errors[0]); Assert.AreEqual(1, errors.Count); } [Test] - public void ValidateFailureWithLineInfo() + public void ValidateRequiredFieldsWithLineInfo() { JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'type':'string'}}}"); JObject o = JObject.Parse("{'lol':1}"); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index 457310ec..409faaca 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -23,8 +23,9 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !(PORTABLE || ASPNETCORE50 || PORTABLE40) -#if !(NET35 || NET20 || PORTABLE || ASPNETCORE50) +#if !(PORTABLE || PORTABLE40) +using System.Collections.ObjectModel; +#if !(NET35 || NET20) using System.Dynamic; #endif using System.Text; @@ -58,6 +59,71 @@ namespace Newtonsoft.Json.Tests.Serialization [TestFixture] public class TypeNameHandlingTests : TestFixtureBase { +#if !(NET20 || NET35 || NET40) + public class KnownAutoTypes + { + public ICollection Collection { get; set; } + public IList List { get; set; } + public IDictionary Dictionary { get; set; } + public ISet Set { get; set; } + public IReadOnlyCollection ReadOnlyCollection { get; set; } + public IReadOnlyList ReadOnlyList { get; set; } + public IReadOnlyDictionary ReadOnlyDictionary { get; set; } + } + + [Test] + public void KnownAutoTypesTest() + { + KnownAutoTypes c = new KnownAutoTypes + { + Collection = new List { "Collection value!" }, + List = new List { "List value!" }, + Dictionary = new Dictionary + { + { "Dictionary key!", "Dictionary value!" } + }, + ReadOnlyCollection = new ReadOnlyCollection(new[] { "Read Only Collection value!" }), + ReadOnlyList = new ReadOnlyCollection(new[] { "Read Only List value!" }), + Set = new HashSet { "Set value!" }, + ReadOnlyDictionary = new ReadOnlyDictionary(new Dictionary + { + { "Read Only Dictionary key!", "Read Only Dictionary value!" } + }) + }; + + string json = JsonConvert.SerializeObject(c, Formatting.Indented, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Auto + }); + + Console.WriteLine(json); + + StringAssert.AreEqual(@"{ + ""Collection"": [ + ""Collection value!"" + ], + ""List"": [ + ""List value!"" + ], + ""Dictionary"": { + ""Dictionary key!"": ""Dictionary value!"" + }, + ""Set"": [ + ""Set value!"" + ], + ""ReadOnlyCollection"": [ + ""Read Only Collection value!"" + ], + ""ReadOnlyList"": [ + ""Read Only List value!"" + ], + ""ReadOnlyDictionary"": { + ""Read Only Dictionary key!"": ""Read Only Dictionary value!"" + } +}", json); + } +#endif + [Test] public void DictionaryAuto() { @@ -1035,7 +1101,7 @@ namespace Newtonsoft.Json.Tests.Serialization CollectionAssert.AreEquivalent(data, d); } -#if !(NETFX_CORE) +#if !(NETFX_CORE || ASPNETCORE50) [Test] public void ISerializableTypeNameHandlingTest() { @@ -1132,10 +1198,10 @@ namespace Newtonsoft.Json.Tests.Serialization public override void BindToName(Type serializedType, out string assemblyName, out string typeName) { assemblyName = "AssemblyName"; -#if !NETFX_CORE +#if !(NETFX_CORE || ASPNETCORE50) typeName = ":::" + serializedType.Name.ToUpper(CultureInfo.InvariantCulture) + ":::"; #else - typeName = ":::" + serializedType.Name.ToUpper() + ":::"; + typeName = ":::" + serializedType.Name.ToUpper() + ":::"; #endif } } @@ -1577,7 +1643,7 @@ namespace Newtonsoft.Json.Tests.Serialization } #endif -#if !NETFX_CORE +#if !(NETFX_CORE || ASPNETCORE50) [Test] public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid() { @@ -1772,7 +1838,7 @@ namespace Newtonsoft.Json.Tests.Serialization #endif } -#if !NETFX_CORE +#if !(NETFX_CORE || ASPNETCORE50) public class ParentParent { [JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)] @@ -1840,7 +1906,7 @@ namespace Newtonsoft.Json.Tests.Serialization public int Quantity { get; set; } } -#if !(NETFX_CORE) +#if !(NETFX_CORE || ASPNETCORE50) public class SerializableWrapper { public object Content { get; set; } diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs index 694da3be..8b29d885 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs @@ -169,11 +169,6 @@ namespace Newtonsoft.Json.Linq return false; } - private bool IsEndElement - { - get { return (_current == _parent); } - } - private JsonToken? GetEndToken(JContainer c) { switch (c.Type) @@ -293,7 +288,7 @@ namespace Newtonsoft.Json.Linq if (CurrentState == State.Start) return false; - IJsonLineInfo info = IsEndElement ? null : _current; + IJsonLineInfo info = _current; return (info != null && info.HasLineInfo()); } @@ -304,7 +299,7 @@ namespace Newtonsoft.Json.Linq if (CurrentState == State.Start) return 0; - IJsonLineInfo info = IsEndElement ? null : _current; + IJsonLineInfo info = _current; if (info != null) return info.LineNumber; @@ -319,7 +314,7 @@ namespace Newtonsoft.Json.Linq if (CurrentState == State.Start) return 0; - IJsonLineInfo info = IsEndElement ? null : _current; + IJsonLineInfo info = _current; if (info != null) return info.LinePosition;