public void DeserializeWithConfigurationUsesConfiguration()
        {
            var expr         = 42.AsConstantExpression();
            var serialized   = QueryExprSerializer.Serialize(expr);
            var deserialized = QueryExprSerializer.Deserialize(
                serialized,
                null,
                config => config.CompressExpressionTree(false),
                null);

            Assert.NotNull(deserialized);
        }
        public void HandlesElementInits()
        {
            Expression <Func <DataHost> > elemInit = () => new DataHost {
                Elems = { new DataElem() }
            };
            var root             = QueryExprSerializer.Serialize(elemInit, config => config.CompressExpressionTree(false));
            var json             = wrapper.FromSerializationRoot(root);
            var deserializedRoot = wrapper.ToSerializationRoot(json);

            QueryExprSerializer.ConfigureRules(rules => rules.RuleForType <DataHost>()
                                               .RuleForType <DataElem>());
            var deserializedExpr = QueryExprSerializer.Deserialize <LambdaExpression>(deserializedRoot);

            Assert.True(elemInit.IsEquivalentTo(deserializedExpr));
        }
        public void HandlesInterfaces()
        {
            var expr = Expression.Constant(new IdContainer
            {
                Id   = Guid.NewGuid().ToString(),
                Name = nameof(IdContainer),
            }, typeof(IHaveId));
            var root             = QueryExprSerializer.Serialize(expr, config => config.CompressExpressionTree(false));
            var json             = wrapper.FromSerializationRoot(root);
            var deserializedRoot = wrapper.ToSerializationRoot(json);
            var deserializedExpr = QueryExprSerializer.Deserialize <ConstantExpression>(deserializedRoot);

            Assert.Equal(typeof(IHaveId), deserializedExpr.Type);
            Assert.True(deserializedExpr.Value is IdContainer);
            Assert.Equal(nameof(IdContainer), ((IdContainer)deserializedExpr.Value).Name);
        }
        public void HandlesNullAnonymousTypes()
        {
            var expected = new
            {
                Id      = 1,
                SubAnon = default(object)
            };

            var expr             = expected.AsConstantExpression();
            var root             = QueryExprSerializer.Serialize(expr);
            var json             = wrapper.FromSerializationRoot(root);
            var deserializedRoot = wrapper.ToSerializationRoot(json);
            var deserializedExpr = QueryExprSerializer.Deserialize <ConstantExpression>(deserializedRoot);

            Assert.True(expressionEvaluator.Value.AnonymousValuesAreEquivalent(expr.Value, deserializedExpr.Value));
        }
        public void SerializesAndDeserializesAnonymousTypes()
        {
            var expected = new
            {
                Id      = 1,
                SubAnon = new
                {
                    Id  = 2,
                    Two = 2.ToString()
                }
            };

            var expr             = expected.AsConstantExpression();
            var root             = QueryExprSerializer.Serialize(expr);
            var json             = wrapper.FromSerializationRoot(root);
            var deserializedRoot = wrapper.ToSerializationRoot(json);
            var deserializedExpr = QueryExprSerializer.Deserialize <ConstantExpression>(deserializedRoot);

            Assert.True(expressionEvaluator.Value.AnonymousValuesAreEquivalent(expr.Value, deserializedExpr.Value));
        }