public void FieldWrapperIsSerializable()
        {
            var prop = typeof(Sample).GetField("TestField").ToSettable();

            var result = SimpleSerializer.Binary().RoundTrip(prop);

            result.Name.Should().Be.Equals(prop.Name);
        }
Example #2
0
        public void ShouldBeSerializable()
        {
            var expr = ExprTyped(x => x.TestProp).ToSettable();

            var expr2 = SimpleSerializer.Binary().RoundTrip(expr);

            expr2.Expression.ToString().Should().Be(expr.Expression.ToString());
        }
        public void TestItInternal <T, TRet>(Expression <T> expr, Func <T, TRet> howToCall)
        {
            TestItInternalInternal <T, TRet>(expr, howToCall,
                                             SimpleSerializer.Binary());

            TestItInternalInternal <T, TRet>(expr, howToCall,
                                             SimpleSerializer.NetDataContract());
        }
        public void TestMethodSerialization()
        {
            var method  = typeof(Queryable).GetMember("Where").OfType <MethodInfo>().Where(x => x.GetParameters().Length == 2).First();
            var bytes   = SimpleSerializer.Binary().Serialize(method);
            var method2 = (MethodInfo)SimpleSerializer.Binary().Deserialize(bytes);

            method2.Should().Be(method);
        }
        public void TestTypeSerialization()
        {
            var type  = typeof(Expression <Func <int, bool> >);
            var bytes = SimpleSerializer.Binary().Serialize(type);
            var type2 = (Type)SimpleSerializer.Binary().Deserialize(bytes);

            type2.Should().Be(type);
        }
Example #6
0
        public void WhenTheValueIsNullItDoesntSerializeTheProxy()
        {
            var serializable    = new SerializeAsString(null);
            var newSerializable = SimpleSerializer.Binary().RoundTrip(serializable);

            newSerializable.IsProxyActivated.Should().Be.False();
            newSerializable.IsRealActivated.Should().Be.False();
            newSerializable.Real.Should().Be.Null();
            newSerializable.IsRealActivated.Should().Be.True();
        }
        public void TestGeneratedQuoteSerialization()
        {
            Expression <Func <int, int> > original = x => x * 2;
            var expr1 = EditableExpression.Create(Expression.Quote(original));

            var bytes = SimpleSerializer.Binary().Serialize(expr1);
            var expr2 = (EditableExpression)SimpleSerializer.Binary().Deserialize(bytes);

            expr2.Should().Not.Be.Null();
        }
        public void TestSerializeLambda()
        {
            var ser = SimpleSerializer.Binary(new ExpressionSurrogateSelector());

            Expression <Func <int, int> > expr = x => x * 2;

            var newExpr = (Expression <Func <int, int> >)ser.Deserialize(ser.Serialize(expr));

            newExpr.Should().Not.Be(expr);
            newExpr.Compile()(21).Should().Be(42);
        }
        public void CompositeWrapperIsSerializable()
        {
            var outer = typeof(Sample).GetProperty("TestInner");
            var inner = typeof(Inner).GetProperty("TestInt");
            var props = new[] { outer, inner }.Select(x => x.ToSettable());

            var set = props.ToSettable();

            var result = SimpleSerializer.Binary().RoundTrip(set);

            result.Name.Should().Be.Equals(set.Name);
        }
        public void TestSerializeLambdaWithAnonymousTypes()
        {
            var ser = SimpleSerializer.Binary(new ExpressionSurrogateSelector());

            var expr = Expr(x => new { asd = x * 2 });

            var newExpr = (LambdaExpression)ser.Deserialize(ser.Serialize(expr));

            newExpr.Should().Not.Be(expr);
            var obj = newExpr.Compile().DynamicInvoke(21);

            obj.GetType().GetProperty("asd").GetValue(obj, null).Should().Be(42);
        }
        public void WhenSerializingNullExpressionItWorksWell()
        {
            var lazy = new LazyExpression <Func <string, int> >(null);
            var real = lazy.Real;

            var newLazy = SimpleSerializer.Binary().RoundTrip(lazy);

            newLazy.IsRealActivated.Should().Be.False();
            newLazy.IsProxyActivated.Should().Be.False();
            var newReal = newLazy.Real;

            newLazy.IsRealActivated.Should().Be.True();
            newLazy.IsProxyActivated.Should().Be.False();


            newReal.Should().Be(real);
        }
        public void WhenSerializingSimpleExpressionItWorksWell()
        {
            var lazy = new LazyExpression <Func <string, int> >(x => int.Parse(x));
            var real = lazy.Real;

            var newLazy = SimpleSerializer.Binary().RoundTrip(lazy);

            newLazy.IsRealActivated.Should().Be.False();
            newLazy.IsProxyActivated.Should().Be.True();
            var newReal = newLazy.Real;

            newLazy.IsRealActivated.Should().Be.True();
            newLazy.IsProxyActivated.Should().Be.True();


            Assert.AreNotSame(real, newReal);
        }
Example #13
0
 protected T SerializeAndDeserialize <T>(T value)
 {
     return(SimpleSerializer.Binary().RoundTrip(value));
 }
 protected override ISimpleStringSerializer GetStringSerializer <T>()
 {
     return(SimpleSerializer.Binary());
 }