Skip to content

Commit

Permalink
Add serializer tests for value types (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveharter committed Feb 27, 2020
1 parent 4e8f103 commit 8e40c12
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/benchmarks/micro/Serializers/DataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ internal static T Generate<T>()
return (T)(object)new ArrayList(ValuesGenerator.ArrayOfUniqueValues<string>(100));
if (typeof(T) == typeof(Hashtable))
return (T)(object)new Hashtable(ValuesGenerator.ArrayOfUniqueValues<string>(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();
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -357,7 +370,24 @@ public class CollectionsOfPrimitives

[ProtoMember(4)] [Key(3)] public List<int> 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace System.Text.Json.Serialization.Tests
[GenericTypeArguments(typeof(HashSet<string>))]
[GenericTypeArguments(typeof(ArrayList))]
[GenericTypeArguments(typeof(Hashtable))]
[GenericTypeArguments(typeof(SimpleStructWithProperties))]
[GenericTypeArguments(typeof(LargeStructWithProperties))]
[GenericTypeArguments(typeof(int))]
public class ReadJson<T>
{
private string _serialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace System.Text.Json.Serialization.Tests
[GenericTypeArguments(typeof(HashSet<string>))]
[GenericTypeArguments(typeof(ArrayList))]
[GenericTypeArguments(typeof(Hashtable))]
[GenericTypeArguments(typeof(SimpleStructWithProperties))]
[GenericTypeArguments(typeof(LargeStructWithProperties))]
[GenericTypeArguments(typeof(int))]
public class WriteJson<T>
{
private T _value;
Expand Down

0 comments on commit 8e40c12

Please sign in to comment.