From 2c9d9b9598d3d1546bf3272896f8056e826e5b02 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 26 Nov 2017 13:00:07 +1300 Subject: [PATCH] -Updated NuGet packages -Fixed xunit warnings --- .../Bson/BsonReaderTests.cs | 53 ++---------- .../CustomCreationConverterTests.cs | 3 +- .../Documentation/LinqToJsonTests.cs | 2 + .../Documentation/PerformanceTests.cs | 40 ++-------- .../ReadingAndWritingJsonTests.cs | 4 + .../Documentation/SerializationTests.cs | 17 +++- Src/Newtonsoft.Json.Tests/JsonConvertTest.cs | 7 +- Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs | 4 +- .../Newtonsoft.Json.Tests.csproj | 80 +++++++++---------- .../Serialization/JsonSerializerTest.cs | 1 + .../PreserveReferencesHandlingTests.cs | 1 + 11 files changed, 87 insertions(+), 125 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs index 31406eb8..95fa88f9 100644 --- a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs +++ b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs @@ -69,52 +69,6 @@ namespace Newtonsoft.Json.Tests.Bson Assert.AreEqual("1", (string)o["$id"]); } - 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() { @@ -1396,6 +1350,7 @@ namespace Newtonsoft.Json.Tests.Bson Assert.AreEqual(JsonToken.EndObject, reader.TokenType); } + [Test] public void UriGuidTimeSpanTestClassEmptyTest() { UriGuidTimeSpanTestClass c1 = new UriGuidTimeSpanTestClass(); @@ -1417,6 +1372,7 @@ namespace Newtonsoft.Json.Tests.Bson Assert.AreEqual(c1.Uri, c2.Uri); } + [Test] public void UriGuidTimeSpanTestClassValuesTest() { UriGuidTimeSpanTestClass c1 = new UriGuidTimeSpanTestClass @@ -1473,10 +1429,11 @@ namespace Newtonsoft.Json.Tests.Bson CollectionAssert.AreEquivalent(new byte[] { 72, 63, 62, 71, 92, 55 }, newObject.Data); } } - + + [Test] public void Utf8Text() { - string badText = System.IO.File.ReadAllText(@"PoisonText.txt"); + string badText = System.IO.File.ReadAllText(TestFixtureBase.ResolvePath(@"PoisonText.txt")); var j = new JObject(); j["test"] = badText; diff --git a/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs index 0c35d190..bce4d0b7 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs @@ -42,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Converters [TestFixture] public class CustomCreationConverterTests : TestFixtureBase { + [Test] public void DeserializeObject() { string json = JsonConvert.SerializeObject(new List @@ -85,7 +86,7 @@ namespace Newtonsoft.Json.Tests.Converters IPerson person = people[0]; - Assert.AreEqual("Newtonsoft.Json.Tests.Employee", person.GetType().Name); + Assert.AreEqual("Employee", person.GetType().Name); Assert.AreEqual("Maurice", person.FirstName); diff --git a/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs b/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs index 6314f377..c9465548 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/LinqToJsonTests.cs @@ -75,6 +75,7 @@ namespace Newtonsoft.Json.Tests.Documentation [TestFixture] public class LinqToJsonTests : TestFixtureBase { + [Test] public void LinqToJsonBasic() { #region LinqToJsonBasic @@ -98,6 +99,7 @@ namespace Newtonsoft.Json.Tests.Documentation #endregion } + [Test] public void LinqToJsonCreateNormal() { #region LinqToJsonCreateNormal diff --git a/Src/Newtonsoft.Json.Tests/Documentation/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/Documentation/PerformanceTests.cs index f3aed861..428bc2e9 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/PerformanceTests.cs @@ -105,7 +105,14 @@ namespace Newtonsoft.Json.Tests.Documentation public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - return null; + JObject o = (JObject)JToken.ReadFrom(reader); + + Person p = new Person + { + Name = (string)o["Name"] + }; + + return p; } public override bool CanConvert(Type objectType) @@ -127,37 +134,6 @@ namespace Newtonsoft.Json.Tests.Documentation Console.WriteLine(json); } - - public void DeserializeString() - { - #region DeserializeString - HttpClient client = new HttpClient(); - - // read the json into a string - // string could potentially be very large and cause memory problems - string json = client.GetStringAsync("http://www.test.com/large.json").Result; - - Person p = JsonConvert.DeserializeObject(json); - #endregion - } - - public void DeserializeStream() - { - #region DeserializeStream - HttpClient client = new HttpClient(); - - using (Stream s = client.GetStreamAsync("http://www.test.com/large.json").Result) - using (StreamReader sr = new StreamReader(s)) - using (JsonReader reader = new JsonTextReader(sr)) - { - JsonSerializer serializer = new JsonSerializer(); - - // read the json from a stream - // json size doesn't matter because only a small piece is read at a time from the HTTP request - Person p = serializer.Deserialize(reader); - } - #endregion - } } public static class PersonWriter diff --git a/Src/Newtonsoft.Json.Tests/Documentation/ReadingAndWritingJsonTests.cs b/Src/Newtonsoft.Json.Tests/Documentation/ReadingAndWritingJsonTests.cs index ddf4a1cb..a1d95a4e 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/ReadingAndWritingJsonTests.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/ReadingAndWritingJsonTests.cs @@ -52,6 +52,7 @@ namespace Newtonsoft.Json.Tests.Documentation [TestFixture] public class ReadingAndWritingJsonTests : TestFixtureBase { + [Test] public void ReadingAndWritingJsonText() { #region ReadingAndWritingJsonText @@ -134,6 +135,7 @@ namespace Newtonsoft.Json.Tests.Documentation #endregion } + [Test] public void ReadingAndWritingJsonLinq() { #region ReadingAndWritingJsonLinq @@ -148,6 +150,8 @@ namespace Newtonsoft.Json.Tests.Documentation Console.WriteLine(p.Name); // John Smith #endregion + + Assert.AreEqual("John Smith", p.Name); } } } diff --git a/Src/Newtonsoft.Json.Tests/Documentation/SerializationTests.cs b/Src/Newtonsoft.Json.Tests/Documentation/SerializationTests.cs index 9634f7df..942be054 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/SerializationTests.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/SerializationTests.cs @@ -46,12 +46,21 @@ using Newtonsoft.Json.Tests.TestObjects; using Newtonsoft.Json.Utilities; using System.Globalization; using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs; +using OriginalStreamWriter = System.IO.StreamWriter; +using StreamWriter = Newtonsoft.Json.Tests.Documentation.SerializationTests.StreamWriter; namespace Newtonsoft.Json.Tests.Documentation { [TestFixture] public class SerializationTests : TestFixtureBase { + public class StreamWriter : OriginalStreamWriter + { + public StreamWriter(string path) : base(TestFixtureBase.ResolvePath(Path.GetFileName(path))) + { + } + } + [Test] public void SerializeObject() { @@ -81,6 +90,7 @@ namespace Newtonsoft.Json.Tests.Documentation Assert.AreEqual("Apple", deserializedProduct.Name); } + [Test] public void JsonSerializerToStream() { #region JsonSerializerToStream @@ -114,7 +124,6 @@ namespace Newtonsoft.Json.Tests.Documentation // new Date(976918263055) [JsonProperty] - [JsonConverter(typeof(JavaScriptDateTimeConverter))] public DateTime LastModified { get; set; } // not serialized because mode is opt-in @@ -338,6 +347,7 @@ namespace Newtonsoft.Json.Tests.Documentation }", json); } + [Test] public void PreservingObjectReferencesOff() { #region PreservingObjectReferencesOff @@ -679,6 +689,7 @@ namespace Newtonsoft.Json.Tests.Documentation public DateTime LogDate { get; set; } } + [Test] public void WriteJsonDates() { LogEntry entry = new LogEntry @@ -814,6 +825,7 @@ namespace Newtonsoft.Json.Tests.Documentation } #endregion + [Test] public void ReducingSerializedJsonSizeDefaultValueHandlingExample() { #region ReducingSerializedJsonSizeDefaultValueHandlingExample @@ -862,7 +874,7 @@ namespace Newtonsoft.Json.Tests.Documentation Assert.AreEqual(@"{ ""Company"": ""Acme Ltd."", ""Amount"": 50.0 -}", included); +}", ignored); } #region ReducingSerializedJsonSizeContractResolverObject @@ -897,6 +909,7 @@ namespace Newtonsoft.Json.Tests.Documentation } #endregion + [Test] public void ReducingSerializedJsonSizeContractResolverExample() { #region ReducingSerializedJsonSizeContractResolverExample diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index dda3d1d0..8862c975 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -1137,7 +1137,12 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual(typeof(DateTime), jsonReader.ValueType); } - //[Test] +#if DNXCORE50 + [Test(Skip = "Don't run with other unit tests")] +#else + [Ignore("Don't run with other unit tests")] + [Test] +#endif public void StackOverflowTest() { StringBuilder sb = new StringBuilder(); diff --git a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs index 4586fec4..57add05e 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs @@ -469,6 +469,7 @@ namespace Newtonsoft.Json.Tests.Linq o.Property("DateTimeOffset").Value = dateTimeOffset; } + [Test] public void ParseAndConvertDateTimeOffset() { var json = @"{ d: ""\/Date(0+0100)\/"" }"; @@ -490,6 +491,7 @@ namespace Newtonsoft.Json.Tests.Linq } } + [Test] public void ReadDatesAsDateTimeOffsetViaJsonConvert() { var content = @"{""startDateTime"":""2012-07-19T14:30:00+09:30""}"; @@ -499,7 +501,7 @@ namespace Newtonsoft.Json.Tests.Linq object startDateTime = obj["startDateTime"]; - CustomAssert.IsInstanceOfType(typeof(DateTimeOffset), startDateTime); + CustomAssert.IsInstanceOfType(typeof(DateTimeOffset), ((JValue)startDateTime).Value); } #endif diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index eaa229b4..7f212cfd 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -46,14 +46,14 @@ - - - - + + + + - + - + @@ -69,13 +69,13 @@ - - - + + + - + - + @@ -91,13 +91,13 @@ - - - + + + - + - + @@ -113,9 +113,9 @@ - - - + + + @@ -130,8 +130,8 @@ - - + + @@ -145,8 +145,8 @@ - - + + @@ -155,18 +155,18 @@ - + - - - - - + + + + + Json.NET Tests .NET Standard 2.0 @@ -175,18 +175,18 @@ - + - - - - - + + + + + Json.NET Tests .NET Standard 1.3 @@ -201,11 +201,11 @@ - - - - - + + + + + Json.NET Tests .NET Standard 1.0 diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index b2b066b4..7ae239a9 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -2871,6 +2871,7 @@ keyword such as type of business."" Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":new Date(1234656000000)}", javascriptJson); } + [Test] public void GenericListAndDictionaryInterfaceProperties() { GenericListAndDictionaryInterfaceProperties o = new GenericListAndDictionaryInterfaceProperties(); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs index ddbdee57..9bd80634 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs @@ -165,6 +165,7 @@ namespace Newtonsoft.Json.Tests.Serialization public string PropertyName { get; set; } } + [Test] public void SerializeReadOnlyProperty() { Child c = new Child