Ejemplo n.º 1
0
        public void TestMultiple()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            IOrderCriteria orderCriteria = new OrderCriteria().Add("TestProp");  
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------

            orderCriteria.Add("TestProp2", SortDirection.Descending);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, orderCriteria.Fields.Count);
            Assert.Contains(new OrderCriteriaField("TestProp2", SortDirection.Descending), orderCriteria.Fields);
            //---------------Tear Down -------------------------
        }
Ejemplo n.º 2
0
        public void TestMultiple()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            IOrderCriteria orderCriteria = new OrderCriteria().Add("TestProp");

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------

            orderCriteria.Add("TestProp2", SortDirection.Descending);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, orderCriteria.Fields.Count);
            Assert.Contains(new OrderCriteriaField("TestProp2", SortDirection.Descending), orderCriteria.Fields);
            //---------------Tear Down -------------------------
        }
Ejemplo n.º 3
0
        public void TestToString()
        {
            //---------------Set up test pack-------------------
            IOrderCriteria orderCriteria = new OrderCriteria().Add("TestProp");

            orderCriteria.Add("TestProp2", SortDirection.Descending);
            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------

            string orderCriteriaString = orderCriteria.ToString();

            //---------------Test Result -----------------------
            StringAssert.AreEqualIgnoringCase("TestProp ASC, TestProp2 DESC", orderCriteriaString);
            //---------------Tear Down -------------------------
        }
Ejemplo n.º 4
0
        private IOrderCriteria GetOrderCriteria(ObservableCollection <Ordering> orderings)
        {
            var orderCriteria = new OrderCriteria();

            foreach (var ordering in orderings)
            {
                var expression = ordering.Expression;
                if (expression.NodeType == ExpressionType.MemberAccess)
                {
                    var memberExpression = (MemberExpression)expression;
                    orderCriteria.Add(memberExpression.Member.Name, ordering.OrderingDirection == OrderingDirection.Asc ? SortDirection.Ascending : SortDirection.Descending);
                }
            }

            return(orderCriteria);
        }
Ejemplo n.º 5
0
 public void Sort_OneFieldAscending()
 {
     //---------------Set up test pack-------------------
     var resultSet = new QueryResult();
     resultSet.AddField("Name");
     const string lastValue = "zzzzz";
     const string firstValue = "aaaaa";
     resultSet.AddResult(new object[] { lastValue });
     resultSet.AddResult(new object[] { firstValue });
     var orderCriteria = new OrderCriteria();
     orderCriteria.Add("Name");
     var sorter = new QueryResultSorter();
     //---------------Execute Test ----------------------
     sorter.Sort(resultSet, orderCriteria);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(firstValue, rows[0].Values[0]);
     Assert.AreEqual(lastValue, rows[1].Values[0]);
 }
Ejemplo n.º 6
0
        public void Sort_OneFieldAscending()
        {
            //---------------Set up test pack-------------------
            var resultSet = new QueryResult();

            resultSet.AddField("Name");
            const string lastValue  = "zzzzz";
            const string firstValue = "aaaaa";

            resultSet.AddResult(new object[] { lastValue });
            resultSet.AddResult(new object[] { firstValue });
            var orderCriteria = new OrderCriteria();

            orderCriteria.Add("Name");
            var sorter = new QueryResultSorter();

            //---------------Execute Test ----------------------
            sorter.Sort(resultSet, orderCriteria);
            //---------------Test Result -----------------------
            var rows = resultSet.Rows.ToList();

            Assert.AreEqual(firstValue, rows[0].Values[0]);
            Assert.AreEqual(lastValue, rows[1].Values[0]);
        }
Ejemplo n.º 7
0
        public void TestToString()
        {
            //---------------Set up test pack-------------------
            IOrderCriteria orderCriteria = new OrderCriteria().Add("TestProp");
            orderCriteria.Add("TestProp2", SortDirection.Descending);
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------

            string orderCriteriaString = orderCriteria.ToString();
            //---------------Test Result -----------------------
            StringAssert.AreEqualIgnoringCase("TestProp ASC, TestProp2 DESC", orderCriteriaString);
            //---------------Tear Down -------------------------
        }
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Where")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                return(m);
            }

            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Take")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                Take = (int?)VisitedElements.Pop().Evaluate();
                return(m);
            }

            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Skip")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                Skip = (int?)VisitedElements.Pop().Evaluate();
                return(m);
            }
            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "OrderBy")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                var criteria = new StorageQueryOrderCriteria
                {
                    Direction  = QueryOrderDirection.Ascending,
                    OrderField = (StorageQueryEntityMember)VisitedElements.Pop()
                };
                if (OrderCriteria.Any())
                {
                    throw new StorageArgumentException("Order criteria already has some terms, use ThenBy");
                }
                OrderCriteria.Add(criteria);
                return(m);
            }

            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "OrderByDescending")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                var criteria = new StorageQueryOrderCriteria
                {
                    Direction  = QueryOrderDirection.Descending,
                    OrderField = (StorageQueryEntityMember)VisitedElements.Pop()
                };
                if (OrderCriteria.Any())
                {
                    throw new StorageArgumentException("Order criteria already has some terms, use ThenByDescending");
                }
                OrderCriteria.Add(criteria);
                return(m);
            }


            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "ThenBy")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                var criteria = new StorageQueryOrderCriteria
                {
                    Direction  = QueryOrderDirection.Ascending,
                    OrderField = (StorageQueryEntityMember)VisitedElements.Pop()
                };
                if (!OrderCriteria.Any())
                {
                    throw new StorageArgumentException("Order criteria not have terms, use OrderBy");
                }
                OrderCriteria.Add(criteria);
                return(m);
            }

            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "ThenByDescending")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                var criteria = new StorageQueryOrderCriteria
                {
                    Direction  = QueryOrderDirection.Descending,
                    OrderField = (StorageQueryEntityMember)VisitedElements.Pop()
                };
                if (!OrderCriteria.Any())
                {
                    throw new StorageArgumentException("Order criteria not have terms, use OrderByDescending");
                }
                OrderCriteria.Add(criteria);
                return(m);
            }

            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "FirstOrDefault")
            {
                Take = 1;
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                return(m);
            }

            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "First")
            {
                Take = 1;
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                return(m);
            }

            if (m.Method.DeclaringType == typeof(string) && m.Method.Name == "IsNullOrWhiteSpace")
            {
                foreach (var arg in m.Arguments)
                {
                    Visit(arg);
                }
                return(m);
            }

            try
            {
                ProcessMemberStack(m);
            }
            catch
            {
                throw new StorageArgumentException($"Can not process expression {m}");
            }
            return(m);
        }
        public void Test_GetCollection_Generic_LoadWithLimit_CriteriaObject_IncludesCriteriaMatchesWithinLimit()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            DateTime now = DateTime.Now;
            ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now, "aaa");
            ContactPersonTestBO cpLast = ContactPersonTestBO.CreateSavedContactPerson(now, "zzz");
            ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now, "hhh");
            ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(-3), "bbb");

            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, now.AddHours(-1));
            OrderCriteria orderCriteria = new OrderCriteria();
            orderCriteria.Add("Surname");
            int totalNoOfRecords;
            //---------------Assert Precondition ---------------
            //---------------Execute Test ----------------------
            //            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);
            BusinessObjectCollection<ContactPersonTestBO> col =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection<ContactPersonTestBO>
                    (criteria, orderCriteria, 0, 2, out totalNoOfRecords);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.AreSame(cp1, col[0]);
            Assert.AreSame(cp2, col[1]);
            Assert.IsFalse(col.Contains(cpLast));
        }
 public void Test_GetCollection_Generic_LoadWithLimit_FirstAtStart_LimitEqualsEnd()
     //NoRecords_StartRecords_ContainsAllRecords()
 {
     const int totalRecords = 3;
     const int firstRecord = 0;
     const int limit = totalRecords;
     SetupDefaultContactPersonBO();
     ContactPersonTestBO[] contactPersonTestBOs = CreateSavedContactPeople(totalRecords);
     OrderCriteria orderCriteria = new OrderCriteria();
     orderCriteria.Add("Surname");
     //---------------Assert Precondition----------------
     Assert.AreEqual(totalRecords, contactPersonTestBOs.Length);
     //---------------Execute Test ----------------------
     int totalNoOfRecords;
     BusinessObjectCollection<ContactPersonTestBO> col =
         BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection<ContactPersonTestBO>
             (null, orderCriteria, firstRecord, limit, out totalNoOfRecords);
     //---------------Test Result -----------------------
     AssertLimitedResultsCorrect
         (firstRecord, limit, totalRecords, totalRecords, contactPersonTestBOs, col, totalNoOfRecords);
 }
            Test_GetCollection_NonGeneric_LoadWithLimit_ThenRefresh_CriteriaObject_NewObjectWithinLimitAndCriteria_Included
            ()
        {
            //---------------Set up test pack-------------------
            IClassDef def = SetupDefaultContactPersonBO();
            DateTime now = DateTime.Now;
            ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson(now, "aaa");
            ContactPersonTestBO cpLast = ContactPersonTestBO.CreateSavedContactPerson(now, "zzz");
            ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson(now, "hhh");
            ContactPersonTestBO.CreateSavedContactPerson(DateTime.Now.AddDays(-3));

            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, now.AddHours(-1));
            OrderCriteria orderCriteria = new OrderCriteria();
            orderCriteria.Add("Surname");
            int noRecords;
            IBusinessObjectCollection col = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection
                (def, criteria, orderCriteria, 0, 2, out noRecords);
            //            col.LoadWithLimit(criteria, "Surname", 2);
            ContactPersonTestBO cpnew = ContactPersonTestBO.CreateSavedContactPerson(now, "bbb");

            //---------------Assert Precondition ---------------
            Assert.AreEqual(2, col.Count);

            //---------------Execute Test ----------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(col);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.AreSame(cp1, col[0]);
            Assert.AreSame(cpnew, col[1]);
            Assert.IsFalse(col.Contains(cpLast));
            Assert.IsFalse(col.Contains(cp2));
        }
 public void Test_LoadWithOrderBy_ManualOrderbyFieldName()
 {
     //---------------Set up test pack-------------------
     SetupDefaultContactPersonBO();
     ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("eeeee");
     ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("ggggg");
     ContactPersonTestBO cp3 = ContactPersonTestBO.CreateSavedContactPerson("bbbbb");
     OrderCriteria orderCriteria = new OrderCriteria();
     //---------------Execute Test ----------------------
     orderCriteria.Add
         (new OrderCriteriaField("Surname", "Surname_field", null, SortDirection.Ascending));
     BusinessObjectCollection<ContactPersonTestBO> col =
         BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection<ContactPersonTestBO>
             (null, orderCriteria);
     //---------------Test Result -----------------------
     Assert.AreSame(cp3, col[0]);
     Assert.AreSame(cp1, col[1]);
     Assert.AreSame(cp2, col[2]);
 }
        public void Test_GetCollection_NonGeneric_LoadWithLimit_FirstNegative_ThrowsError()
        {
            const int totalRecords = 3;
            const int firstRecord = -1;
            const int limit = 0;
            IClassDef def = SetupDefaultContactPersonBO();
            ContactPersonTestBO[] contactPersonTestBOs = CreateSavedContactPeople(totalRecords);
            //---------------Assert Precondition----------------
            Assert.AreEqual(totalRecords, contactPersonTestBOs.Length);
            //---------------Execute Test ----------------------
            try
            {
                int totalNoOfRecords;
                OrderCriteria orderCriteria = new OrderCriteria();
                orderCriteria.Add("Surname");
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection(def, null, orderCriteria, firstRecord, limit, out totalNoOfRecords);

                //---------------Test Result -----------------------
                Assert.Fail("IndexOutOfRangeException exception expected");
            }
            catch (IndexOutOfRangeException ex)
            {
                Assert.AreEqual("FirstRecordToLoad should not be negative.", ex.Message);
            }
        }
        public void Test_GetCollection_NonGeneric_LoadWithLimit_FirstAfterEnd_LimitZero()
        {
            const int totalRecords = 3;
            const int firstRecord = 4;
            const int limit = 0;
            IClassDef def = SetupDefaultContactPersonBO();
            ContactPersonTestBO[] contactPersonTestBOs = CreateSavedContactPeople(totalRecords);
            //---------------Assert Precondition----------------
            Assert.AreEqual(totalRecords, contactPersonTestBOs.Length);
            //---------------Execute Test ----------------------
            int totalNoOfRecords;
            OrderCriteria orderCriteria = new OrderCriteria();
            orderCriteria.Add("Surname");
            IBusinessObjectCollection col =
                 BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection(def, null, orderCriteria, firstRecord, limit, out totalNoOfRecords);

            //---------------Test Result -----------------------
            AssertLimitedResultsCorrect
                (firstRecord, limit, totalRecords, 0, contactPersonTestBOs, col, totalNoOfRecords);
        }
        public void Test_GetCollection_NonGeneric_LoadWithLimit_FirstAtEnd_LimitBeyondEnd_RefreshWithAdditionalBO()
        {
            const int totalRecords = 5;
            const int firstRecord = totalRecords - 1;
            const int limit = 3;
            IClassDef def = SetupDefaultContactPersonBO();
            ContactPersonTestBO[] contactPersonTestBOs = CreateSavedContactPeople(totalRecords);
            ContactPersonTestBO[] contactPersonTestBOsPlusOne = new ContactPersonTestBO[totalRecords + 1];
            contactPersonTestBOs.CopyTo(contactPersonTestBOsPlusOne, 0);
            int totalNoOfRecords;
            OrderCriteria orderCriteria = new OrderCriteria();
            orderCriteria.Add("Surname");
            IBusinessObjectCollection col =
                 BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection(def, null, orderCriteria, firstRecord, limit, out totalNoOfRecords);

            contactPersonTestBOsPlusOne[totalRecords] = ContactPersonTestBO.CreateSavedContactPerson
                ("ZZZZZZZZZZZZZZZZZ");
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(totalRecords, contactPersonTestBOs.Length);
            Assert.AreEqual(totalRecords + 1, contactPersonTestBOsPlusOne.Length);
            //---------------Execute Test ----------------------
            col.Refresh();
            //---------------Test Result -----------------------
            totalNoOfRecords++;
            AssertLimitedResultsCorrect
                (firstRecord, limit, totalRecords + 1, 2, contactPersonTestBOsPlusOne, col, totalNoOfRecords);
        }