void DoTest <TModel, TData>(IExpressionParameter bodyParameter,
                                    IExpressionParameter queryFunc,
                                    SelectExpandDefinitionParameters expansion,
                                    string parameterName,
                                    Action <TModel, ISchoolRepository> update,
                                    Action <TModel> assert,
                                    string expectedExpressionString) where TModel : LogicBuilder.Domain.BaseModel where TData : LogicBuilder.Data.BaseData
        {
            //arrange
            IMapper              mapper              = serviceProvider.GetRequiredService <IMapper>();
            ISchoolRepository    repository          = serviceProvider.GetRequiredService <ISchoolRepository>();
            IExpressionParameter expressionParameter = GetFilterParameter <TModel>(bodyParameter, parameterName);

            TestExpressionString();
            TestReturnValue();

            void TestReturnValue()
            {
                //act
                TModel returnValue = ProjectionOperations <TModel, TData> .Get
                                     (
                    repository,
                    mapper,
                    expressionParameter,
                    queryFunc,
                    expansion
                                     );

                update(returnValue, repository);

                returnValue = ProjectionOperations <TModel, TData> .Get
                              (
                    repository,
                    mapper,
                    expressionParameter,
                    queryFunc,
                    expansion
                              );

                //assert
                assert(returnValue);
            }

            void TestExpressionString()
            {
                //act
                Expression <Func <TModel, bool> > expression = ProjectionOperations <TModel, TData> .GetFilter
                                                               (
                    mapper.MapToOperator(expressionParameter)
                                                               );

                //assert
                if (!string.IsNullOrEmpty(expectedExpressionString))
                {
                    AssertFilterStringIsCorrect(expression, expectedExpressionString);
                }
            }
        }
Example #2
0
 public static TModelReturn Query(IContextRepository repository,
                                  IMapper mapper,
                                  IExpressionParameter queryExpression,
                                  SelectExpandDefinitionParameters expansion = null)
 => repository.QueryAsync <TModel, TData, TModelReturn, TDataReturn>
 (
     GetQueryFunc(mapper.MapToOperator(queryExpression)),
     mapper.MapExpansion(expansion)
 ).Result;
Example #3
0
 public static ICollection <TModel> GetItems(IContextRepository repository,
                                             IMapper mapper,
                                             IExpressionParameter filterExpression      = null,
                                             IExpressionParameter queryFunc             = null,
                                             SelectExpandDefinitionParameters expansion = null)
 => repository.GetAsync <TModel, TData>
 (
     GetFilter(mapper.MapToOperator(filterExpression)),
     GetQueryFunc(mapper.MapToOperator(queryFunc)),
     mapper.MapExpansion(expansion)
 ).Result;
Example #4
0
 public static TModel Get(IContextRepository repository,
                          IMapper mapper,
                          IExpressionParameter filterExpression,
                          IExpressionParameter queryFunc             = null,
                          SelectExpandDefinitionParameters expansion = null)
 => GetItems
 (
     repository,
     mapper,
     filterExpression,
     queryFunc,
     expansion
 ).SingleOrDefault();
Example #5
0
        public RequestDetailsParameters
        (
            [ParameterEditorControl(ParameterControlType.TypeAutoComplete)]
            [NameValue(AttributeNames.DEFAULTVALUE, "Contoso.Domain.Entities")]
            [Comments("Fully qualified class name for the model type.")]
            string modelType,

            [ParameterEditorControl(ParameterControlType.TypeAutoComplete)]
            [NameValue(AttributeNames.DEFAULTVALUE, "Contoso.Data.Entities")]
            [Comments("Fully qualified class name for the data type.")]
            string dataType,

            string dataSourceUrl = "/api/Generic/GetData",
            string getUrl        = "/api/Generic/GetSingle",
            string addUrl        = "/api/Generic/Add",
            string updateUrl     = "/api/Generic/Update",
            string deleteUrl     = "/api/Generic/Delete",

            [ListEditorControl(ListControlType.HashSetForm)]
            [ParameterEditorControl(ParameterControlType.ParameterSourcedPropertyInput)]
            [NameValue(AttributeNames.PROPERTYSOURCEPARAMETER, "modelType")]
            string[] includes = null,

            [ListEditorControl(ListControlType.HashSetForm)]
            List <SelectParameters> selects = null,
            bool?distinct = null,

            [Comments("Defines and navigation properties to include in the edit model")]
            SelectExpandDefinitionParameters selectExpandDefinition = null
        )
        {
            ModelType              = modelType;
            DataType               = dataType;
            DataSourceUrl          = dataSourceUrl;
            GetUrl                 = getUrl;
            AddUrl                 = addUrl;
            UpdateUrl              = updateUrl;
            DeleteUrl              = deleteUrl;
            Includes               = includes;
            Selects                = selects?.ToDictionary(s => s.FieldName, s => s.SourceMember);
            Distinct               = distinct;
            SelectExpandDefinition = selectExpandDefinition;
        }
        public FormRequestDetailsParameters
        (
            [Comments("API end point to get the entity.")]
            [NameValue(AttributeNames.DEFAULTVALUE, "api/Entity/GetEntity")]
            string getUrl,

            [Comments("API end point to add the entity.")]
            [NameValue(AttributeNames.DEFAULTVALUE, "api/Student/Save")]
            string addUrl,

            [Comments("API end point to update the entity.")]
            [NameValue(AttributeNames.DEFAULTVALUE, "api/Student/Save")]
            string updateUrl,

            [Comments("API end point to update the entity.")]
            [NameValue(AttributeNames.DEFAULTVALUE, "api/Student/Delete")]
            string deleteUrl,

            [Comments("The model type for the object being requested. Click the function button and use the configured GetType function.  Use the Assembly qualified type name for the type argument.")]
            Type modelType,

            [Comments("The data type for the object being requested. Click the function button and use the configured GetType function.  Use the Assembly qualified type name for the type argument.")]
            Type dataType,

            [Comments("Defines the filter for the single object being edited - only applicable when the edit type is update.")]
            FilterLambdaOperatorParameters filter = null,

            [Comments("Defines and navigation properties to include in the edit model")]
            SelectExpandDefinitionParameters selectExpandDefinition = null
        )
        {
            GetUrl    = getUrl;
            AddUrl    = addUrl;
            UpdateUrl = updateUrl;
            DeleteUrl = deleteUrl;
            ModelType = modelType;
            DataType  = dataType;
            Filter    = filter;
            SelectExpandDefinition = selectExpandDefinition;
        }
Example #7
0
 public static SelectExpandDefinition MapExpansion(this IMapper mapper, SelectExpandDefinitionParameters expression)
 => mapper.MapExpansion
 (
     mapper.Map <SelectExpandDefinitionDescriptor>(expression)
 );