示例#1
0
        public void Should_query_primitive_value_injected_as_variable_closure(Type type, object value)
        {
            Skip.If(this.TestIs <With_xml_serializer>() && type.Is <DateTimeOffset>(), $"{type} not supported by With_xml_serializer");
            Skip.If(this.TestIs <With_xml_serializer>() && type.Is <TimeSpan>(), $"{type} not supported by With_xml_serializer");
            Skip.If(this.TestIs <With_xml_serializer>() && type.Is <BigInteger>(), $"{type} not supported by With_xml_serializer");
            Skip.If(this.TestIs <With_xml_serializer>() && type.Is <Complex>(), $"{type} not supported by With_xml_serializer");

            if (this.TestIs <With_protobuf_net_serializer>())
            {
                ProtobufNetSerializationHelper.SkipUnsupportedDataType(type, value);
            }

            if (this.TestIs <With_system_text_json_serializer>())
            {
                SystemTextJsonSerializationHelper.SkipUnsupportedDataType(type, value);
            }

#if NET5_0_OR_GREATER
            Skip.If(type.Is <Half>(), $"{type} not supported by serializers");
#endif // NET5_0_OR_GREATER

            RunTestMethod(
                nameof(TestMethodFor_Should_query_primitive_value_injected_as_variable_closure),
                type,
                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_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}");
        }