Example #1
0
        public void Test_KendoGridModelBinder_One_GroupBy_WithIncludes()
        {
            var form = new NameValueCollection
            {
                { "take", "5" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "5" },

                { "group[0][field]", "CountryName" },
                { "group[0][dir]", "asc" }
            };

            var gridRequest = SetupBinder(form, null);

            Assert.AreEqual(1, gridRequest.GroupObjects.Count());
            Assert.AreEqual(0, gridRequest.GroupObjects.First().AggregateObjects.Count());

            InitAutoMapper();
            var employees = InitEmployeesWithData().AsQueryable();
            var mappings  = new Dictionary <string, MapExpression <Employee> >
            {
                { "CompanyId", new MapExpression <Employee> {
                      Path = "Company.Id", Expression = m => m.Company.Id
                  } },
                { "CompanyName", new MapExpression <Employee> {
                      Path = "Company.Name", Expression = m => m.Company.Name
                  } },
                { "CountryName", new MapExpression <Employee> {
                      Path = "Country.Name", Expression = m => m.Country.Name
                  } }
            };
            var kendoGrid = new KendoGridEx <Employee, EmployeeVM>(gridRequest, employees, new[] { "Company", "Company.MainCompany", "Country" }, mappings, null, false);

            Assert.IsNull(kendoGrid.Data);
            Assert.IsNotNull(kendoGrid.Groups);
            var json = JsonConvert.SerializeObject(kendoGrid.Groups, Formatting.Indented);

            Assert.IsNotNull(json);

            var groups = kendoGrid.Groups as List <KendoGroup>;

            Assert.IsNotNull(groups);

            Assert.AreEqual(2, groups.Count());
            Assert.AreEqual(employees.Count(), kendoGrid.Total);

            var employeesFromFirstGroup = groups.First().items as IEnumerable <EmployeeVM>;

            Assert.IsNotNull(employeesFromFirstGroup);

            var employeesFromFirstGroupList = employeesFromFirstGroup.ToList();

            Assert.AreEqual(4, employeesFromFirstGroupList.Count);

            var testEmployee = employeesFromFirstGroupList.First();

            Assert.AreEqual("Belgium", testEmployee.CountryName);
            Assert.AreEqual("B", testEmployee.CompanyName);
        }
        public void Test_KendoGridModelBinder_Aggregates_WithIncludes()
        {
            var form = new NameValueCollection
            {
                { "take", "5" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "5" },

                { "aggregate[0][field]", "Id" },
                { "aggregate[0][aggregate]", "sum" },
                { "aggregate[1][field]", "Id" },
                { "aggregate[1][aggregate]", "min" },
                { "aggregate[2][field]", "Id" },
                { "aggregate[2][aggregate]", "max" },
                { "aggregate[3][field]", "Id" },
                { "aggregate[3][aggregate]", "count" },
                { "aggregate[4][field]", "Id" },
                { "aggregate[4][aggregate]", "average" }
            };

            var gridRequest = SetupBinder(form, null);

            Assert.IsNull(gridRequest.GroupObjects);
            Assert.AreEqual(5, gridRequest.AggregateObjects.Count());


            InitAutoMapper();
            var employees = InitEmployeesWithData().AsQueryable();
            var mappings  = new Dictionary <string, string> {
                { "CompanyId", "Company.Id" }, { "CountryName", "Country.Name" }
            };
            var kendoGrid = new KendoGridEx <Employee, EmployeeVM>(gridRequest, employees, new[] { "Company", "Company.MainCompany", "Country" }, mappings, null, false);

            Assert.IsNull(kendoGrid.Groups);
            Assert.IsNotNull(kendoGrid.Data);
            Assert.AreEqual(5, kendoGrid.Data.Count());

            Assert.IsNotNull(kendoGrid.Aggregates);
            var json = JsonConvert.SerializeObject(kendoGrid.Aggregates, Formatting.Indented);

            Assert.IsNotNull(json);

            var aggregatesAsDictionary = kendoGrid.Aggregates as Dictionary <string, Dictionary <string, object> >;

            Assert.IsNotNull(aggregatesAsDictionary);
            Assert.AreEqual(1, aggregatesAsDictionary.Keys.Count);
            Assert.AreEqual("Id", aggregatesAsDictionary.Keys.First());

            var aggregatesForId = aggregatesAsDictionary["Id"];

            Assert.AreEqual(5, aggregatesForId.Keys.Count);
            Assert.AreEqual(78, aggregatesForId["sum"]);
            Assert.AreEqual(1, aggregatesForId["min"]);
            Assert.AreEqual(12, aggregatesForId["max"]);
            Assert.AreEqual(12, aggregatesForId["count"]);
            Assert.AreEqual(6.5d, aggregatesForId["average"]);
        }
Example #3
0
        public void Test_KendoGridModelBinder_Aggregates_WithIncludes_NoResults()
        {
            var form = new NameValueCollection
            {
                { "take", "5" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "5" },

                { "filter[filters][0][field]", "LastName" },
                { "filter[filters][0][operator]", "equals" },
                { "filter[filters][0][value]", "xxx" },
                { "filter[filters][1][field]", "Email" },
                { "filter[filters][1][operator]", "contains" },
                { "filter[filters][1][value]", "r" },
                { "filter[logic]", "or" },

                { "aggregate[0][field]", "Id" },
                { "aggregate[0][aggregate]", "sum" },
                { "aggregate[1][field]", "Id" },
                { "aggregate[1][aggregate]", "min" },
                { "aggregate[2][field]", "Id" },
                { "aggregate[2][aggregate]", "max" },
                { "aggregate[3][field]", "Id" },
                { "aggregate[3][aggregate]", "count" },
                { "aggregate[4][field]", "Id" },
                { "aggregate[4][aggregate]", "average" }
            };

            var gridRequest = SetupBinder(form, null);

            Assert.IsNull(gridRequest.GroupObjects);
            Assert.AreEqual(5, gridRequest.AggregateObjects.Count());

            InitAutoMapper();
            var employees = InitEmployeesWithData().AsQueryable();
            var mappings  = new Dictionary <string, string> {
                { "CompanyId", "Company.Id" }, { "CountryName", "Country.Name" }
            };
            var kendoGrid = new KendoGridEx <Employee, EmployeeVM>(gridRequest, employees, new[] { "Company", "Company.MainCompany", "Country" }, mappings, null, false);

            Assert.IsNull(kendoGrid.Groups);
            Assert.IsNotNull(kendoGrid.Data);
            Assert.AreEqual(0, kendoGrid.Data.Count());

            Assert.IsNotNull(kendoGrid.Aggregates);
            var json = JsonConvert.SerializeObject(kendoGrid.Aggregates, Formatting.Indented);

            Assert.IsNotNull(json);

            var aggregatesAsDictionary = kendoGrid.Aggregates as Dictionary <string, Dictionary <string, object> >;

            Assert.IsNotNull(aggregatesAsDictionary);
            Assert.AreEqual(0, aggregatesAsDictionary.Keys.Count);
        }
        public void Test_KendoGridModelBinder_Grid_Page_Filter_Sort()
        {
            var form = new NameValueCollection
            {
                {"take", "5"},
                {"skip", "0"},
                {"page", "1"},
                {"pagesize", "5"},

                {"sort[0][field]", "First"},
                {"sort[0][dir]", "asc"},
                {"sort[1][field]", "Email"},
                {"sort[1][dir]", "desc"},

                {"filter[filters][0][logic]", "or"},
                {"filter[filters][0][filters][0][field]", "CompanyName"},
                {"filter[filters][0][filters][0][operator]", "eq"},
                {"filter[filters][0][filters][0][value]", "A"},
                {"filter[filters][0][filters][1][field]", "CompanyName"},
                {"filter[filters][0][filters][1][operator]", "contains"},
                {"filter[filters][0][filters][1][value]", "B"},

                {"filter[filters][1][field]", "Last"},
                {"filter[filters][1][operator]", "contains"},
                {"filter[filters][1][value]", "s"},
                {"filter[logic]", "and"}
            };

            var gridRequest = SetupBinder(form, null);

            InitAutoMapper();
            var employees = InitEmployees();
            var kendoGrid = new KendoGridEx<Employee, EmployeeVM>(gridRequest, employees);
            Assert.IsNotNull(kendoGrid);

            Assert.AreEqual(11, kendoGrid.Total);
            Assert.IsNotNull(kendoGrid.Data);
            Assert.AreEqual(4, kendoGrid.Data.Count());

            Assert.AreEqual("Bill Smith", kendoGrid.Data.First().Full);
            Assert.AreEqual("Jack Smith", kendoGrid.Data.Last().Full);

            var query = kendoGrid.AsQueryable();
            Assert.AreEqual("Bill Smith", query.First().FullName);
            Assert.AreEqual("Jack Smith", query.Last().FullName);
        }
        public void Test_KendoGridModelBinder_Grid_Page()
        {
            var form = new NameValueCollection
            {
                {"take", "5"},
                {"skip", "0"},
                {"page", "1"},
                {"pagesize", "5"}
            };

            var gridRequest = SetupBinder(form, null);

            InitAutoMapper();
            var employees = InitEmployees().AsQueryable();
            var kendoGrid = new KendoGridEx<Employee, EmployeeVM>(gridRequest, employees);
            Assert.IsNotNull(kendoGrid);

            Assert.AreEqual(employees.Count(), kendoGrid.Total);
            Assert.IsNotNull(kendoGrid.Data);
            Assert.AreEqual(5, kendoGrid.Data.Count());
        }
        public void Test_KendoGridModelBinder_Group()
        {
            var form = new NameValueCollection
            {
                {"take", "5"},
                {"skip", "0"},
                {"page", "1"},
                {"pagesize", "5"},

                {"group[0][field]", "First"},
                {"group[0][dir]", "asc"},
                {"group[1][field]", "Last"},
                {"group[1][dir]", "asc"}
            };

            var gridRequest = SetupBinder(form, null);
            Assert.AreEqual(2, gridRequest.GroupObjects.Count());
            Assert.AreEqual(0, gridRequest.GroupObjects.First().AggregateObjects.Count());

            InitAutoMapper();
            var employees = InitEmployees();
            var kendoGrid = new KendoGridEx<Employee, EmployeeVM>(gridRequest, employees);

            Assert.IsNull(kendoGrid.Data);
            Assert.IsNotNull(kendoGrid.Groups);
            var json = JsonConvert.SerializeObject(kendoGrid.Groups, Formatting.Indented);
            Assert.IsNotNull(json);

            var groups = kendoGrid.Groups as List<KendoGroup>;
            Assert.IsNotNull(groups);

            Assert.AreEqual(5, groups.Count());
            Assert.AreEqual(11, kendoGrid.Total);
        }