public void BuildPreSearchFilterOperationsTest(IEnumerable <KeyValuePair <string, int> > countOfFilters, IEnumerable <KeyValuePair <string, PreSearchFilterLogicalOperator> > filterFields, string expectedFilterBy) { var model = new PreSearchFiltersResultsModel { Sections = new List <FilterResultsSection>() }; if (countOfFilters == null) { throw new TestException("Count Of Filters passed is null"); } foreach (var item in countOfFilters) { var section = new FilterResultsSection { SectionDataType = item.Key, Name = item.Key, Options = GetTestFilterOptions(item).ToList(), SingleSelectOnly = item.Value == 1, SingleSelectedValue = item.Value == 1 ? $"{item.Key.ToLower()}{item.Value}" : null }; model.Sections.Add(section); } var testObject = new DfcBuildFilterService(); var result = testObject.BuildPreSearchFilters(model, filterFields.ToDictionary(k => k.Key, v => v.Value)); result.Should().Be(expectedFilterBy); }
private void BuildPreSearchFiltersForField(System.Text.StringBuilder builder, FilterResultsSection fieldFilter, KeyValuePair <string, PreSearchFilterLogicalOperator> field) { var notApplicableSelected = fieldFilter.Options.Any(opt => opt.ClearOtherOptionsIfSelected); if (!notApplicableSelected) { var fieldValue = fieldFilter.SingleSelectOnly ? fieldFilter.SingleSelectedValue : string.Join(",", fieldFilter.Options.Where(opt => opt.IsSelected).Select(opt => opt.OptionKey)); if (!string.IsNullOrWhiteSpace(fieldValue)) { builder.Append($"{(builder.Length > 0 ? field.Value.ToString().ToLowerInvariant() : string.Empty)} {field.Key}/any(t: search.in(t, '{fieldValue}')) "); } } }