예제 #1
0
        public void SimpleFilter()
        {
            var dataSource = _context.Things.Where(x => x.Id > 95);
            var data = dataSource.Take(PageSize).ToList();

            var request = new GridDataRequest()
            {
                Take = PageSize,
                Skip = 0,
                Search = new Filter(),
                Columns = Thing.GetColumnsWithIdFilter()
            };

            var response = request.CreateGridDataResponse(dataSource);

            Assert.AreEqual(data.Count, response.Payload.Count, "Same length");

            Assert.AreEqual(dataSource.Count(), response.FilteredRecordCount, "Total filtered rows matching");
        }
예제 #2
0
        public void SimpleSearch()
        {
            var dataSource = _context.Things;
            var data = dataSource.Where(x => x.Name.Contains(SearchText)).Take(PageSize).ToList();

            var request = new GridDataRequest()
            {
                Take = PageSize,
                Skip = 0,
                Search = new Filter()
                {
                  Operator = CompareOperators.Auto,
                  Text = SearchText
                },
                Columns = Thing.GetColumns()
            };

            var response = request.CreateGridDataResponse(dataSource);

            Assert.AreEqual(data.Count, response.Payload.Count, "Same length");
            Assert.AreEqual(data.First().Id, response.Payload.First().First(), "Same first item");

            Assert.AreEqual(dataSource.Count(x => x.Name.Contains(SearchText)), response.FilteredRecordCount, "Total filtered rows matching");
        }
예제 #3
0
        public void SimpleList()
        {
            var dataSource = _context.Things;
            var data = dataSource.Take(PageSize).ToList();

            Assert.AreEqual(PageSize, data.Count, "Set has 10 items");

            var request = new GridDataRequest()
            {
                Take = PageSize,
                Skip = 0,
                Search = new Filter(),
                Columns = Thing.GetColumns()
            };

            var response = request.CreateGridDataResponse(dataSource);

            Assert.AreEqual(data.Count, response.Payload.Count, "Same length");
            Assert.AreEqual(data.First().Id, response.Payload.First().First(), "Same first item");

            Assert.AreEqual(dataSource.Count(), response.TotalRecordCount, "Total rows matching");
        }
예제 #4
0
        public void TestSimpleAggregate()
        {
            var dataSource = _context.Things;
            var data = dataSource.Take(PageSize).ToList();

            Assert.AreEqual(PageSize, data.Count, "Set has 10 items");

            var request = new GridDataRequest()
            {
                Take = PageSize,
                Skip = 0,
                Search = new Filter(),
                Columns = Thing.GetColumnsWithAggregate()
            };

            var response = request.CreateGridDataResponse(dataSource);

            Assert.AreEqual(data.Count, response.Payload.Count, "Same length");
            Assert.AreEqual(data.First().Id, response.Payload.First().First(), "Same first item");

            Assert.AreEqual(dataSource.Sum(x => x.Number), (double)response.AggregationPayload["Number"], "Same average number");
            Assert.AreEqual(dataSource.Sum(x => x.DecimalNumber), (decimal)response.AggregationPayload["DecimalNumber"], "Same average decimal number");
        }
예제 #5
0
        public void TestMultipleAggregate()
        {
            var dataSource = _context.Things;
            var data = dataSource.Take(PageSize).ToList();

            Assert.AreEqual(PageSize, data.Count, "Set has 10 items");

            var request = new GridDataRequest()
            {
                Take = PageSize,
                Skip = 0,
                Search = new Filter(),
                Columns = Thing.GetColumnsWithMultipleCounts()
            };

            var response = request.CreateGridDataResponse(dataSource);

            Assert.AreEqual(data.Count, response.Payload.Count, "Same length");
            Assert.AreEqual(data.First().Id, response.Payload.First().First(), "Same first item");

            Assert.AreEqual(dataSource.Select(x => x.Id).Distinct().Count(), (int)response.AggregationPayload["Id"], "Id same distinct count");
            Assert.AreEqual(dataSource.Select(x => x.Number).Distinct().Count(), (int)response.AggregationPayload["Number"], "Number same distinct count");
            Assert.AreEqual(dataSource.Select(x => x.DecimalNumber).Distinct().Count(), (int)response.AggregationPayload["DecimalNumber"], "DecimalNumber same distinct count");
            Assert.AreEqual(dataSource.Select(x => x.Name).Distinct().Count(), (int)response.AggregationPayload["Name"], "Name same distinct count");
            Assert.AreEqual(dataSource.Select(x => x.Date).Distinct().Count(), (int)response.AggregationPayload["Date"], "Date same distinct count");
            Assert.AreEqual(dataSource.Select(x => x.Bool).Distinct().Count(), (int)response.AggregationPayload["Bool"], "Bool same distinct count");
        }
예제 #6
0
        public void TestListSimpleSearch()
        {
            var dataSource = new List<Thing>
            {
                new Thing { Name= SearchText + "1" },
                new Thing { Name= SearchText.ToLower() + "2" },
                new Thing { Name= SearchText.ToUpper() + "3" },
                new Thing { Name= SearchText + "4" },
                new Thing { Name= "ODOR" }
            };

            var data = dataSource.Where(x => x.Name.ToLowerInvariant().Contains(SearchText.ToLowerInvariant())).Take(PageSize).ToList();

            var request = new GridDataRequest()
            {
                Take = PageSize,
                Skip = 0,
                Search = new Filter()
                {
                    Operator = CompareOperators.Auto,
                    Text = SearchText
                },
                Columns = Thing.GetColumns()
            };

            var response = request.CreateGridDataResponse(dataSource.AsQueryable());

            Assert.AreEqual(data.Count, response.Payload.Count, "Same length");
            Assert.AreEqual(data.First().Id, response.Payload.First().First(), "Same first item");

            Assert.AreEqual(dataSource.Count(x => x.Name.ToLowerInvariant().Contains(SearchText.ToLowerInvariant())), response.FilteredRecordCount, "Total filtered rows matching");
        }