private async Task TransformTagAsync(Context context, ClrQuery query) { if (query.Filter != null) { query.Filter = await FilterTagTransformer.TransformAsync(query.Filter, context.App.Id, tagService); } }
public virtual async ValueTask <ClrQuery> ParseQueryAsync(Context context, Q q) { Guard.NotNull(context, nameof(context)); Guard.NotNull(q, nameof(q)); using (Profiler.TraceMethod <AssetQueryParser>()) { ClrQuery result; if (q.Query != null) { result = q.Query; } else { if (!string.IsNullOrWhiteSpace(q?.JsonQuery)) { result = ParseJson(q.JsonQuery); } else if (!string.IsNullOrWhiteSpace(q?.ODataQuery)) { result = ParseOData(q.ODataQuery); } else { result = new ClrQuery(); } } if (result.Filter != null) { result.Filter = await FilterTagTransformer.TransformAsync(result.Filter, context.App.Id, tagService); } if (result.Sort.Count == 0) { result.Sort.Add(new SortNode(new List <string> { "lastModified" }, SortOrder.Descending)); } if (!result.Sort.Any(x => string.Equals(x.Path.ToString(), "id", StringComparison.OrdinalIgnoreCase))) { result.Sort.Add(new SortNode(new List <string> { "id" }, SortOrder.Ascending)); } if (result.Take == long.MaxValue) { result.Take = options.DefaultPageSize; } else if (result.Take > options.MaxResults) { result.Take = options.MaxResults; } return(result); } }
public void Should_not_normalize_other_field() { var source = FilterBuilder.Eq("other", "value"); var result = FilterTagTransformer.Transform(source, appId, tagService); Assert.Equal("other == 'value'", result.ToString()); A.CallTo(() => tagService.GetTagIdsAsync(appId, A <string> .Ignored, A <HashSet <string> > .Ignored)) .MustNotHaveHappened(); }
public void Should_not_fail_when_tags_not_found() { A.CallTo(() => tagService.GetTagIdsAsync(appId, TagGroups.Assets, A <HashSet <string> > .That.Contains("name1"))) .Returns(new Dictionary <string, string>()); var source = FilterBuilder.Eq("tags", "name1"); var result = FilterTagTransformer.Transform(source, appId, tagService); Assert.Equal("tags == 'name1'", result.ToString()); }
public async Task Should_not_normalize_other_field() { var source = ClrFilter.Eq("other", "value"); var result = await FilterTagTransformer.TransformAsync(source, appId, tagService); Assert.Equal("other == 'value'", result !.ToString()); A.CallTo(() => tagService.GetTagIdsAsync(appId, A <string> ._, A <HashSet <string> > ._)) .MustNotHaveHappened(); }
public void Should_normalize_tags() { A.CallTo(() => tagService.GetTagIdsAsync(appId, TagGroups.Assets, A <HashSet <string> > .That.Contains("name1"))) .Returns(new Dictionary <string, string> { ["name1"] = "id1" }); var source = ClrFilter.Eq("tags", "name1"); var result = FilterTagTransformer.Transform(source, appId, tagService); Assert.Equal("tags == 'id1'", result.ToString()); }
public virtual ClrQuery ParseQuery(Context context, Q q) { Guard.NotNull(context); using (Profiler.TraceMethod <AssetQueryParser>()) { ClrQuery result; if (q.Query != null) { result = q.Query; } else { if (!string.IsNullOrWhiteSpace(q?.JsonQuery)) { result = ParseJson(q.JsonQuery); } else if (!string.IsNullOrWhiteSpace(q?.ODataQuery)) { result = ParseOData(q.ODataQuery); } else { result = new ClrQuery(); } } if (result.Filter != null) { result.Filter = FilterTagTransformer.Transform(result.Filter, context.App.Id, tagService); } if (result.Sort.Count == 0) { result.Sort.Add(new SortNode(new List <string> { "lastModified" }, SortOrder.Descending)); } if (result.Take == long.MaxValue) { result.Take = options.DefaultPageSize; } else if (result.Take > options.MaxResults) { result.Take = options.MaxResults; } return(result); } }