-Fixed tests
-Changed JTokenReader to provide line numbers for end tokens
This commit is contained in:
+1
-1
@@ -162,7 +162,7 @@ function CoreClrTests($build)
|
|||||||
|
|
||||||
Write-Host -ForegroundColor Green "Ensuring latest CoreCLR is installed for $name"
|
Write-Host -ForegroundColor Green "Ensuring latest CoreCLR is installed for $name"
|
||||||
Write-Host
|
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 -ForegroundColor Green "Restoring packages for $name"
|
||||||
Write-Host
|
Write-Host
|
||||||
|
|||||||
@@ -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; }"
|
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
|
pause
|
||||||
@@ -74,6 +74,52 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
}
|
}
|
||||||
#endif
|
#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<MyTest>(reader);
|
||||||
|
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
MyTest tst2A = serializer.Deserialize<MyTest>(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]
|
[Test]
|
||||||
public void CloseInput()
|
public void CloseInput()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2360,9 +2360,27 @@ third line", jsonTextReader.Value);
|
|||||||
[Test]
|
[Test]
|
||||||
public void SupportMultipleContent()
|
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;
|
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.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||||
|
|
||||||
|
|||||||
@@ -270,15 +270,15 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
jsonReader.Read();
|
jsonReader.Read();
|
||||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
|
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
|
||||||
Assert.AreEqual(0, lineInfo.LineNumber);
|
Assert.AreEqual(3, lineInfo.LineNumber);
|
||||||
Assert.AreEqual(0, lineInfo.LinePosition);
|
Assert.AreEqual(12, lineInfo.LinePosition);
|
||||||
Assert.AreEqual(false, lineInfo.HasLineInfo());
|
Assert.AreEqual(true, lineInfo.HasLineInfo());
|
||||||
|
|
||||||
jsonReader.Read();
|
jsonReader.Read();
|
||||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject);
|
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject);
|
||||||
Assert.AreEqual(0, lineInfo.LineNumber);
|
Assert.AreEqual(1, lineInfo.LineNumber);
|
||||||
Assert.AreEqual(0, lineInfo.LinePosition);
|
Assert.AreEqual(1, lineInfo.LinePosition);
|
||||||
Assert.AreEqual(false, lineInfo.HasLineInfo());
|
Assert.AreEqual(true, lineInfo.HasLineInfo());
|
||||||
|
|
||||||
jsonReader.Read();
|
jsonReader.Read();
|
||||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.None);
|
Assert.AreEqual(jsonReader.TokenType, JsonToken.None);
|
||||||
|
|||||||
@@ -107,18 +107,19 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
[Test]
|
[Test]
|
||||||
public void ValidateFailureWithOutLineInfoBecauseOfEndToken()
|
public void ValidateFailureWithOutLineInfoBecauseOfEndToken()
|
||||||
{
|
{
|
||||||
|
// changed in 6.0.6 to now include line info!
|
||||||
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'required':true}}}");
|
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'required':true}}}");
|
||||||
JObject o = JObject.Parse("{}");
|
JObject o = JObject.Parse("{}");
|
||||||
|
|
||||||
List<string> errors = new List<string>();
|
List<string> errors = new List<string>();
|
||||||
o.Validate(schema, (sender, args) => errors.Add(args.Message));
|
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);
|
Assert.AreEqual(1, errors.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ValidateFailureWithLineInfo()
|
public void ValidateRequiredFieldsWithLineInfo()
|
||||||
{
|
{
|
||||||
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'type':'string'}}}");
|
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'type':'string'}}}");
|
||||||
JObject o = JObject.Parse("{'lol':1}");
|
JObject o = JObject.Parse("{'lol':1}");
|
||||||
|
|||||||
@@ -23,8 +23,9 @@
|
|||||||
// OTHER DEALINGS IN THE SOFTWARE.
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#if !(PORTABLE || ASPNETCORE50 || PORTABLE40)
|
#if !(PORTABLE || PORTABLE40)
|
||||||
#if !(NET35 || NET20 || PORTABLE || ASPNETCORE50)
|
using System.Collections.ObjectModel;
|
||||||
|
#if !(NET35 || NET20)
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
#endif
|
#endif
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -58,6 +59,71 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TypeNameHandlingTests : TestFixtureBase
|
public class TypeNameHandlingTests : TestFixtureBase
|
||||||
{
|
{
|
||||||
|
#if !(NET20 || NET35 || NET40)
|
||||||
|
public class KnownAutoTypes
|
||||||
|
{
|
||||||
|
public ICollection<string> Collection { get; set; }
|
||||||
|
public IList<string> List { get; set; }
|
||||||
|
public IDictionary<string, string> Dictionary { get; set; }
|
||||||
|
public ISet<string> Set { get; set; }
|
||||||
|
public IReadOnlyCollection<string> ReadOnlyCollection { get; set; }
|
||||||
|
public IReadOnlyList<string> ReadOnlyList { get; set; }
|
||||||
|
public IReadOnlyDictionary<string, string> ReadOnlyDictionary { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void KnownAutoTypesTest()
|
||||||
|
{
|
||||||
|
KnownAutoTypes c = new KnownAutoTypes
|
||||||
|
{
|
||||||
|
Collection = new List<string> { "Collection value!" },
|
||||||
|
List = new List<string> { "List value!" },
|
||||||
|
Dictionary = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "Dictionary key!", "Dictionary value!" }
|
||||||
|
},
|
||||||
|
ReadOnlyCollection = new ReadOnlyCollection<string>(new[] { "Read Only Collection value!" }),
|
||||||
|
ReadOnlyList = new ReadOnlyCollection<string>(new[] { "Read Only List value!" }),
|
||||||
|
Set = new HashSet<string> { "Set value!" },
|
||||||
|
ReadOnlyDictionary = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "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]
|
[Test]
|
||||||
public void DictionaryAuto()
|
public void DictionaryAuto()
|
||||||
{
|
{
|
||||||
@@ -1035,7 +1101,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
CollectionAssert.AreEquivalent(data, d);
|
CollectionAssert.AreEquivalent(data, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NETFX_CORE)
|
#if !(NETFX_CORE || ASPNETCORE50)
|
||||||
[Test]
|
[Test]
|
||||||
public void ISerializableTypeNameHandlingTest()
|
public void ISerializableTypeNameHandlingTest()
|
||||||
{
|
{
|
||||||
@@ -1132,10 +1198,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
|
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
|
||||||
{
|
{
|
||||||
assemblyName = "AssemblyName";
|
assemblyName = "AssemblyName";
|
||||||
#if !NETFX_CORE
|
#if !(NETFX_CORE || ASPNETCORE50)
|
||||||
typeName = ":::" + serializedType.Name.ToUpper(CultureInfo.InvariantCulture) + ":::";
|
typeName = ":::" + serializedType.Name.ToUpper(CultureInfo.InvariantCulture) + ":::";
|
||||||
#else
|
#else
|
||||||
typeName = ":::" + serializedType.Name.ToUpper() + ":::";
|
typeName = ":::" + serializedType.Name.ToUpper() + ":::";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1577,7 +1643,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !NETFX_CORE
|
#if !(NETFX_CORE || ASPNETCORE50)
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
|
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
|
||||||
{
|
{
|
||||||
@@ -1772,7 +1838,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NETFX_CORE
|
#if !(NETFX_CORE || ASPNETCORE50)
|
||||||
public class ParentParent
|
public class ParentParent
|
||||||
{
|
{
|
||||||
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
|
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
|
||||||
@@ -1840,7 +1906,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public int Quantity { get; set; }
|
public int Quantity { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NETFX_CORE)
|
#if !(NETFX_CORE || ASPNETCORE50)
|
||||||
public class SerializableWrapper
|
public class SerializableWrapper
|
||||||
{
|
{
|
||||||
public object Content { get; set; }
|
public object Content { get; set; }
|
||||||
|
|||||||
@@ -169,11 +169,6 @@ namespace Newtonsoft.Json.Linq
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsEndElement
|
|
||||||
{
|
|
||||||
get { return (_current == _parent); }
|
|
||||||
}
|
|
||||||
|
|
||||||
private JsonToken? GetEndToken(JContainer c)
|
private JsonToken? GetEndToken(JContainer c)
|
||||||
{
|
{
|
||||||
switch (c.Type)
|
switch (c.Type)
|
||||||
@@ -293,7 +288,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
if (CurrentState == State.Start)
|
if (CurrentState == State.Start)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IJsonLineInfo info = IsEndElement ? null : _current;
|
IJsonLineInfo info = _current;
|
||||||
return (info != null && info.HasLineInfo());
|
return (info != null && info.HasLineInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +299,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
if (CurrentState == State.Start)
|
if (CurrentState == State.Start)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
IJsonLineInfo info = IsEndElement ? null : _current;
|
IJsonLineInfo info = _current;
|
||||||
if (info != null)
|
if (info != null)
|
||||||
return info.LineNumber;
|
return info.LineNumber;
|
||||||
|
|
||||||
@@ -319,7 +314,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
if (CurrentState == State.Start)
|
if (CurrentState == State.Start)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
IJsonLineInfo info = IsEndElement ? null : _current;
|
IJsonLineInfo info = _current;
|
||||||
if (info != null)
|
if (info != null)
|
||||||
return info.LinePosition;
|
return info.LinePosition;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user