示例#1
0
        public void TestOrderBy1()
        {
            var conditionBuilder = ConditionBuilder <Account> .Create();

            conditionBuilder.OrderBy(x => new { x.Sex, x.Age });

            Assert.Fail("期望抛出NotSupportedException,但实际并没抛出异常");
        }
示例#2
0
        public void TestCreate()
        {
            var builder = ConditionBuilder <Account> .Create();

            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);
        }
示例#3
0
        public void TestGetAccountPagingData()
        {
            var conditionBuilder = ConditionBuilder <Account> .Create();

            conditionBuilder.OrderBy(x => x.Sex).ThenBy(x => x.CreateTime);
            var pagingCondition = new PagingCondition(0, 15);

            Account.GetPagingDtoData <AccountDto>(pagingCondition, conditionBuilder);
        }
示例#4
0
        public void TestOrderBy3()
        {
            var conditionBuilder = ConditionBuilder <Account> .Create();

            conditionBuilder.OrderBy(x => x.Sex);
            conditionBuilder.OrderByDescending(x => x.Sex);

            Assert.AreEqual(1, conditionBuilder.OrderByConditions.Count);
            Assert.AreEqual("Sex", conditionBuilder.OrderByConditions.First().Key);
            Assert.AreEqual(ListSortDirection.Descending, conditionBuilder.OrderByConditions.Last().Value.Direction);
        }
示例#5
0
        public void TestGetSoftDeletedItems()
        {
            AccountRepository.Delete(AccountRepository.Entities);

            var conditionBuilder = ConditionBuilder <Account> .Create();

            Assert.AreEqual(false, AccountRepository.Entities.Where(conditionBuilder.Predicate).Any());

            conditionBuilder.Clear();
            conditionBuilder.IsGetSoftDeletedItems = true;
            Assert.AreEqual(true, AccountRepository.Entities.Where(conditionBuilder.Predicate).Any());
        }
示例#6
0
        public void TestOrderBy4()
        {
            var conditionBuilder = ConditionBuilder <Account> .Create();

            conditionBuilder.OrderBy(x => x.Sex).ThenByDescending(x => x.Id).ThenBy(x => x.Name.FirstName);
            Assert.AreEqual(3, conditionBuilder.OrderByConditions.Count);
            Assert.AreEqual("Sex", conditionBuilder.OrderByConditions.First().Key);
            Assert.AreEqual("FirstName", conditionBuilder.OrderByConditions.Last().Key);
            Assert.AreEqual(ListSortDirection.Ascending, conditionBuilder.OrderByConditions.First().Value.Direction);
            Assert.AreEqual(ListSortDirection.Descending, conditionBuilder.OrderByConditions.Single(x => x.Key == "Id").Value.Direction);
            Assert.AreEqual(ListSortDirection.Ascending, conditionBuilder.OrderByConditions.Last().Value.Direction);
        }
示例#7
0
        public static List <SectionConfigDto> GetSectionConfigDtos(int?articleId = null)
        {
            var condition = ConditionBuilder <SectionConfig> .Create();

            if (articleId != null)
            {
                condition.Equal(x => x.ArticleId, articleId.Value);
            }
            return(Repository.Entities
                   .Where(condition.Predicate)
                   .OrderBy(x => x.Depth)
                   .ThenBy(x => x.Index)
                   .Project().To <SectionConfigDto>().ToList());
        }
示例#8
0
        public void TestBetween()
        {
            var builder = ConditionBuilder <Account> .Create();

            builder.Between(x => x.Age, 20, 30);
            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);

            builder.Clear();
            builder.Between(x => x.Age, 30, 50);
            account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);
            Assert.IsNull(account);
        }
示例#9
0
        public void TestLessThan()
        {
            var builder = ConditionBuilder <Account> .Create();

            builder.LessThan(x => x.Age, 25);
            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);

            builder.Clear();
            builder.LessThan(x => x.Age, 16);
            account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);
            Assert.IsNull(account);
        }
示例#10
0
        public void TestFuzzy()
        {
            var builder = ConditionBuilder <Account> .Create();

            builder.Fuzzy(x => x.Name.LastName, "yi,bin,yibin,Wu");
            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);

            builder.Clear();
            builder.Fuzzy(x => x.Name.LastName, "world,good");
            account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);
            Assert.IsNull(account);
        }
示例#11
0
        public void TestIn()
        {
            var builder = ConditionBuilder <Account> .Create();

            builder.In(x => x.Name.LastName, "Wu", "Chen");
            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);

            builder.Clear();
            builder.In(x => x.Name.LastName, "hello", "world");
            account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);
            Assert.IsNull(account);
        }
示例#12
0
        public void TestLike()
        {
            var builder = ConditionBuilder <Account> .Create();

            builder.Like(x => x.Name.FirstName, "bin");
            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);

            builder.Clear();
            ;
            builder.Like(x => x.Name.FirstName, "51b");
            account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);
            Assert.IsNull(account);
        }
示例#13
0
        public void TestNotEquals()
        {
            var builder = ConditionBuilder <Account> .Create();

            builder.NotEqual(x => x.Sex, Sex.Female);
            var account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);

            Assert.IsNotNull(account);

            builder.Clear();
            builder.NotEqual(x => x.Sex, Sex.Male);
            builder.NotEqual(x => x.Sex, Sex.Unknown);
            account = AccountRepository.Entities.FirstOrDefault(builder.Predicate);
            Assert.IsNull(account);
        }