public void Should_serialize_value_as_property_when_using_string_formatting(Type type, object value, CultureInfo culture) { using var cultureContext = culture.CreateContext(); var result = SerializeAsPropertyMethod.MakeGenericMethod(type).Invoke(this, new[] { value, true, true }); result.ShouldBe(value, $"type: {type.FullName} ({value})"); }
public void Should_serialize_value(Type type, object value, CultureInfo culture) { using var cultureContext = culture.CreateContext(); var result = SerializeMethod.MakeGenericMethod(type).Invoke(this, new[] { value, true, false }); result.ShouldBe(value, $"type: {type.FullName}"); }
public void Should_serialize_value_as_property_when_using_string_formatting(Type type, object value, CultureInfo culture) { Skip.If(this.TestIs <XmlSerializer>() && type.Is <char>(), "Only characters which are valid in xml may be supported by XmlSerializer."); using var cultureContext = culture.CreateContext(); var result = SerializeAsProperty(type, value, true, true); result.ShouldBe(value, $"type: {type.FullName} ({value})"); }
public void Should_serialize_collection_property(Type type, object value, CultureInfo culture) { SkipUnsupportedDataType(type, value); using var cultureContext = culture.CreateContext(); var property = new Property("p1", value); var model = ProtoBufTypeModel.ConfigureAquaTypes(configureDefaultSystemTypes: false) .AddDynamicPropertyType(TypeHelper.GetElementType(type), addSingleValueSuppoort: false, addNullableSupport: type.IsNullableType()) .Compile(); var copy = property.Serialize(model); copy.Value.ShouldBe(value); }
public void Should_serialize_value_when_using_string_formatting(Type type, object value, CultureInfo culture) { if (this.TestIs <ProtobufNetSerializer>()) { ProtobufNetSerializationHelper.SkipUnsupportedDataType(type, value); } Skip.If(this.TestIs <XmlSerializer>() && type.Is <char>(), "Only characters which are valid in xml may be supported by XmlSerializer."); using var cultureContext = culture.CreateContext(); var result = Serialize(type, value, true, true); result.ShouldBe(value, $"type: {type.FullName}"); }
public void Should_serialize_dynamic_object(Type type, object value, CultureInfo culture) { SkipUnsupportedDataType(type, value); using var cultureContext = culture.CreateContext(); var dynamicObject = new DynamicObjectMapper().MapObject(value); var copy = dynamicObject.Serialize(); copy?.Get().ShouldBe(dynamicObject?.Get(), $"type: {type} value: {value}"); var c = new DynamicObjectMapper().Map(copy); c.ShouldBe(value); }
public void Should_serialize_value_as_property(Type type, object value, CultureInfo culture) { if (this.TestIs <ProtobufNetSerializer>()) { ProtobufNetSerializationHelper.SkipUnsupportedDataType(type, value); } #if NET5_0 Skip.If(type.Is <Half>(), "Half type serialization is not supported."); #endif // NET5_0 Skip.If(this.TestIs <XmlSerializer>(), "XmlSerializer has limited type support."); using var cultureContext = culture.CreateContext(); var result = SerializeAsProperty(type, value, true, false); result.ShouldBe(value, $"type: {type.FullName}"); }
public void Should_serialize_property_set(Type type, object value, CultureInfo culture) { SkipUnsupportedDataType(type, value); using var cultureContext = culture.CreateContext(); var propertySet = new PropertySet { { "p1", value }, }; var config = ProtoBufTypeModel.ConfigureAquaTypes(configureDefaultSystemTypes: false) .AddDynamicPropertyType(TypeHelper.GetElementType(type) ?? type) .Compile(); var copy = propertySet.Serialize(config); copy["p1"].ShouldBe(value); }
public void Should_map_native_value_property(Type type, object value, CultureInfo culture) { using var cultureContext = culture.CreateContext(); var result = MapAsPropertyMethod.MakeGenericMethod(type).Invoke(null, new[] { value }); if (result is null) { if (type.IsValueType) { var message = $"value must not be null for type {type}"; type.IsGenericType.ShouldBeTrue(message); type.GetGenericTypeDefinition().ShouldBe(typeof(Nullable <>), message); } } else { result.ShouldBeAssignableTo(type); } result.ShouldBe(value); }
public void Should_serialize_dynamic_object_collection(Type type, IEnumerable value, CultureInfo culture) { SkipUnsupportedDataType(type, value); using var cultureContext = culture.CreateContext(); var dynamicObjects = new DynamicObjectMapper().MapCollection(value); var copy = dynamicObjects.Serialize(); var dynamicObjectsCount = dynamicObjects?.Count() ?? 0; var copyCount = copy?.Count() ?? 0; copyCount.ShouldBe(dynamicObjectsCount); for (int i = 0; i < copyCount; i++) { var originalValue = dynamicObjects.ElementAt(i)?.Get(); var copyValue = copy.ElementAt(i)?.Get(); copyValue.ShouldBe(originalValue); } var c = new DynamicObjectMapper().Map(copy); if (value is null) { c.ShouldBeNull(); } else { var array = value.Cast <object>().ToArray(); var copyArray = c.Cast <object>().ToArray(); for (int i = 0; i < copyArray.Length; i++) { copyArray[i].ShouldBe(array[i]); } } }