From e355d761a5930b86213c7d60f7f72a04fdc5d048 Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Wed, 26 Feb 2020 16:01:33 -0600 Subject: [PATCH] Add serializer tests for value types --- .../micro/Serializers/DataGenerator.cs | 34 +++++++++++++++++-- .../System.Text.Json/Serializer/ReadJson.cs | 3 ++ .../System.Text.Json/Serializer/WriteJson.cs | 3 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/benchmarks/micro/Serializers/DataGenerator.cs b/src/benchmarks/micro/Serializers/DataGenerator.cs index 33bf8adb1e2..70ecede8b7c 100644 --- a/src/benchmarks/micro/Serializers/DataGenerator.cs +++ b/src/benchmarks/micro/Serializers/DataGenerator.cs @@ -51,7 +51,10 @@ internal static T Generate() return (T)(object)new ArrayList(ValuesGenerator.ArrayOfUniqueValues(100)); if (typeof(T) == typeof(Hashtable)) return (T)(object)new Hashtable(ValuesGenerator.ArrayOfUniqueValues(100).ToDictionary(value => value)); - + if (typeof(T) == typeof(LargeStructWithProperties)) + return (T)(object)CreateLargeStructWithProperties(); + if (typeof(T) == typeof(int)) + return (T)(object)42; throw new NotImplementedException(); } @@ -106,6 +109,16 @@ private static IndexViewModel CreateIndexViewModel() count: 20).ToList() }; + private static LargeStructWithProperties CreateLargeStructWithProperties() + => new LargeStructWithProperties + { + String1 = "1", + String2 = "2", + String3 = "3", + String4 = "4", + String5 = "5", + }; + private static MyEventsListerViewModel CreateMyEventsListerViewModel() => new MyEventsListerViewModel { @@ -357,7 +370,24 @@ public class CollectionsOfPrimitives [ProtoMember(4)] [Key(3)] public List ListOfInt { get; set; } } - + + [Serializable] + [ProtoContract] + [MessagePackObject] + public struct LargeStructWithProperties + { + [ProtoMember(1)] [Key(0)] public string String1 { get; set; } + [ProtoMember(2)] [Key(1)] public string String2 { get; set; } + [ProtoMember(3)] [Key(2)] public string String3 { get; set; } + [ProtoMember(4)] [Key(3)] public string String4 { get; set; } + [ProtoMember(5)] [Key(4)] public string String5 { get; set; } + [ProtoMember(6)] [Key(5)] public int Int1 { get; set; } + [ProtoMember(7)] [Key(6)] public int Int2 { get; set; } + [ProtoMember(8)] [Key(7)] public int Int3 { get; set; } + [ProtoMember(9)] [Key(8)] public int Int4 { get; set; } + [ProtoMember(10)] [Key(9)] public int Int5 { get; set; } + } + public struct SimpleStructWithProperties { public int Num { get; set; } diff --git a/src/benchmarks/micro/libraries/System.Text.Json/Serializer/ReadJson.cs b/src/benchmarks/micro/libraries/System.Text.Json/Serializer/ReadJson.cs index 144d5e48356..db28e852ead 100644 --- a/src/benchmarks/micro/libraries/System.Text.Json/Serializer/ReadJson.cs +++ b/src/benchmarks/micro/libraries/System.Text.Json/Serializer/ReadJson.cs @@ -24,6 +24,9 @@ namespace System.Text.Json.Serialization.Tests [GenericTypeArguments(typeof(HashSet))] [GenericTypeArguments(typeof(ArrayList))] [GenericTypeArguments(typeof(Hashtable))] + [GenericTypeArguments(typeof(SimpleStructWithProperties))] + [GenericTypeArguments(typeof(LargeStructWithProperties))] + [GenericTypeArguments(typeof(int))] public class ReadJson { private string _serialized; diff --git a/src/benchmarks/micro/libraries/System.Text.Json/Serializer/WriteJson.cs b/src/benchmarks/micro/libraries/System.Text.Json/Serializer/WriteJson.cs index e4b15c9d770..4a06f196255 100644 --- a/src/benchmarks/micro/libraries/System.Text.Json/Serializer/WriteJson.cs +++ b/src/benchmarks/micro/libraries/System.Text.Json/Serializer/WriteJson.cs @@ -24,6 +24,9 @@ namespace System.Text.Json.Serialization.Tests [GenericTypeArguments(typeof(HashSet))] [GenericTypeArguments(typeof(ArrayList))] [GenericTypeArguments(typeof(Hashtable))] + [GenericTypeArguments(typeof(SimpleStructWithProperties))] + [GenericTypeArguments(typeof(LargeStructWithProperties))] + [GenericTypeArguments(typeof(int))] public class WriteJson { private T _value;