Esempio n. 1
0
        public void When_serializing_method_call_expression_with_parameter_and_variable_argument_B()
        {
            var m = typeof(Math).GetMethod(nameof(Math.Pow), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
            var v = System.Linq.Expressions.Expression.Constant(new VariableQueryArgument(2.0, typeof(double)));
            var b = System.Linq.Expressions.Expression.Convert(
                System.Linq.Expressions.Expression.MakeMemberAccess(v, typeof(VariableQueryArgument).GetProperty(nameof(VariableQueryArgument.Value))),
                typeof(double));
            var pExp             = System.Linq.Expressions.Expression.Parameter(typeof(double), "exp");
            var c                = System.Linq.Expressions.Expression.Call(m, b, pExp);
            var l                = System.Linq.Expressions.Expression.Lambda(c, pExp);
            var r                = (double)l.Compile().DynamicInvoke(8);
            var remoteExpression = l.ToRemoteLinqExpression();

            // throws on deep clone
            Should.Throw <ProtoException>(remoteExpression.Serialize);

            var config = ProtoBufTypeModel.ConfigureRemoteLinq().Model;

            using var memorystream = new MemoryStream();

            // while serialization seems fine ...
            config.Serialize(memorystream, remoteExpression);

            memorystream.Position = 0;
            var schema = config.GetSchema(remoteExpression.GetType(), ProtoSyntax.Proto3);

            // ... actually throws on deserialize.
            Should.Throw <ProtoException>(() => config.Deserialize(memorystream, null, remoteExpression.GetType()));
        }
Esempio n. 2
0
        public void Should_serialize_property(Type type, object value)
        {
            SkipUnsupportedDataType(type, value);

            var property = new Property("p1", value);

            var config = ProtoBufTypeModel.ConfigureRemoteLinq(configureDefaultSystemTypes: false)
                         .AddDynamicPropertyType(TypeHelper.GetElementType(type) ?? type)
                         .Compile();
            var copy = property.Serialize(config);

            copy.Value.ShouldBe(value);
        }
Esempio n. 3
0
        private static TypeModel CreateTypeModel()
        {
            var configuration = ProtoBufTypeModel.ConfigureRemoteLinq();

            var testdatatypes = TestData.TestTypes
                                .Select(x => (Type)x[0])
                                .Select(x => x.AsNonNullableType())
                                .Distinct()
                                .ToArray();

            testdatatypes.ForEach(x => configuration.AddDynamicPropertyType(x));

            return(configuration);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public static TypeModel CreateModelFor(Type type)
        {
            if (type.IsCollection())
            {
                type = TypeHelper.GetElementType(type);
            }

            if (type.IsEnum)
            {
                type = typeof(string);
            }

            return(ProtoBufTypeModel.ConfigureRemoteLinq()
                   .AddDynamicPropertyType(type)
                   .Compile());
        }
        public void Should_serialize_property_set_2(Type type, object value)
        {
            SkipUnsupportedDataType(type, value);

            var propertySet = new PropertySet
            {
                { "p1", value },
            };

            var config = ProtoBufTypeModel.ConfigureRemoteLinq(configureDefaultSystemTypes: false)
                         .AddDynamicPropertyType(TypeHelper.GetElementType(type))
                         .Compile();
            var copy = propertySet.Clone(config);

            copy["p1"].ShouldBe(value);
        }
Esempio n. 7
0
        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);
        }