Пример #1
0
        public void Get_instructor_list_with_select_new()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = null,
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Contoso.Domain.Entities.InstructorModel",
                DataType  = "Contoso.Data.Entities.Instructor",
                Includes  = null,
                Selects   = new Dictionary <string, string> {
                    ["id"] = "id", ["fullName"] = "fullName"
                },
                Distinct = false
            };

            ISchoolRepository     repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            IEnumerable <dynamic> result     = Task.Run(() => request.InvokeGenericMethod <IEnumerable <dynamic> >("GetDynamicSelect", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal("Roger Zheng", result.First().fullName);
        }
Пример #2
0
        public void Get_departments_ungrouped_with_aggregates_and_includes()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = "administratorName-min~name-count~budget-sum~budget-min~startDate-min",
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Contoso.Domain.Entities.DepartmentModel",
                DataType  = "Contoso.Data.Entities.Department",
                Includes  = new string[] { "administratorName" },
                Selects   = null,
                Distinct  = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", 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("Min", result.AggregateResults.First().AggregateMethodName);
            Assert.Equal("Candace Kapoor", (string)result.AggregateResults.First().Value);
        }
Пример #3
0
        public void Get_lookup_list_with_select_new()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = null,
                    Filter    = "listName~eq~'residentstates'",
                    Group     = null,
                    Page      = 0,
                    Sort      = "value-asc",
                    PageSize  = 0
                },
                ModelType = "Enrollment.Domain.Entities.LookUpsModel",
                DataType  = "Enrollment.Data.Entities.LookUps",
                Includes  = null,
                Selects   = new Dictionary <string, string> {
                    ["value"] = "value", ["text"] = "text", ["listName"] = "listName"
                },
                Distinct = false
            };

            IEnrollmentRepository repository = serviceProvider.GetRequiredService <IEnrollmentRepository>();
            IEnumerable <dynamic> result     = Task.Run(() => request.InvokeGenericMethod <IEnumerable <dynamic> >("GetDynamicSelect", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal("AK", result.First().value);
            Assert.Equal(60, result.Count());
        }
Пример #4
0
        public void Get_lookUps_grouped_with_aggregates()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    //Queryable.Min<TSource, string> throws System.ArgumentException against In-Memory DB
                    //Aggregate = "listName-count~value-min",
                    Aggregate = "listName-count~booleanValue-min",
                    Filter    = null,
                    Group     = "listName-asc",
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Enrollment.Domain.Entities.LookUpsModel",
                DataType  = "Enrollment.Data.Entities.LookUps",
                Includes  = null,
                Selects   = null,
                Distinct  = false
            };

            IEnrollmentRepository repository = serviceProvider.GetRequiredService <IEnrollmentRepository>();
            DataSourceResult      result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal(466, result.Total);
            Assert.Equal(2, ((IEnumerable <AggregateFunctionsGroupModel <LookUpsModel> >)result.Data).Count());
            Assert.Equal(2, result.AggregateResults.Count());
            Assert.Equal("Count", result.AggregateResults.First().AggregateMethodName);
            Assert.Equal(466, (int)result.AggregateResults.First().Value);
        }
Пример #5
0
        public void Get__single_student_with_navigation_property_of_navigation_property()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = null,
                    Filter    = "id~eq~3",
                    Group     = null,
                    Page      = 0,
                    Sort      = null,
                    PageSize  = 0
                },
                ModelType = "Contoso.Domain.Entities.StudentModel",
                DataType  = "Contoso.Data.Entities.Student",
                Includes  = new string[] { "enrollments.courseTitle" },
                Selects   = null,
                Distinct  = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            StudentModel      result     = (StudentModel)Task.Run(() => request.InvokeGenericMethod <BaseModelClass>("GetSingle", repository)).Result;

            Assert.Equal("Chemistry", result.Enrollments.First().CourseTitle);
            Assert.Equal("Arturo Anand", result.FullName);
        }
Пример #6
0
        public void Get_students_ungrouped_with_aggregates()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = "lastName-count~enrollmentDate-min",
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Contoso.Domain.Entities.StudentModel",
                DataType  = "Contoso.Data.Entities.Student",
                Includes  = null,
                Selects   = null,
                Distinct  = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal(11, result.Total);
            Assert.Equal(5, ((IEnumerable <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);
        }
Пример #7
0
        public void Get_single_student_with_navigation_property_of_navigation_property()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = null,
                    Filter    = "id~eq~3",
                    Group     = null,
                    Page      = 0,
                    Sort      = null,
                    PageSize  = 0
                },
                ModelType = "Contoso.Domain.Entities.StudentModel",
                DataType  = "Contoso.Data.Entities.Student",
                SelectExpandDefinition = new SelectExpandDefinitionView
                {
                    ExpandedItems = new List <SelectExpandItemView>
                    {
                        new SelectExpandItemView
                        {
                            MemberName = "enrollments"
                        }
                    }
                },
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            StudentModel      result     = (StudentModel)Task.Run(() => request.InvokeGenericMethod <BaseModelClass>("GetSingle", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal("Chemistry", result.Enrollments.First(e => !e.Grade.HasValue).CourseTitle);
            Assert.Equal("Arturo Anand", result.FullName);
        }
Пример #8
0
        public void Get_single_department()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = null,
                    Filter    = "departmentID~eq~2",
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Contoso.Domain.Entities.DepartmentModel",
                DataType  = "Contoso.Data.Entities.Department",
                Includes  = null,
                Selects   = null,
                Distinct  = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DepartmentModel   result     = (DepartmentModel)Task.Run(() => request.InvokeGenericMethod <BaseModelClass>("GetSingle", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal("Mathematics", result.Name);
        }
Пример #9
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
                },
                ModelType = "Contoso.Domain.Entities.InstructorModel",
                DataType  = "Contoso.Data.Entities.Instructor",
                Selects   = null,
                Distinct  = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            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);
        }
Пример #10
0
        public void Get_courses_ungrouped_with_aggregates()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = "credits-sum",
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Contoso.Domain.Entities.CourseModel",
                DataType  = "Contoso.Data.Entities.Course",
                //Includes = new string[] { "departmentName" },
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal(7, result.Total);
            Assert.Equal(5, ((IEnumerable <CourseModel>)result.Data).Count());
            Assert.Single(result.AggregateResults);
            Assert.Equal("Calculus", ((IEnumerable <CourseModel>)result.Data).First().Title);
        }
Пример #11
0
        public void Get_departments_grouped_with_aggregates()
        {
            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     = "budget-asc",
                    Page      = 1,
                    Sort      = null,
                    PageSize  = 5
                },
                ModelType = "Contoso.Domain.Entities.DepartmentModel",
                DataType  = "Contoso.Data.Entities.Department",
                Includes  = null,
                Selects   = null,
                Distinct  = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal(4, result.Total);
            Assert.Equal(2, ((IEnumerable <AggregateFunctionsGroupModel <DepartmentModel> >)result.Data).Count());
            Assert.Equal(5, result.AggregateResults.Count());
            //Queryable.Min<TSource, string> throws System.ArgumentException against In-Memory DB
            //Assert.Equal("Min", result.AggregateResults.First().AggregateMethodName);
            //Assert.Equal("Candace Kapoor", (string)result.AggregateResults.First().Value);
        }
Пример #12
0
 public async Task <IActionResult> GetSingle([FromBody] DataRequest request)
 {
     try
     {
         return(Json
                (
                    await request.InvokeGenericMethod <BaseModelClass>("GetSingle", this._schoolRepository, this._mapper)
                ));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #13
0
 public async Task <IActionResult> GetFilterData([FromBody] DataRequest request)
 {
     try
     {
         return(Json
                (
                    await request.InvokeGenericMethod <IEnumerable <dynamic> >("GetDynamicSelect", this._schoolRepository, this._mapper)
                ));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #14
0
 public async Task <IActionResult> GetData([FromBody] DataRequest request)
 {
     try
     {
         return(Json
                (
                    await request.InvokeGenericMethod <DataSourceResult>("GetData", this._enrollmentRepository, this._mapper)
                ));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #15
0
 public async Task <IActionResult> GetData([FromBody] DataRequest request)
 {
     try
     {
         return(Json
                (
                    await Task.Run
                    (
                        () => request.InvokeGenericMethod <DataSourceResult>("GetData", this._schoolRepository)
                    )
                ));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #16
0
        public void Get_single_user_with_navigation_property_of_navigation_property()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    Aggregate = null,
                    Filter    = "userID~eq~1",
                    Group     = null,
                    Page      = 0,
                    Sort      = null,
                    PageSize  = 0
                },
                ModelType = "Enrollment.Domain.Entities.UserModel",
                DataType  = "Enrollment.Data.Entities.User",
                //Includes = new string[] { "residency.statesLivedIn" },
                SelectExpandDefinition = new SelectExpandDefinitionView
                {
                    ExpandedItems = new List <SelectExpandItemView>
                    {
                        new SelectExpandItemView
                        {
                            MemberName    = "residency",
                            ExpandedItems = new List <SelectExpandItemView>
                            {
                                new SelectExpandItemView
                                {
                                    MemberName = "statesLivedIn"
                                }
                            }
                        }
                    }
                },
                Selects  = null,
                Distinct = false
            };

            IEnrollmentRepository repository = serviceProvider.GetRequiredService <IEnrollmentRepository>();
            UserModel             result     = (UserModel)Task.Run(() => request.InvokeGenericMethod <BaseModelClass>("GetSingle", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal(2, result.Residency.StatesLivedIn.Count());
            Assert.Equal("ForeignStudent01", result.UserName);
        }
Пример #17
0
        public void Get_residency_ungrouped_with_aggregates_and_includes()
        {
            DataRequest request = new DataRequest
            {
                Options = new DataSourceRequestOptions
                {
                    //Queryable.Min<TSource, string> throws System.ArgumentException against In-Memory DB
                    //Aggregate = "citizenshipStatus-count~countryOfCitizenship-min",
                    Aggregate = "citizenshipStatus-count~countryOfCitizenship-count",
                    Filter    = null,
                    Group     = null,
                    Page      = 1,
                    Sort      = "citizenshipStatus-asc",
                    PageSize  = 5
                },
                ModelType = "Enrollment.Domain.Entities.ResidencyModel",
                DataType  = "Enrollment.Data.Entities.Residency",
                //Includes = new string[] { "StatesLivedIn" },
                SelectExpandDefinition = new SelectExpandDefinitionView
                {
                    ExpandedItems = new List <SelectExpandItemView>
                    {
                        new SelectExpandItemView
                        {
                            MemberName = "StatesLivedIn"
                        }
                    }
                },
                Selects  = null,
                Distinct = false
            };

            IEnrollmentRepository repository = serviceProvider.GetRequiredService <IEnrollmentRepository>();
            DataSourceResult      result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).Result;

            Assert.Equal(2, result.Total);
            Assert.Equal(2, ((IEnumerable <ResidencyModel>)result.Data).Count());
            Assert.Equal(2, result.AggregateResults.Count());
            Assert.Equal("AA", ((IEnumerable <ResidencyModel>)result.Data).First().CountryOfCitizenship);
            Assert.Equal("Count", result.AggregateResults.First().AggregateMethodName);
            Assert.Equal(2, (int)result.AggregateResults.First().Value);
        }
Пример #18
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
                },
                ModelType = "Contoso.Domain.Entities.InstructorModel",
                DataType  = "Contoso.Data.Entities.Instructor",
                SelectExpandDefinition = new SelectExpandDefinitionView
                {
                    ExpandedItems = new List <SelectExpandItemView>
                    {
                        new SelectExpandItemView
                        {
                            MemberName = "courses"
                        },
                        new SelectExpandItemView
                        {
                            MemberName = "officeAssignment"
                        }
                    }
                },
                Selects  = null,
                Distinct = false
            };

            ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>();
            DataSourceResult  result     = Task.Run(() => request.InvokeGenericMethod <DataSourceResult>("GetData", repository, serviceProvider.GetRequiredService <IMapper>())).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);
        }