Esempio n. 1
0
        public void ObjectPropertyMethodSerializeTest()
        {
            Expression <Func <SecurityDbContext, DbContextObject1, bool> > criteria = (db, obj) => obj.Description.StartsWith("hello");
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

            string propertyType        = "System.String";
            string methodResultType    = "System.Boolean";
            string methodObjectType    = "System.String";
            string methodParameterType = "System.String";
            string objectType          = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

            XElement body = new XElement("MethodCallExpression",
                                         new XAttribute("NodeType", "Call"),
                                         new XAttribute("CanReduce", "false"),
                                         SerializeTestHelper.GetTypeElement(methodResultType),
                                         SerializeTestHelper.GetSingleParameterMethod("StartsWith", methodObjectType, methodParameterType),
                                         new XElement("Object",
                                                      SerializeTestHelper.GetMemberExpression(objectType, "obj", propertyType, "Description")
                                                      ),
                                         new XElement("Arguments",
                                                      SerializeTestHelper.GetConstantExpression(methodParameterType, "hello")
                                                      )
                                         );

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 2
0
        public void TwoPropertiesWithImplicitConversionSerializeTest()
        {
            Expression <Func <SecurityDbContext, DbContextObject1, bool> > criteria = (db, obj) => obj.ItemCount < obj.DecimalItem;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

            string property1Type = "System.Int32";
            string property2Type = "System.Decimal";
            string property1Name = "ItemCount";
            string property2Name = "DecimalItem";
            string objectName    = "obj";
            string objectType    = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

            XElement implicitConversionMethod = SerializeTestHelper.GetSingleParameterMethod("op_Implicit", "System.Decimal", "System.Int32");
            XElement lessThanMethod           = SerializeTestHelper.GetMethod("op_LessThan", "System.Decimal", new string[] { "System.Decimal", "System.Decimal" });

            XElement right = SerializeTestHelper.GetMemberExpression(objectType, objectName, property2Type, property2Name);
            XElement left  = SerializeTestHelper.GetMemberConvertUnaryExpression(property2Type, objectType, objectName, property1Type, property1Name);

            SerializeTestHelper.SetMethodElement(left, implicitConversionMethod);

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

            SerializeTestHelper.SetMethodElement(body, lessThanMethod);

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 3
0
        public void LessThanFunctionCallSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj < getSomeValue();
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = new XElement("BinaryExpression",
                                         new XAttribute("NodeType", "LessThan"),
                                         new XAttribute("CanReduce", "false"),
                                         new XAttribute("IsLifted", "false"),
                                         new XAttribute("IsLiftedToNull", "false"),
                                         SerializeTestHelper.GetTypeElement("System.Boolean"),
                                         new XElement("Right",
                                                      SerializeTestHelper.GetConstantExpression("System.Int32", "5")
                                                      ),
                                         new XElement("Left",
                                                      SerializeTestHelper.GetParameterExpression("System.Int32", "obj")
                                                      ),
                                         new XElement("Method"),
                                         new XElement("Conversion")
                                         );

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 4
0
        public void LiftedArithmeticPlusSerializeTest()
        {
            Expression <Func <SecurityDbContext, int?, bool> > criteria = (db, obj) => obj + 1 < 5;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

            string   objectType = "System.Nullable`1|System.Int32";
            XElement nominal    = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

            XElement left = SerializeTestHelper.GetBinaryExpression("Add",
                                                                    SerializeTestHelper.SetLifted(SerializeTestHelper.GetConstantConvertUnaryExpression(objectType, "System.Int32", "1"), true, true),
                                                                    SerializeTestHelper.GetParameterExpression(objectType, "obj"),
                                                                    objectType);
            XElement right = SerializeTestHelper.GetConstantConvertUnaryExpression(objectType, "System.Int32", "5");

            SerializeTestHelper.SetLifted(left, true, true);
            SerializeTestHelper.SetLifted(right, true, true);

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

            SerializeTestHelper.SetLifted(body, true, false);

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 5
0
        public void MultipleSerializeTest()
        {
            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();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);

            XElement serialized2 = criteriaSerializer.SerializeAsXElement(criteria);

            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized2);
        }
Esempio n. 6
0
        public void ParameterExpressionSerializeTest()
        {
            Expression         criteria           = Expression.Parameter(typeof(int), "intParam");
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();

            XElement serialized = criteriaSerializer.SerializeAsXElement(criteria);
            XElement nominal    = SerializeTestHelper.GetParameterExpression("System.Int32", "intParam");

            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 7
0
        public void ComplexSerializeTest()
        {
            Expression <Func <DbContextMultiClass, DbContextObject1, bool> > criteria = (db, obj) => obj.ItemCount < db.dbContextDbSet1.Count();
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

            string propertyType         = "System.Int32";
            string objectType           = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";
            string dbContextType        = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextMultiClass";
            string methodCallResultType = "System.Int32";
            string methodObjectType     = "System.Linq.Queryable";
            string methodParameterType  = "System.Linq.IQueryable`1|DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";
            string dbSetMemberType      = "Microsoft.EntityFrameworkCore.DbSet`1|DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";
            string dbSetPropertyName    = "dbContextDbSet1";
            string dbSetType            = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextMultiClass";

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElement(objectType, dbContextType);

            XElement memberExpression = new XElement("MemberExpression",
                                                     new XAttribute("NodeType", "MemberAccess"),
                                                     new XAttribute("CanReduce", "false"),
                                                     SerializeTestHelper.GetTypeElement(dbSetMemberType),
                                                     new XElement("Member",
                                                                  new XAttribute("MemberType", "Property"),
                                                                  new XAttribute("PropertyName", dbSetPropertyName),
                                                                  new XElement("DeclaringType",
                                                                               new XElement("Type",
                                                                                            new XAttribute("Name", dbSetType)
                                                                                            )
                                                                               )
                                                                  ),
                                                     new XElement("Expression",
                                                                  SerializeTestHelper.GetParameterExpression(dbContextType, "db")
                                                                  )
                                                     );

            XElement right = new XElement("MethodCallExpression",
                                          new XAttribute("NodeType", "Call"),
                                          new XAttribute("CanReduce", "false"),
                                          SerializeTestHelper.GetTypeElement(methodCallResultType),
                                          SerializeTestHelper.GetSingleParameterMethod("Count", methodObjectType, methodParameterType, new string[] { objectType }),
                                          new XElement("Object"),
                                          new XElement("Arguments",
                                                       memberExpression
                                                       )
                                          );

            XElement body = SerializeTestHelper.GetBinaryExpression("LessThan",
                                                                    right,
                                                                    SerializeTestHelper.GetMemberExpression(objectType, "obj", propertyType, "ItemCount"));

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 8
0
        public void ReturnFalseSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => false;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement body = SerializeTestHelper.GetConstantExpression("System.Boolean", "False");

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public void ConvertToDoubleSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => obj / 2.0 < 5.2;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement left = SerializeTestHelper.GetBinaryExpression("Divide",
                                                                    SerializeTestHelper.GetConstantExpression("System.Double", "2"),
                                                                    SerializeTestHelper.GetParameterConvertUnaryExpression("System.Double", "System.Int32", "obj"),
                                                                    "System.Double");
            XElement right = SerializeTestHelper.GetConstantExpression("System.Double", "5.2");
            XElement body  = SerializeTestHelper.GetBinaryExpression("LessThan", right, left);

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 11
0
        public void ArithmeticXorSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, bool> > criteria = (db, obj) => (obj ^ 2) < 5;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);
            XElement           nominal            = SerializeTestHelper.CreateBaseCriteriaXElementWithIntObj();

            XElement left = SerializeTestHelper.GetBinaryExpression("ExclusiveOr",
                                                                    SerializeTestHelper.GetConstantExpression("System.Int32", "2"),
                                                                    SerializeTestHelper.GetParameterExpression("System.Int32", "obj"),
                                                                    "System.Int32");
            XElement right = SerializeTestHelper.GetConstantExpression("System.Int32", "5");
            XElement body  = SerializeTestHelper.GetBinaryExpression("LessThan", right, left);

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 12
0
        public void BadExpressionParametersCountSerializeTest()
        {
            Expression <Func <SecurityDbContext, int, int, bool> > criteria = (db, obj, obj2) => obj < obj2;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();

            bool withArgumentException = false;

            try {
                XElement serialized = criteriaSerializer.SerializeAsXElement(criteria);
            }
            catch (ArgumentException) {
                withArgumentException = true;
            }
            catch (Exception e) {
                Assert.Fail(e.Message);
            }
            Assert.IsTrue(withArgumentException);
        }
Esempio n. 13
0
        public void BadExpressionExpressionType2SerializeTest()
        {
            Expression <Func <SecurityDbContext, int, int> > criteria = (db, obj) => obj + 5;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();

            bool withArgumentException = false;

            try {
                XElement serialized = criteriaSerializer.SerializeAsXElement(criteria.Body);
            }
            catch (ArgumentException) {
                withArgumentException = true;
            }
            catch (Exception e) {
                Assert.Fail(e.Message);
            }
            Assert.IsTrue(withArgumentException);
        }
Esempio n. 14
0
        public void BadExpressionExpressionTypeSerializeTest()
        {
            Expression         criteria           = Expression.Constant(10, typeof(int));
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();

            bool withArgumentException = false;

            try {
                XElement serialized = criteriaSerializer.SerializeAsXElement(criteria);
            }
            catch (ArgumentException) {
                withArgumentException = true;
            }
            catch (Exception e) {
                Assert.Fail(e.Message);
            }
            Assert.IsTrue(withArgumentException);
        }
Esempio n. 15
0
        public void ObjectPropertyLessThanConstantSerializeTest()
        {
            Expression <Func <SecurityDbContext, DbContextObject1, bool> > criteria = (db, obj) => obj.ItemCount < 3;
            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

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

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

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

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 16
0
        public void NotEqualNullSerializeTest()
        {
            Expression <Func <SecurityDbContext, DbContextObject1, bool> > criteria = (db, obj) => obj != null;

            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

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

            XElement nominal = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

            XElement body = SerializeTestHelper.GetBinaryExpression("NotEqual",
                                                                    SerializeTestHelper.GetConstantExpression("System.Object", ""),
                                                                    SerializeTestHelper.GetParameterExpression(objectType, "obj"));

            SerializeTestHelper.SetLambdaBody(nominal, body);
            SerializeTestHelper.CheckIfNominalAndSerializedAreEqual(nominal, serialized);
        }
Esempio n. 17
0
        public void ObjectNullablleIsNotNullSerializeTest()
        {
            Expression <Func <SecurityDbContext, DbContextObject1, bool> > criteria = (db, obj) => obj.ItemCountNull != null;

            CriteriaSerializer criteriaSerializer = new CriteriaSerializer();
            XElement           serialized         = criteriaSerializer.SerializeAsXElement(criteria);

            string   objectType   = "DevExpress.EntityFramework.SecurityDataStore.Tests.DbContexts.DbContextObject1";
            string   propertyType = "System.Nullable`1|System.Int32";
            XElement nominal      = SerializeTestHelper.CreateBaseCriteriaXElement(objectType);

            XElement left  = SerializeTestHelper.GetMemberExpression(objectType, "obj", propertyType, "ItemCountNull");
            XElement right = SerializeTestHelper.GetConstantExpression(propertyType, "");

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

            SerializeTestHelper.SetLifted(body, true, false);

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