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 = 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
                  } }
            };


            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, null, mappings);

            Assert.IsNotNull(kendoGrid);

            Assert.AreEqual(4, 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_One_GroupBy_WithoutIncludes()
        {
            var form = new NameValueCollection
            {
                { "take", "5" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "5" },

                { "group[0][field]", "LastName" },
                { "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   = InitEmployees().AsQueryable();
            var employeeVMs = _mapper.Map <List <EmployeeVM> >(employees.ToList());

            Assert.IsNotNull(employeeVMs);

            var mappings = new Dictionary <string, MapExpression <Employee> >
            {
                { "CompanyId", new MapExpression <Employee> {
                      Path = "Company.Id", Expression = m => m.Company.Id
                  } }
            };

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, null, mappings);

            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(employees.Count(), kendoGrid.Total);

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

            Assert.IsNotNull(employeesFromFirstGroup);

            var employeesFromFirstGroupList = employeesFromFirstGroup.ToList();

            Assert.AreEqual(1, employeesFromFirstGroupList.Count);

            var testEmployee = employeesFromFirstGroupList.First();

            Assert.IsNull(testEmployee.CountryName);
        }
Esempio n. 3
0
        public EmployeeController(IEmployeeService employeeService, ICompanyService companyService, IFunctionService functionService, ISubFunctionService subfunctionService, ICountryService countryService)
            : base(employeeService)
        {
            _employeeService    = employeeService;
            _companyService     = companyService;
            _functionService    = functionService;
            _subfunctionService = subfunctionService;
            _countryService     = countryService;

            _employeeValidator        = new EmployeeValidator(_employeeService);
            _kendoGridQueryableHelper = new KendoGridQueryableHelper(AutoMapperConfig.MapperConfiguration);
        }
        public void Test_KendoGridModelBinder_A()
        {
            var form = new NameValueCollection
            {
                { "take", "10" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "10" },

                { "group[0][field]", "Id" },
                { "group[0][dir]", "asc" },
                { "group[0][aggregates][0][field]", "Id" },
                { "group[0][aggregates][0][aggregate]", "count" }
            };

            var gridRequest = SetupBinder(form, null);

            Assert.AreEqual(1, gridRequest.GroupObjects.Count());
            Assert.AreEqual(1, gridRequest.GroupObjects.First().AggregateObjects.Count());
            Assert.AreEqual(1, gridRequest.GroupObjects.Last().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
                  } }
            };

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, null, mappings);

            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(10, groups.Count());
            Assert.AreEqual(employees.Count(), kendoGrid.Total);
        }
        public void Test_KendoGridModelBinder_Json_Filter()
        {
            var form = new NameValueCollection
            {
                { "take", "5" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "5" },

                { "group", "[]" },
                //{"filter", "{\"logic\":\"and\",\"filters\":[{\"field\":\"CompanyName\",\"operator\":\"eq\",\"value\":\"A\"}]}"},
                { "filter", "{\"logic\":\"and\",\"filters\":[{\"logic\":\"or\",\"filters\":[{\"field\":\"LastName\",\"operator\":\"contains\",\"value\":\"s\"},{\"field\":\"LastName\",\"operator\":\"endswith\",\"value\":\"ll\"}]},{\"field\":\"FirstName\",\"operator\":\"startswith\",\"value\":\"n\"}]}" },
                { "sort", "[{\"field\":\"FirstName\",\"dir\":\"asc\",\"compare\":null},{\"field\":\"LastName\",\"dir\":\"desc\",\"compare\":null}]" }
            };

            var gridRequest = SetupBinder(form, null);

            Assert.IsNull(gridRequest.GroupObjects);

            InitAutoMapper();
            var employees   = InitEmployees().AsQueryable();
            var employeeVMs = _mapper.Map <List <EmployeeVM> >(employees.ToList());

            Assert.IsNotNull(employeeVMs);

            var mappings = new Dictionary <string, MapExpression <Employee> >
            {
                { "CompanyId", new MapExpression <Employee> {
                      Path = "Company.Id", Expression = m => m.Company.Id
                  } }
            };

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, null, mappings);

            Assert.IsNotNull(kendoGrid);
            Assert.IsNull(kendoGrid.Groups);
            Assert.NotNull(kendoGrid.Data);

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

                { "sort[0][field]", "Full" },
                { "sort[0][dir]", "asc" },

                { "group[0][field]", "First" },
                { "group[0][dir]", "asc" },
                { "group[0][aggregates][0][field]", "First" },
                { "group[0][aggregates][0][aggregate]", "count" }
            };

            var gridRequest = SetupBinder(form, null);

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

            InitAutoMapper();
            var employees = InitEmployeesWithData().AsQueryable();

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest);

            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(employees.Count(), kendoGrid.Total);
        }
        //{"take":5,"skip":0,"page":1,"pageSize":5,"group":[]}
        public void Test_KendoGridModelBinder_Json_WithoutIncludes()
        {
            var form = new NameValueCollection
            {
                { "take", "5" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "5" },

                { "group", "[]" }
            };

            var gridRequest = SetupBinder(form, null);

            Assert.IsNull(gridRequest.GroupObjects);

            InitAutoMapper();
            var employees   = InitEmployees().AsQueryable();
            var employeeVMs = _mapper.Map <List <EmployeeVM> >(employees.ToList());

            Assert.IsNotNull(employeeVMs);

            var mappings = new Dictionary <string, MapExpression <Employee> >
            {
                { "CompanyId", new MapExpression <Employee> {
                      Path = "Company.Id", Expression = m => m.Company.Id
                  } }
            };

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, null, mappings);

            Assert.IsNotNull(kendoGrid);
            Assert.IsNull(kendoGrid.Groups);
            Assert.NotNull(kendoGrid.Data);

            Assert.AreEqual(employees.Count(), kendoGrid.Total);
            Assert.IsNotNull(kendoGrid.Data);
            Assert.AreEqual(5, kendoGrid.Data.Count());
        }
        public void Test_KendoGridModelBinder_Grid_Sort_Filter_EntitiesWithNullValues()
        {
            var form = new NameValueCollection
            {
                { "sort[0][field]", "Id" },
                { "sort[0][dir]", "asc" },

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

            var gridRequest = SetupBinder(form, null);

            var employeeList = InitEmployeesWithData().ToList();

            foreach (var employee in employeeList.Where(e => e.LastName.Contains("e")))
            {
                employee.LastName  = null;
                employee.FirstName = null;
            }

            var employees = employeeList.AsQueryable();

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest);

            Assert.IsNotNull(kendoGrid);

            Assert.AreEqual(3, kendoGrid.Total);
            Assert.IsNotNull(kendoGrid.Data);
        }
        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 = InitEmployeesWithData().AsQueryable();

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest);

            Assert.IsNotNull(kendoGrid);

            Assert.AreEqual(employees.Count(), kendoGrid.Total);
            Assert.IsNotNull(kendoGrid.Data);
            Assert.AreEqual(5, kendoGrid.Data.Count());
        }
        //{"take":5,"skip":0,"page":1,"pageSize":5,"group":[{"field":"LastName","dir":"asc","aggregates":["field":"Number","aggregate":"Sum"]}]}
        public void Test_KendoGridModelBinder_Json_One_GroupBy_One_Aggregate_Sum()
        {
            var form = new NameValueCollection
            {
                { "take", "10" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "10" },

                { "group", "[{\"field\":\"LastName\",\"dir\":\"asc\",\"aggregates\":[{\"field\":\"Number\",\"aggregate\":\"sum\"}]}]" }
            };

            var gridRequest = SetupBinder(form, null);

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

            InitAutoMapper();
            var employees = InitEmployeesWithData().AsQueryable();

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest);

            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(9, groups.Count());
            Assert.AreEqual(employees.Count(), kendoGrid.Total);

            var groupBySmith = groups.FirstOrDefault(g => g.value.ToString() == "Smith");

            Assert.IsNotNull(groupBySmith);

            var items = groupBySmith.items as List <EmployeeVM>;

            Assert.IsNotNull(items);
            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(2, items.Count(e => e.Last == "Smith"));

            var aggregates = groupBySmith.aggregates as Dictionary <string, Dictionary <string, object> >;

            Assert.IsNotNull(aggregates);

            Assert.IsTrue(aggregates.ContainsKey("Number"));
            var aggregatesNumber = aggregates["Number"];

            Assert.IsNotNull(aggregatesNumber);
            Assert.AreEqual(1, aggregatesNumber.Count);

            var aggregateSum = aggregatesNumber.First();

            Assert.IsNotNull(aggregateSum);
            Assert.AreEqual("sum", aggregateSum.Key);
            Assert.AreEqual(2003, aggregateSum.Value);
        }
        public void Test_KendoGridModelBinder_Two_GroupBy_One_Aggregate_Min()
        {
            var form = new NameValueCollection
            {
                { "take", "10" },
                { "skip", "0" },
                { "page", "1" },
                { "pagesize", "10" },

                { "group[0][field]", "CompanyName" },
                { "group[0][dir]", "asc" },
                { "group[0][aggregates][0][field]", "Number" },
                { "group[0][aggregates][0][aggregate]", "min" },

                { "group[1][field]", "LastName" },
                { "group[1][dir]", "asc" },
                { "group[1][aggregates][0][field]", "Number" },
                { "group[1][aggregates][0][aggregate]", "min" },
            };

            var gridRequest = SetupBinder(form, null);

            Assert.AreEqual(2, gridRequest.GroupObjects.Count());
            Assert.AreEqual(1, gridRequest.GroupObjects.First().AggregateObjects.Count());
            Assert.AreEqual(1, gridRequest.GroupObjects.Last().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
                  } }
            };

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, null, mappings);

            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(10, groups.Count());
            Assert.AreEqual(employees.Count(), kendoGrid.Total);

            /*
             * var groupBySmith = groups.FirstOrDefault(g => g.value.ToString() == "Smith");
             * Assert.IsNotNull(groupBySmith);
             *
             * var items = groupBySmith.items as List<EmployeeVM>;
             * Assert.IsNotNull(items);
             * Assert.AreEqual(2, items.Count);
             * Assert.AreEqual(2, items.Count(e => e.Last == "Smith"));
             *
             * var aggregates = groupBySmith.aggregates as Dictionary<string, Dictionary<string, object>>;
             * Assert.IsNotNull(aggregates);
             *
             * Assert.IsTrue(aggregates.ContainsKey("Number"));
             * var aggregatesNumber = aggregates["Number"];
             * Assert.IsNotNull(aggregatesNumber);
             * Assert.AreEqual(1, aggregatesNumber.Count);
             *
             * var aggregateSum = aggregatesNumber.First();
             * Assert.IsNotNull(aggregateSum);
             * Assert.AreEqual("sum", aggregateSum.Key);
             * Assert.AreEqual(2003, aggregateSum.Value);
             */
        }
        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, 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
                  } }
            };

            _instanceUnderTest = new KendoGridQueryableHelper(_mapperConfiguration);
            var kendoGrid = _instanceUnderTest.ToKendoGridEx <Employee, EmployeeVM>(employees, gridRequest, new[] { "Company", "Company.MainCompany", "Country" }, mappings);

            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);
        }
Esempio n. 13
0
 public EmployeeApiController()
 {
     _employeeService          = UnityBootstrapper.Container.Resolve <IEmployeeService>();
     _kendoGridQueryableHelper = new KendoGridQueryableHelper(AutoMapperConfig.MapperConfiguration);
 }
Esempio n. 14
0
 protected BaseMvcGridController(IBaseService <TEntity> service) : base(service)
 {
     _kendoGridExQueryableHelper = new KendoGridQueryableHelper(AutoMapperConfig.MapperConfiguration);
 }
Esempio n. 15
0
 public OUController(IOUService service)
     : base(service)
 {
     _ouService = service;
     _kendoGridQueryableHelper = new KendoGridQueryableHelper(AutoMapperConfig.MapperConfiguration);
 }