public void TestSerializer() { List <QueryBuilderColumn> cols = new List <QueryBuilderColumn>(); List <QueryBuilderFilter> filters = new List <QueryBuilderFilter>(); List <QueryBuilderColumn> orderBy = new List <QueryBuilderColumn>(); cols.Add(MockColumn.Create("Category", "'Product Category'[Category]", typeof(string), ADOTabularObjectType.Column)); cols.Add(MockColumn.Create("Color", "'Product'[Color]", typeof(string), ADOTabularObjectType.Column)); filters.Add( new QueryBuilderFilter( MockColumn.CreateADOTabularColumn("Gender", "'Customer'[Gender]", typeof(string), ADOTabularObjectType.Column), modelCaps) { FilterType = FilterType.Is, FilterValue = "M" }); filters.Add( new QueryBuilderFilter( MockColumn.CreateADOTabularColumn("Color", "'Product'[Color]", typeof(string), ADOTabularObjectType.Column), modelCaps) { FilterType = FilterType.Is, FilterValue = "Red" }); orderBy.Add(MockColumn.Create("Category", "'Product Category'[Category]", typeof(string), ADOTabularObjectType.Column)); var qry = QueryBuilder.BuildQuery(modelCaps, cols, filters, orderBy); QueryBuilderViewModel vm = new QueryBuilderViewModel(new MockEventAggregator(), null, mockOptions); cols.ForEach(c => vm.Columns.Add(c)); filters.ForEach(f => vm.Filters.Add(f)); orderBy.ForEach(o => vm.OrderBy.Add(o)); var json = vm.GetJson(); var expectedJson = @"{}"; StringAssertion.ShouldEqualWithDiff(expectedJson, json, DiffStyle.Full); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { // Load the JSON for the Result into a JObject JObject jo = JObject.Load(reader); // Construct a dummy copy of the VM here so that we can populate the Columns, Filters and OrderBy collections var vm = new QueryBuilderViewModel(null, null, null); // Read the properties which will be used as constructor parameters foreach (var col in jo["Columns"].ToArray()) { IADOTabularColumn obj = col["TabularObject"].ToObject <ADOTabularColumnStub>(); bool isModelItem = (bool)col["IsModelItem"]; bool isOverridden = (bool)col["IsOverriden"]; string measureExpression = col["MeasureExpression"].ToString(); var queryBuilderCol = new QueryBuilderColumn(obj, isModelItem); queryBuilderCol.MeasureExpression = isOverridden?measureExpression:string.Empty; vm.Columns.Add(queryBuilderCol); } foreach (var filter in jo["Filters"]["Items"].ToArray()) { IADOTabularColumn obj = filter["TabularObject"].ToObject <ADOTabularColumnStub>(); FilterType filterType = filter["FilterType"].ToObject <FilterType>(); string filterValue = filter["FilterValue"].ToString(); string filterValue2 = filter["FilterValue2"].ToString(); IModelCapabilities modelCapabilities = filter["ModelCapabilities"].ToObject <ADOTabularModelCapabilities>(); var queryBuilderFilter = new QueryBuilderFilter(obj, modelCapabilities); queryBuilderFilter.FilterType = filterType; queryBuilderFilter.FilterValue = filterValue; queryBuilderFilter.FilterValue2 = filterValue2; vm.Filters.Add(queryBuilderFilter); } // Return the result return(vm); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { // Load the JSON for the Result into a JObject JObject jo = JObject.Load(reader); // Construct a dummy copy of the VM here so that we can populate the Columns, Filters and OrderBy collections var vm = new QueryBuilderViewModel(_eventAggregator, _document, _options); // Read the properties which will be used as constructor parameters foreach (var col in jo["Columns"].ToArray()) { IADOTabularColumn obj = col["TabularObject"].ToObject <ADOTabularColumnStub>(); bool isModelItem = (bool)col["IsModelItem"]; bool isOverridden = (bool)col["IsOverriden"]; SortDirection sortDirection = SortDirection.ASC; var _ = Enum.TryParse(col["SortDirection"].ToString(), out sortDirection); string measureExpression = col["MeasureExpression"].ToString(); string measureCaption = col["Caption"].ToString(); var queryBuilderCol = new QueryBuilderColumn(obj, isModelItem, _eventAggregator); queryBuilderCol.MeasureExpression = isOverridden?measureExpression:string.Empty; queryBuilderCol.SortDirection = sortDirection; if (isOverridden) { queryBuilderCol.Caption = measureCaption; } vm.Columns.Add(queryBuilderCol); } foreach (var filter in jo["Filters"]["Items"].ToArray()) { IADOTabularColumn obj = filter["TabularObject"].ToObject <ADOTabularColumnStub>(); FilterType filterType = filter["FilterType"].ToObject <FilterType>(); string filterValue = filter["FilterValue"].ToString(); var filterValueIsParameterToken = filter["FilterValueIsParameter"]; var filterValue2IsParameterToken = filter["FilterValue2IsParameter"]; string filterValue2 = filter["FilterValue2"].ToString(); IModelCapabilities modelCapabilities = filter["ModelCapabilities"].ToObject <ADOTabularModelCapabilities>(); var queryBuilderFilter = new QueryBuilderFilter(obj, modelCapabilities, _eventAggregator); queryBuilderFilter.FilterType = filterType; queryBuilderFilter.FilterValue = filterValue; if (filterValueIsParameterToken != null) { bool filterValueIsParameter = Convert.ToBoolean(filterValueIsParameterToken.ToString()); queryBuilderFilter.FilterValueIsParameter = filterValueIsParameter; } queryBuilderFilter.FilterValue2 = filterValue2; if (filterValue2IsParameterToken != null) { bool filterValue2IsParameter = Convert.ToBoolean(filterValue2IsParameterToken.ToString()); queryBuilderFilter.FilterValue2IsParameter = filterValue2IsParameter; } vm.Filters.Add(queryBuilderFilter); } // Return the result return(vm); }
protected override IQueryBuilderView CreateView(QueryBuilderViewModel queryBuilderViewModel) { return(new NoPreviewQueryBuilderView(queryBuilderViewModel, Owner, LookAndFeel, ParameterService, PropertyGridServices, NoCustomSql, Light, DisplayNameProvider, NoDiagramControl, LegacyExpressionEditor, LoaderExceptionHandler, RepositoryItemsProvider)); }