예제 #1
0
        public void Get_departments_ungrouped_with_aggregates_and_includes()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    //Queryable.Min<TSource, string> throws System.ArgumentException against In-Memory DB
                    //Aggregate = "administratorName-min~name-count~budget-sum~budget-min~startDate-min",
                    Aggregate = "administratorName-count~name-count~budget-sum~budget-min~startDate-min",
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                Includes = new string[] { "administratorName" },
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.GetData <DepartmentModel, Department>(repository)).Result;

            Assert.Equal(4, result.Total);
            Assert.Equal(4, ((IEnumerable <DepartmentModel>)result.Data).Count());
            Assert.Equal(5, result.AggregateResults.Count());
            Assert.Equal("Kim Abercrombie", ((IEnumerable <DepartmentModel>)result.Data).First().AdministratorName);
            Assert.Equal("Count", result.AggregateResults.First().AggregateMethodName);
            //Queryable.Min<TSource, string> throws System.ArgumentException against In - Memory DB
            // Assert.Equal("Candace Kapoor", (string)result.AggregateResults.First().Value);
        }
예제 #2
0
        public void Get_instructors_grouped_with_aggregates_without_includes()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = "lastName-count~hireDate-min",
                    Filter    = null,
                    Group     = "hireDate-asc",
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.GetData <InstructorModel, Instructor>(repository)).Result;
            var obj = ((IEnumerable <AggregateFunctionsGroupModel <InstructorModel> >)result.Data).First().Items.Cast <InstructorModel>().First();

            Assert.Equal(5, result.Total);
            Assert.Equal(5, ((IEnumerable <AggregateFunctionsGroupModel <InstructorModel> >)result.Data).Count());
            Assert.Empty(((IEnumerable <AggregateFunctionsGroupModel <InstructorModel> >)result.Data).First().Items.Cast <InstructorModel>().First().Courses);
            Assert.Null(((IEnumerable <AggregateFunctionsGroupModel <InstructorModel> >)result.Data).First().Items.Cast <InstructorModel>().First().OfficeAssignment);
            Assert.Equal(2, result.AggregateResults.Count());
            Assert.Equal("Count", result.AggregateResults.First().AggregateMethodName);
            Assert.Equal(5, (int)result.AggregateResults.First().Value);
        }
예제 #3
0
        public void Get_students_grouped_with_aggregates()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = "lastName-count~enrollmentDate-min",
                    Filter    = null,
                    Group     = "enrollmentDate-asc",
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                Includes = null,
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.GetData <StudentModel, Student>(repository)).Result;

            Assert.Equal(11, result.Total);
            Assert.Equal(3, ((IEnumerable <AggregateFunctionsGroupModel <StudentModel> >)result.Data).Count());
            Assert.Equal(2, result.AggregateResults.Count());
            Assert.Equal("Count", result.AggregateResults.First().AggregateMethodName);
            Assert.Equal(11, (int)result.AggregateResults.First().Value);
        }
예제 #4
0
        public void Get_instructors_ungrouped_with_aggregates()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = "lastName-count~hireDate-min",
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                SelectExpandDefinition = new SelectExpandDefinition
                {
                    ExpandedItems = new List <SelectExpandItem>
                    {
                        new SelectExpandItem
                        {
                            MemberName = "courses"
                        },
                        new SelectExpandItem
                        {
                            MemberName = "officeAssignment"
                        }
                    }
                },
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.GetData <InstructorModel, Instructor>(repository)).Result;

            Assert.Equal(5, result.Total);
            Assert.Equal(5, ((IEnumerable <InstructorModel>)result.Data).Count());
            Assert.Equal(2, result.AggregateResults.Count());
            Assert.Equal("Roger Zheng", ((IEnumerable <InstructorModel>)result.Data).First().FullName);
        }