Exemplo n.º 1
0
        public void GreaterThanOrEqualConstantSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj >= 5;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = SerializeTestHelper.GetIntegerBinaryExpression("GreaterThanOrEqual", "5");

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Exemplo n.º 2
0
        public void SerializeToStringTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj < 5;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            string             serializedString   = criteriaSerializer.Serialize(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = SerializeTestHelper.GetIntegerBinaryExpression("LessThan", "5");

            SerializeTestHelper.SetLambdaBody(nominal, body);

            Assert.AreEqual(nominal.ToString(), serializedString);
        }
        public void GreaterThanConstantDeserializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj > 5;

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();
            XElement body    = SerializeTestHelper.GetIntegerBinaryExpression("GreaterThan", "5");

            SerializeTestHelper.SetLambdaBody(nominal, body);

            CriteriaSerializer criteriaSerializer   = new CriteriaSerializer();
            Expression         deserializedCriteria = criteriaSerializer.Deserialize(nominal);

            SerializeTestHelper.CheckIfExpressionsAreEqual(criteria, deserializedCriteria);
        }
Exemplo n.º 4
0
        public void LogicalOrSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj < 5 || obj > 1;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement left  = SerializeTestHelper.GetIntegerBinaryExpression("LessThan", "5");
            XElement right = SerializeTestHelper.GetIntegerBinaryExpression("GreaterThan", "1");

            XElement body = SerializeTestHelper.GetBinaryExpression("OrElse", right, left);

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
        public void LogicalAndDeserializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj < 5 && obj > 1;

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();
            XElement left    = SerializeTestHelper.GetIntegerBinaryExpression("LessThan", "5");
            XElement right   = SerializeTestHelper.GetIntegerBinaryExpression("GreaterThan", "1");

            XElement body = SerializeTestHelper.GetBinaryExpression("AndAlso", right, left);

            SerializeTestHelper.SetLambdaBody(nominal, body);

            CriteriaSerializer criteriaSerializer   = new CriteriaSerializer();
            Expression         deserializedCriteria = criteriaSerializer.Deserialize(nominal);

            SerializeTestHelper.CheckIfExpressionsAreEqual(criteria, deserializedCriteria);
        }
        public void DeserializeFromStringTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj < 5;
            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = SerializeTestHelper.GetIntegerBinaryExpression("LessThan", "5");

            SerializeTestHelper.SetLambdaBody(nominal, body);

            string nominalString = nominal.ToString();

            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();

            criteriaSerializer.RegisterAdditionalAssemblies(GetAdditionalAssemblies());
            Expression deserializedCriteria = criteriaSerializer.Deserialize(nominalString);

            SerializeTestHelper.CheckIfExpressionsAreEqual(criteria, deserializedCriteria);
        }
        public void MultipleDeserializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj < 5;
            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = SerializeTestHelper.GetIntegerBinaryExpression("LessThan", "5");

            SerializeTestHelper.SetLambdaBody(nominal, body);

            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();

            criteriaSerializer.RegisterAdditionalAssemblies(GetAdditionalAssemblies());

            Expression deserializedCriteria = criteriaSerializer.Deserialize(nominal);

            SerializeTestHelper.CheckIfExpressionsAreEqual(criteria, deserializedCriteria);

            Expression <Func <SecurityDbContext, DbContextObject1, bool> > criteria2 = (db, obj) => obj.ItemCount < 3;

            string propertyType = "System.Int32";
            string objectType   = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";

            XElement nominal2 = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

            XElement body2 = SerializeTestHelper.GetBinaryExpression("LessThan",
                                                                     SerializeTestHelper.GetConstantExpression("System.Int32", "3"),
                                                                     SerializeTestHelper.GetMemberExpression(objectType, "obj", propertyType, "ItemCount"));

            SerializeTestHelper.SetLambdaBody(nominal2, body2);

            Expression deserializedCriteria2 = criteriaSerializer.Deserialize(nominal2);

            SerializeTestHelper.CheckIfExpressionsAreEqual(criteria2, deserializedCriteria2);

            SerializeTestHelper.CheckIfExpressionsAreEqual(criteria, deserializedCriteria);
        }
Exemplo n.º 8
0
        public void LogicalNotSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => !(obj < 5);
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = SerializeTestHelper.GetUnaryExpression("Not", "System.Boolean", SerializeTestHelper.GetIntegerBinaryExpression("LessThan", "5"));

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }