예제 #1
0
        public void GetByFilter_OffsetLimitAndFilter_FilterResult()
        {
            m_roleRepository.Add(new Role() { Name = "TEST1", Description = "DESCR1" });
            m_roleRepository.Add(new Role() { Name = "TEST2", Description = "DESCR2" });
            m_roleRepository.Add(new Role() { Name = "TEST3", Description = "DESCR3" });
            m_unitOfWork.Commit();

            Expression<Func<Role, bool>> query = null;
            RoleFilter filter = new RoleFilter();

            query = GetRoleFilterQuery(filter);
            Assert.AreEqual(3, m_target.Get(0, int.MaxValue, query).TotalCount);

            filter = new RoleFilter()
            {
                Name = "1"
            };

            filter.Sanitize();

            query = GetRoleFilterQuery(filter);
            Assert.AreEqual(1, m_target.Get(0, int.MaxValue, query).TotalCount);

            filter = new RoleFilter()
            {
                Description = "3"
            };

            filter.Sanitize();

            query = GetRoleFilterQuery(filter);
            Assert.AreEqual(1, m_target.Get(0, int.MaxValue, query).TotalCount);

            filter = new RoleFilter()
            {
                Name = "1",
                Description = "2"
            };

            filter.Sanitize();

            query = GetRoleFilterQuery(filter);
            Assert.AreEqual(0, m_target.Get(0, int.MaxValue, query).TotalCount);
        }
예제 #2
0
        private Expression<Func<Role, bool>> GetRoleFilterQuery(RoleFilter filter)
        {
            Expression<Func<Role, bool>> query = (f) => (filter.Description == null || f.Description.ToLower().Contains(filter.Description)) &&
                (filter.Name == null || f.Name.ToLower().Contains(filter.Name));

            return query;
        }