Run unit tests on .NET Core 3.0 and fix Enumerable.Empty (#2137)

This commit is contained in:
James Newton-King
2019-08-19 12:57:09 +12:00
committed by GitHub
parent 083aa6df83
commit 5eac02a797
22 changed files with 300 additions and 81 deletions
@@ -164,7 +164,11 @@ namespace Newtonsoft.Json.Tests.Serialization
{
Dictionary<float, int> dictionary = new Dictionary<float, int> { { float.MaxValue, 1 } };
string output = JsonConvert.SerializeObject(dictionary);
#if !NETSTANDARD2_0
Assert.AreEqual(@"{""3.40282347E+38"":1}", output);
#else
Assert.AreEqual(@"{""3.4028235E+38"":1}", output);
#endif
Dictionary<float, int> deserializedValue = JsonConvert.DeserializeObject<Dictionary<float, int>>(output);
Assert.AreEqual(float.MaxValue, deserializedValue.First().Key);
@@ -2108,6 +2112,26 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
[Test]
public void DeserializeEmptyEnumerable_NoItems()
{
ValuesClass c = JsonConvert.DeserializeObject<ValuesClass>(@"{""Values"":[]}");
Assert.AreEqual(0, c.Values.Count());
}
[Test]
public void DeserializeEmptyEnumerable_HasItems()
{
ValuesClass c = JsonConvert.DeserializeObject<ValuesClass>(@"{""Values"":[""hello""]}");
Assert.AreEqual(1, c.Values.Count());
Assert.AreEqual("hello", c.Values.ElementAt(0));
}
public class ValuesClass
{
public IEnumerable<string> Values { get; set; } = Enumerable.Empty<string>();
}
[Test]
public void DeserializeConstructorWithReadonlyArrayProperty()
{