@@ -72,12 +72,12 @@ public void Should_roundtrip_serialize_int_based_enum_having_formatter()
72
72
}
73
73
74
74
public static IEnumerable < object [ ] > DataForValueObject => new [ ]
75
- {
76
- new object [ ] { new ClassWithIntBasedEnum ( IntegerEnum . Item1 ) } ,
77
- new object [ ] { new ClassWithStringBasedEnum ( TestEnum . Item1 ) } ,
78
- new object [ ] { TestEnum . Item1 } ,
79
- new object [ ] { IntegerEnum . Item1 }
80
- } ;
75
+ {
76
+ new object [ ] { new ClassWithIntBasedEnum ( IntegerEnum . Item1 ) } ,
77
+ new object [ ] { new ClassWithStringBasedEnum ( TestEnum . Item1 ) } ,
78
+ new object [ ] { TestEnum . Item1 } ,
79
+ new object [ ] { IntegerEnum . Item1 }
80
+ } ;
81
81
82
82
[ Theory ]
83
83
[ MemberData ( nameof ( DataForValueObject ) ) ]
@@ -95,15 +95,15 @@ private void RoundTripSerializeWithCustomOptions<T>(T value)
95
95
}
96
96
97
97
public static IEnumerable < object [ ] > DataForValueObjectWithMultipleProperties => new [ ]
98
- {
99
- new object [ ] { null } ,
100
- new object [ ] { ValueObjectWithMultipleProperties . Create ( 0 , null , null ! ) } ,
101
- new object [ ] { ValueObjectWithMultipleProperties . Create ( 0 , null , null ! ) } ,
102
- new object [ ] { ValueObjectWithMultipleProperties . Create ( 0 , 0 , String . Empty ) } ,
103
- new object [ ] { ValueObjectWithMultipleProperties . Create ( 1 , 42 , "Value" ) } ,
104
- new object [ ] { ValueObjectWithMultipleProperties . Create ( 1 , 42 , "Value" ) } ,
105
- new object [ ] { ValueObjectWithMultipleProperties . Create ( 1 , 42 , "Value" ) }
106
- } ;
98
+ {
99
+ new object [ ] { null } ,
100
+ new object [ ] { ValueObjectWithMultipleProperties . Create ( 0 , null , null ! ) } ,
101
+ new object [ ] { ValueObjectWithMultipleProperties . Create ( 0 , null , null ! ) } ,
102
+ new object [ ] { ValueObjectWithMultipleProperties . Create ( 0 , 0 , String . Empty ) } ,
103
+ new object [ ] { ValueObjectWithMultipleProperties . Create ( 1 , 42 , "Value" ) } ,
104
+ new object [ ] { ValueObjectWithMultipleProperties . Create ( 1 , 42 , "Value" ) } ,
105
+ new object [ ] { ValueObjectWithMultipleProperties . Create ( 1 , 42 , "Value" ) }
106
+ } ;
107
107
108
108
[ Theory ]
109
109
[ MemberData ( nameof ( DataForValueObjectWithMultipleProperties ) ) ]
@@ -182,4 +182,59 @@ public void Should_deserialize_complex_value_object_having_custom_factory()
182
182
183
183
value . Should ( ) . BeEquivalentTo ( BoundaryWithCustomFactoryNames . Get ( 1 , 2 ) ) ;
184
184
}
185
+
186
+ public static IEnumerable < object [ ] > ObjectWithStructTestData =
187
+ [
188
+ [ new TestClass < IntBasedStructValueObject > ( IntBasedStructValueObject . Create ( 42 ) ) ] ,
189
+ [ new TestClass < IntBasedStructValueObject ? > ( IntBasedStructValueObject . Create ( 42 ) ) ] ,
190
+ [ new TestClass < IntBasedReferenceValueObject > ( IntBasedReferenceValueObject . Create ( 42 ) ) ] ,
191
+ [ new TestStruct < IntBasedStructValueObject > ( IntBasedStructValueObject . Create ( 42 ) ) ] ,
192
+ [ new TestStruct < IntBasedStructValueObject ? > ( IntBasedStructValueObject . Create ( 42 ) ) ] ,
193
+ [ new TestStruct < IntBasedReferenceValueObject > ( IntBasedReferenceValueObject . Create ( 42 ) ) ] ,
194
+ ] ;
195
+
196
+ [ Theory ]
197
+ [ MemberData ( nameof ( ObjectWithStructTestData ) ) ]
198
+ public void Should_roundtrip_serialize_types_with_struct_properties_using_resolver ( object obj )
199
+ {
200
+ Roundtrip_serialize_types_with_struct_properties_using_resolver ( true , obj ) ;
201
+ Roundtrip_serialize_types_with_struct_properties_using_resolver ( false , obj ) ;
202
+ }
203
+
204
+ private static void Roundtrip_serialize_types_with_struct_properties_using_resolver (
205
+ bool skipValueObjectsWithMessagePackFormatter ,
206
+ object obj )
207
+ {
208
+ var resolver = CompositeResolver . Create ( new ValueObjectMessageFormatterResolver ( skipValueObjectsWithMessagePackFormatter ) , StandardResolver . Instance ) ;
209
+ var options = MessagePackSerializerOptions . Standard . WithResolver ( resolver ) ;
210
+
211
+ var bytes = MessagePackSerializer . Serialize ( obj , options , CancellationToken . None ) ;
212
+ var value = MessagePackSerializer . Deserialize ( obj . GetType ( ) , bytes , options , CancellationToken . None ) ;
213
+
214
+ value . Should ( ) . BeEquivalentTo ( obj ) ;
215
+ }
216
+
217
+ [ MessagePackObject ]
218
+ public struct TestClass < T >
219
+ {
220
+ [ Key ( 0 ) ]
221
+ public T Prop { get ; set ; }
222
+
223
+ public TestClass ( T prop )
224
+ {
225
+ Prop = prop ;
226
+ }
227
+ }
228
+
229
+ [ MessagePackObject ]
230
+ public struct TestStruct < T >
231
+ {
232
+ [ Key ( 0 ) ]
233
+ public T Prop { get ; set ; }
234
+
235
+ public TestStruct ( T prop )
236
+ {
237
+ Prop = prop ;
238
+ }
239
+ }
185
240
}
0 commit comments