示例#1
0
        public void SearchyMultipleConditions()
        {
            SearchyCondition _sc1 = new SearchyCondition(nameof(Employee.FirstName), SearchyRule.EqualsTo, FakeEmployees.Data.First().FirstName);
            SearchyCondition _sc2 = new SearchyCondition(nameof(Employee.LastName), SearchyRule.EqualsTo, FakeEmployees.Data.First().LastName);

            var _data = FakeEmployees.Data.Search(new SearchyCondition[] { _sc1, _sc2 }).ToList();
        }
示例#2
0
        public void SearchyMany()
        {
            SearchyCondition _sc1 = new SearchyCondition($"{nameof(Leave.Days)}", SearchyRule.GreaterThan, 7);

            var data = FakeEmployees.Data.Search <Employee, Leave>("Leaves", new SearchyCondition[] { _sc1 }).ToList();

            Assert.AreEqual(FakeEmployees.Data.Where(s => s.Leaves.Any(l => l.Days > 7)).Count(), data.Count());
        }
示例#3
0
 public void SearchyOrderBy()
 {
     SearchyCondition _sc = new SearchyCondition(new SearchyFilter {
         Value = FakeEmployees.Data.First().FirstName, Rule = SearchyRule.Contains, Field = nameof(Employee.FirstName)
     });
     List <SearchySort> _ob = new List <SearchySort> {
         new SearchySort(nameof(Employee.LastName), SearchySortOrder.ASC)
     };
     var _data = FakeEmployees.Data.Search(new SearchyCondition[] { _sc }, _ob, 0, 0).ToList();
 }
示例#4
0
        public void SearchyManyWithPaging()
        {
            SearchyCondition _sc1 = new SearchyCondition($"{nameof(Leave.Days)}", SearchyRule.GreaterThan, 7);

            var data = FakeEmployees.Data.Search <Employee, Leave>("Leaves", new SearchyCondition[] { _sc1 }, new SearchySort[] { new SearchySort {
                                                                                                                                      Field = "Id", Sort = SearchySortOrder.DEC
                                                                                                                                  } }, 5).ToList();

            Assert.AreEqual(5, data.Count());
        }
示例#5
0
        public void SearchyRange()
        {
            var values = new int[] { 30, 40 };
            var sc     = new SearchyCondition(new SearchyFilter
            {
                Value = values,
                Rule  = SearchyRule.Range,
                Field = nameof(Employee.Age)
            });

            var data = FakeEmployees.Data.Search(sc);

            Assert.AreEqual(FakeEmployees.Data.Where(p => p.Age >= values[0] && p.Age < values[1]).Count(), data.Count());
        }
示例#6
0
        public void SearchyEqualsToList()
        {
            var values = FakeEmployees.Data.Take(3).Select(p => p.FirstName).ToArray();
            var sc     = new SearchyCondition(new SearchyFilter
            {
                Value = values,
                Rule  = SearchyRule.EqualsToList,
                Field = nameof(Employee.FirstName)
            });

            var data = FakeEmployees.Data.Search(sc);

            Assert.AreEqual(FakeEmployees.Data.Where(p => values.Contains(p.FirstName)).Count(), data.Count());
        }
示例#7
0
        public void SearchyFieldSegments()
        {
            //var values = FakeEmployees.Data.Take(3).Select(p => p.FirstName).ToArray();
            var sc = new SearchyCondition(new SearchyFilter
            {
                Value = "120",
                Rule  = SearchyRule.GreaterThan,
                Field = $"{nameof(Employee.Salary)}.{nameof(Money.Amount)}"
            });

            var data = FakeEmployees.Data.Search(sc);

            //Assert.AreEqual(FakeEmployees.Data.Where(p => values.Contains(p.FirstName)).Count(), data.Count());
        }
        public void TestSearchyRequestSerialization()
        {
            var sr1 = new SearchyRequest("Id", SearchyRule.EqualsTo, "s");

            //var sr2 = new SearchyRequest("ID", SearchyRule.EqualsTo, "s");

            //var sr2 =  Newtonsoft.Json.JsonConvert.SerializeObject(sr1);
            //var sr3 = System.Text.Json.JsonSerializer.Serialize(sr1);

            //var result = sr1 == sr2;
            //Assert.IsTrue(result);
            var filters   = new List <SearchyFilter>();
            var condition = new SearchyCondition(filters);
        }
示例#9
0
        public void SearchyMultipleFilters()
        {
            List <SearchyFilter> _fol = new List <SearchyFilter>
            {
                new SearchyFilter {
                    Value = FakeEmployees.Data.First().FirstName, Rule = SearchyRule.Contains, Field = nameof(Employee.FirstName)
                },
                new SearchyFilter {
                    Value = FakeEmployees.Data.First().LastName, Rule = SearchyRule.EqualsTo, Field = nameof(Employee.LastName)
                }
            };

            SearchyCondition _sc = new SearchyCondition(_fol);
            var _data            = FakeEmployees.Data.Search(_sc).ToList();
        }
 public static IQueryable <TEntity> Search <TEntity>(this IQueryable <TEntity> target, SearchyCondition condition)
 {
     return(Search(target, new SearchyCondition[] { condition }));
 }
示例#11
0
 static public Task <IEnumerable <TEntity> > All <TEntity>(this DbConnection connection, string tableName, SearchyCondition condition) where TEntity : new()
 {
     return(connection.All <TEntity>(tableName, new SearchyCondition[] { condition }));
 }
示例#12
0
 public Task <IEnumerable <TEntity> > All <TEntity>(SearchyCondition condition) where TEntity : new()
 {
     return(Connection.All <TEntity>(new SearchyCondition[] { condition }));
 }